Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changelog: Fix CI job and introduce verification CI job #278

Merged
merged 12 commits into from
Jul 1, 2024
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably typo here =

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading