Skip to content

Commit e35be27

Browse files
authored
Improve logging (#15)
1 parent 52f3c55 commit e35be27

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

azure-pipelines/build-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ stages:
126126
- template: steps/install-development-dependencies.yml
127127

128128
- script: |
129-
cd-assert-news -b $(current_branch)
129+
cd-assert-news -vv -b $(current_branch)
130130
displayName: 'Run check'
131131
env:
132132
GIT_TOKEN: $(GIT_TOKEN)

continuous_delivery_scripts/assert_news.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def validate_news_files(git: GitWrapper, root_dir: str, news_dir: str) -> None:
9393
validate_news_file(absolute_file_path)
9494

9595

96-
def add_news_files(git: GitWrapper, news_dir: str) -> None:
96+
def generate_news_file(git: GitWrapper, news_dir: str) -> pathlib.Path:
9797
"""Adds a news file if the branch corresponds to an dependency update.
9898
9999
Args:
@@ -109,19 +109,21 @@ def add_news_files(git: GitWrapper, news_dir: str) -> None:
109109
if not configuration.get_value(ConfigurationVariable.AUTOGENERATE_NEWS_FILE_ON_DEPENDENCY_UPDATE):
110110
raise EnvironmentError(f"Branch {current_branch} must contain a news file.")
111111

112-
create_news_file(
112+
message = str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_MESSAGE)).format(
113+
message=", ".join(groups)
114+
)
115+
logger.info(f"Generating a news file with content: {message}...")
116+
return create_news_file(
113117
news_dir,
114-
str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_MESSAGE)).format(
115-
message=", ".join(groups)
116-
),
118+
message,
117119
configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_TYPE),
118120
)
119121

120122

121-
def _commit_news_file(git: GitWrapper, news_dir: str) -> None:
122-
logger.info("Committing news file...")
123+
def _commit_news_file(git: GitWrapper, news_file: pathlib.Path) -> None:
124+
logger.info(f"Committing news file {str(news_file)}...")
123125
git.configure_for_github()
124-
git.add(news_dir)
126+
git.add(str(news_file))
125127
git.commit("📰 Automatic changes ⚙ Adding news file")
126128
git.push()
127129
git.pull()
@@ -150,11 +152,11 @@ def main() -> None:
150152
except Exception as e:
151153
log_exception(logger, e)
152154
try:
153-
add_news_files(git, absolute_news_dir)
154-
_commit_news_file(git, absolute_news_dir)
155+
news_file = generate_news_file(git, absolute_news_dir)
156+
_commit_news_file(git, news_file)
155157
except Exception as e2:
156158
log_exception(logger, e2)
157-
sys.exit(1)
159+
sys.exit(1)
158160

159161

160162
if __name__ == "__main__":

continuous_delivery_scripts/utils/news_file.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
"""Helpers with regards to news files."""
66
import enum
77
import pathlib
8+
import logging
89
from datetime import datetime
910
from typing import Any
1011

12+
logger = logging.getLogger(__name__)
13+
1114

1215
class NewsType(enum.Enum):
1316
"""Describes the type of news we're writing."""
@@ -44,6 +47,7 @@ def determine_news_file_path(news_dir: str, news_type: NewsType) -> pathlib.Path
4447

4548

4649
def _write_file(file_path: pathlib.Path, text: str) -> None:
50+
logger.info(f"Writing news file: {file_path}")
4751
file_path.parent.mkdir(parents=True, exist_ok=True)
4852
if not text.endswith("\n"):
4953
text = f"{text}\n"

news/202108110106.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improved logging when creating and asserting news files

0 commit comments

Comments
 (0)