Skip to content

Commit 10362ba

Browse files
committed
Capture expected 'FATAL' output from tag check
1 parent bfc0078 commit 10362ba

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

bumpchanges/getversion.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ def get_next_version():
4444
logger.notice("New version (tag): %s (%s)", next_version, next_tag)
4545

4646
# Confirm that the corresponding git tag does not exist
47-
try:
48-
tag_ref = subprocess.check_output(
49-
["git", "rev-parse", "--verify", f"refs/tags/{next_tag}"],
50-
cwd=repo_dir
51-
)
47+
tag_ref_proc = subprocess.run(
48+
["git", "rev-parse", "--verify", f"refs/tags/{next_tag}"],
49+
cwd=repo_dir,
50+
capture_output=True,
51+
check=False,
52+
)
53+
if tag_ref_proc.returncode == 0:
5254
# Oops, that tag does exist
53-
logger.error("Tag %s already exists! %s", next_tag, tag_ref)
55+
logger.error(
56+
"Tag %s already exists! %s", next_tag, tag_ref_proc.stdout.decode("utf-8")
57+
)
5458
raise RuntimeError()
5559

56-
except subprocess.CalledProcessError:
57-
# Tag doesn't exist yet - everything is good!
58-
pass
59-
6060
with output_file.open(mode="w", encoding="utf-8") as outfile:
6161
outfile.write(f"next_version={next_version}\n")

bumpchanges/logging.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"Module to handle logging to GitHub Actions."
2+
23
import logging
34

45

@@ -7,21 +8,22 @@
78

89
class NoticeLogger(logging.getLoggerClass()):
910
"A logger subclass that has an additional NOTICE level."
11+
1012
def notice(self, msg, *args, **kwargs):
1113
"Log the message at NOTICE level."
1214
self.log(NOTICE, msg, *args, **kwargs)
1315

1416

1517
class GHAFilter(logging.Filter):
1618
"A logging filter that plays nice with GitHub Actions output."
19+
1720
prefixes = {
1821
logging.DEBUG: "::debug::",
1922
logging.INFO: "",
2023
NOTICE: "::notice::",
2124
logging.WARNING: "::warning::",
2225
logging.ERROR: "::error::",
2326
logging.CRITICAL: "::error::",
24-
2527
}
2628

2729
def filter(self, record):
@@ -45,6 +47,6 @@ def setup_logging():
4547
handler.addFilter(GHAFilter())
4648

4749
# Set these handlers on the root logger of this module
48-
root_logger = logging.getLogger(__name__.rpartition('.')[0])
50+
root_logger = logging.getLogger(__name__.rpartition(".")[0])
4951
root_logger.addHandler(handler)
5052
root_logger.setLevel(logging.DEBUG)

0 commit comments

Comments
 (0)