forked from polkadot-fellows/runtimes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve release process (polkadot-fellows#63)
* Improve release process This pull request introduces the `changelog-processor.py`. A small script for getting some information out of the `CHANGELOG.md` file for improving the release process. The script supports to get the latest version in the `CHANGELOG.md` file, aka the version top of the file. (This could also be `Unreleased`) The other command is for printing if there should be done a release or not. This is decided based on the latest version and if there exists a tag for it. * Use correct syntax * Single quotes.. * Integer? * 🤦 * This? * AHH * Some last improvements * Update .github/changelog-processor.py Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Apply suggestions from code review * Make the arguments mutally exclusive --------- Co-authored-by: Oliver Tale-Yazdi <[email protected]>
- Loading branch information
1 parent
3c8f25e
commit f881ac4
Showing
4 changed files
with
100 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import sys | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description="Process the CHANGELOG.md") | ||
parser.add_argument( | ||
"changelog", | ||
metavar="CHANGELOG", | ||
help="Path to the CHANGELOG.md file", | ||
default="CHANGELOG.md", | ||
nargs='?' | ||
) | ||
|
||
group = parser.add_mutually_exclusive_group() | ||
group.add_argument( | ||
"--print-latest-version", | ||
dest="print_latest_version", | ||
help="Print the latest version (first in the file) found in the CHANGELOG.md", | ||
action="store_true" | ||
) | ||
group.add_argument( | ||
"--should-release", | ||
dest="should_release", | ||
help="Should a release be made? Prints `1` or `0`.", | ||
action="store_true" | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
with open(args.changelog, "r") as changelog: | ||
lines = changelog.readlines() | ||
|
||
# Find the latest version | ||
for line in lines: | ||
if not line.startswith("## ["): | ||
continue | ||
|
||
version = line.strip().removeprefix("## [").split("]")[0] | ||
break | ||
|
||
if args.print_latest_version: | ||
print(version, end = "") | ||
sys.exit(0) | ||
elif args.should_release: | ||
if version.lower() == "unreleased": | ||
print("0", end = "") | ||
sys.exit(-1) | ||
elif version.count(".") != 2: | ||
print("0", end = "") | ||
sys.exit(-1) | ||
|
||
stream = os.popen("git tag -l v" + version) | ||
output = stream.read() | ||
|
||
# Empty output means that the tag doesn't exist and that we should release. | ||
if output.strip() == "": | ||
print("1", end = "") | ||
else: | ||
print("0", end = "") | ||
|
||
sys.exit(0) | ||
else: | ||
parser.print_help() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters