Skip to content

Commit 613faf7

Browse files
committed
Print changelogs and fail if git tag does not exist
1 parent 32dcf83 commit 613faf7

File tree

3 files changed

+37
-23
lines changed

3 files changed

+37
-23
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
Nothing right now.
1111

12+
## [1.2.0] - 2020-09-06
13+
14+
Allows changelog content for a version to be empty, while still creating a GitHub Release for the tag.
15+
1216
## [1.1.1] - 2020-09-06
1317

1418
Added a `--no-tag-prefix` option to fix an empty issue with `--tag-prefix`.
@@ -22,6 +26,7 @@ Adds a `tag_prefix` option so that tags don't have to start with a "v". You can
2226
The first release! Includes the `sync` command which will sync your `CHANGELOG.md` to GitHub Release notes.
2327

2428
[Unreleased]: https://github.com/dropseed/changerelease/compare/v1.1.1...HEAD
25-
[1.1.0]: https://github.com/dropseed/changerelease/compare/v1.1.0...v1.1.1
29+
[1.2.0]: https://github.com/dropseed/changerelease/compare/v1.1.1...v1.2.0
30+
[1.1.1]: https://github.com/dropseed/changerelease/compare/v1.1.0...v1.1.1
2631
[1.1.0]: https://github.com/dropseed/changerelease/compare/v1.0.0...v1.1.0
2732
[1.0.0]: https://github.com/dropseed/changerelease/releases/tag/v1.0.0

changerelease/cli.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,32 @@ def sync(changelog, tag_prefix, no_tag_prefix, repo, api_url, token):
4444

4545
cl = Changelog(changelog)
4646

47+
outline = "-" * 80
48+
49+
results = []
50+
4751
for version in cl.versions:
4852
click.secho(f"\nSyncing version {version}", bold=True)
4953
version_contents = cl.parse_version_content(version)
50-
if not version_contents:
51-
click.secho(f"No content found for version {version}", fg="yellow")
54+
55+
click.echo(f"{outline}\n{version_contents or '(empty)'}\n{outline}")
5256

5357
release = Release(repo, tag_prefix, version, requests_session)
54-
release.sync(version_contents)
58+
message, synced = release.sync(version_contents)
59+
60+
click.secho(message, fg="green" if synced else "red")
61+
62+
results.append(synced)
5563

56-
# TODO fail if tag doesn't exist yet? (continue w/ others though)
57-
click.secho(f"\nGitHub releases on {repo} synced with {cl.path}", fg="green")
64+
if all(results):
65+
click.secho(
66+
f"\nSynced {len(results)} GitHub Releases on {repo} with {cl.path}",
67+
fg="green",
68+
)
69+
else:
70+
failed = [x for x in results if not x]
71+
click.secho(f"Failed to sync {len(failed)} versions", fg="red")
72+
exit(1)
5873

5974

6075
if __name__ == "__main__":

changerelease/release.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import click
2-
3-
41
class Release:
52
def __init__(self, repo, tag_prefix, version, requests_session):
63
self.repo = repo
@@ -57,24 +54,21 @@ def update_body(self, contents):
5754
return response.json()
5855

5956
def sync(self, contents):
57+
message = ""
58+
synced = True
59+
6060
if not self.exists():
6161
if self.tag_exists():
62-
click.secho(
63-
f"Release for {self.version} does not exist. Creating it...",
64-
fg="green",
65-
)
62+
message = f"Release for {self.version} does not exist. Creating it..."
6663
release_data = self.create(contents)
67-
click.echo(release_data["html_url"])
64+
message += "\n" + release_data["html_url"]
6865
else:
69-
click.secho(
70-
f'Git tag "{self.version_tag}" not found. A tag needs to be pushed before we can create a release for it.',
71-
fg="red",
72-
)
66+
message = f'Git tag "{self.version_tag}" not found. A tag needs to be pushed before we can create a release for it.'
67+
synced = False
7368
elif not self.body_matches(contents):
74-
click.secho(
75-
f"Release for {self.version} exists but the changelog doesn't match. Updating the release...",
76-
fg="green",
77-
)
69+
message = f"Release for {self.version} exists but the changelog doesn't match. Updating the release..."
7870
self.update_body(contents)
7971
else:
80-
click.echo("No change")
72+
message = "Release is up-to-date"
73+
74+
return (message, synced)

0 commit comments

Comments
 (0)