Skip to content

Commit

Permalink
Changelog: Fix CI job and introduce verification CI job (#278)
Browse files Browse the repository at this point in the history
<!-- Remember that you can run `/merge` to enable auto-merge in the PR
-->

<!-- Remember to modify the changelog. If you don't need to modify it,
you can check the following box.
Instead, if you have already modified it, simply delete the following
line. -->

- [x] Does not require a CHANGELOG entry
  • Loading branch information
bkchr authored Jul 1, 2024
1 parent 750aa73 commit 177cb25
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 10 deletions.
30 changes: 28 additions & 2 deletions .github/changelog-processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,39 @@
help="Print the changelog from the last release.",
action="store_true"
)
group.add_argument(
"--validate-changelog",
dest="validate_changelog",
help="Validates that the changelog uses the correct syntax",
action="store_true"
)

args = parser.parse_args()

with open(args.changelog, "r") as changelog:
lines = changelog.readlines()

if args.validate_changelog:
for line in lines:
if line.startswith("##"):
if line.startswith("###"):
continue
elif not line.startswith("## ["):
print("Line starting with `##` needs to be followed by ` [`, e.g.: `## [Unreleased]`, `## [400.2.1]`")
print(line)
sys.exit(-1)
elif line.strip().removeprefix("## [").split("]")[0].count(".") != 2 and not "unreleased" in line.lower():
print("Only Major.Minor.Patch are supported as versioning")
print(line)
sys.exit(-1)
elif line.startswith("#"):
if line.strip() != "# Changelog":
print("Line starting with `#` is only allowed for `# Changelog`")
print(line)
sys.exit(-1)

sys.exit(0)

changelog_last_release = ""
found_last_version = False

Expand All @@ -53,7 +80,6 @@
else:
break


if args.changelog_last_release:
print(changelog_last_release, end = "")
sys.exit(0)
Expand All @@ -63,7 +89,7 @@
elif args.should_release:
if version.lower() == "unreleased":
print("0", end = "")
sys.exit(-1)
sys.exit(0)
elif version.count(".") != 2:
print("0", end = "")
sys.exit(-1)
Expand Down
46 changes: 40 additions & 6 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
name: Modify Changelog
name: Verify Changelog

# If you modify more test jobs, ensure that you add them as required to the job "confirmTestPassed"
# which is located at the end of this file (more info in the job)

on:
pull_request_target:
types:
- synchronize
- edited
push:
branches: ["main", "release-*"]
pull_request:
workflow_dispatch:

# cancel previous runs
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:

verifyChangelog:
verify-changelog-updated:
name: Verify that Changelog is Updated
runs-on: ubuntu-latest
env:
Expand All @@ -22,3 +30,29 @@ jobs:
- name: Set error
if: steps.changed.outputs.matched != 'true' && !contains(github.event.pull_request.body, '[x] Does not require a CHANGELOG entry')
run: echo "::error::CHANGELOG.md has not been modified. Either modify the file or check the checkbox in the body" && exit 1

verify-changelog-valid:
name: Verify that Changelog is valid
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ github.token }}
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Verify
run: .github/changelog-processor.py CHANGELOG.md --validate-changelog

# This will only run if all the tests in its "needs" array passed.
# Add this as your required job, becuase if the matrix changes size (new things get added)
# it will still require all the steps to succeed.
# If you add more jobs, remember to add them to the "needs" array.
confirmChangelogChecksPassed:
runs-on: ubuntu-latest
name: All tests passed
# If any new job gets added, be sure to add it to this list
needs:
- verify-changelog-updated
- verify-changelog-valid
steps:
- run: echo '### Good job! All the tests passed 🚀' >> $GITHUB_STEP_SUMMARY
3 changes: 2 additions & 1 deletion .github/workflows/check-migrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ jobs:
fi
# Disable the spec version check when we dont want to release.
if ! .github/changelog-processor.py CHANGELOG.md --should-release ; then
# The program prints either `1` or `0`.
if [ "$(.github/changelog-processor.py CHANGELOG.md --should-release)" = "0" ]; then
EXTRA_FLAGS+=" --disable-spec-version-check"
echo "Disabling the spec version check since we are not releasing"
else
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog for the runtimes governed by the Polkadot Fellowship.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased
## [Unreleased]

### Changed

Expand Down

0 comments on commit 177cb25

Please sign in to comment.