From 177cb25b6b5c413f017e4eed25392c38f64369a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 2 Jul 2024 01:18:28 +0200 Subject: [PATCH] Changelog: Fix CI job and introduce verification CI job (#278) - [x] Does not require a CHANGELOG entry --- .github/changelog-processor.py | 30 +++++++++++++++-- .github/workflows/changelog.yml | 46 ++++++++++++++++++++++---- .github/workflows/check-migrations.yml | 3 +- CHANGELOG.md | 2 +- 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/.github/changelog-processor.py b/.github/changelog-processor.py index 10750aade7..29e86bd3ea 100755 --- a/.github/changelog-processor.py +++ b/.github/changelog-processor.py @@ -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 @@ -53,7 +80,6 @@ else: break - if args.changelog_last_release: print(changelog_last_release, end = "") sys.exit(0) @@ -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) diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index f6a85e9b02..7aa221a8ba 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -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: @@ -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 diff --git a/.github/workflows/check-migrations.yml b/.github/workflows/check-migrations.yml index 72ba40db29..6b073bdb1f 100644 --- a/.github/workflows/check-migrations.yml +++ b/.github/workflows/check-migrations.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index d0b7d194b9..a531936ff7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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