From c7527936d1b171be915ca71a3bcb9455cdbcea76 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 28 Nov 2023 11:50:06 +1100 Subject: [PATCH 1/3] Always run changelog lint --- .github/workflows/ci.yml | 16 +++++++++------- scripts/ensure-version-bump-and-changelog.sh | 5 +++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0c852367a2..bf7098900d8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,13 +73,6 @@ jobs: test "$PACKAGE_VERSION" = "$SPECIFIED_VERSION" || test "=$PACKAGE_VERSION" = "$SPECIFIED_VERSION" - name: Ensure manifest and CHANGELOG are properly updated - if: > - github.event_name == 'pull_request' && - !startsWith(github.event.pull_request.title, 'chore') && - !startsWith(github.event.pull_request.title, 'refactor') && - !startsWith(github.event.pull_request.title, 'deps') && - !startsWith(github.event.pull_request.title, 'docs') && - !contains(github.event.pull_request.labels.*.name, 'internal-change') run: | git fetch origin master:master git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }} @@ -87,6 +80,15 @@ jobs: env: HEAD_SHA: ${{ github.event.pull_request.head.sha }} PR_BASE: ${{ github.event.pull_request.base.ref }} + ASSERT_CHANGELOG_UPDATED: | + ${{ + github.event_name == 'pull_request' && + !startsWith(github.event.pull_request.title, 'chore') && + !startsWith(github.event.pull_request.title, 'refactor') && + !startsWith(github.event.pull_request.title, 'deps') && + !startsWith(github.event.pull_request.title, 'docs') && + !contains(github.event.pull_request.labels.*.name, 'internal-change') + }} wasm_tests: name: Run all WASM tests diff --git a/scripts/ensure-version-bump-and-changelog.sh b/scripts/ensure-version-bump-and-changelog.sh index 1470ec3a5e4..e40342997e8 100755 --- a/scripts/ensure-version-bump-and-changelog.sh +++ b/scripts/ensure-version-bump-and-changelog.sh @@ -24,6 +24,11 @@ if [ -z "$SRC_DIFF_TO_BASE" ]; then exit 0; fi +# Exit early if we shouldn't assert for an updated changelog entry. +if [ "$ASSERT_CHANGELOG_UPDATED" == "false" ]; then + exit 0; +fi + # Code was touched, ensure changelog is updated too. if [ -z "$CHANGELOG_DIFF" ]; then echo "Files in $DIR_TO_CRATE have changed, please write a changelog entry in $DIR_TO_CRATE/CHANGELOG.md" From 156ba7283355d624c1f05dd3725ac5420f1bcb79 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 28 Nov 2023 11:59:36 +1100 Subject: [PATCH 2/3] Extract version comparison into separate job --- .github/workflows/ci.yml | 36 +++++++++++++------- scripts/ensure-version-bump-and-changelog.sh | 18 ++-------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf7098900d8..74a472ae59d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,18 +61,39 @@ jobs: with: tool: tomlq + - name: Extract version from manifest + run: | + CRATE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .version') + + echo "CRATE_VERSION=$CRATE_VERSION" >> $GITHUB_ENV + - name: Enforce version in `workspace.dependencies` matches latest version if: env.CRATE != 'libp2p' run: | - PACKAGE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .version') SPECIFIED_VERSION=$(tomlq "workspace.dependencies.$CRATE.version" --file ./Cargo.toml) - echo "Package version: $PACKAGE_VERSION"; + echo "Package version: $CRATE_VERSION"; echo "Specified version: $SPECIFIED_VERSION"; - test "$PACKAGE_VERSION" = "$SPECIFIED_VERSION" || test "=$PACKAGE_VERSION" = "$SPECIFIED_VERSION" + test "$CRATE_VERSION" = "$SPECIFIED_VERSION" || test "=$CRATE_VERSION" = "$SPECIFIED_VERSION" + + - name: Enforce version in CHANGELOG.md matches version in manifest + run: | + VERSION_IN_CHANGELOG=$(awk -F' ' '/^## [0-9]+\.[0-9]+\.[0-9]+/{print $2; exit}' "$DIR_TO_CRATE/CHANGELOG.md") + + echo "Package version: $CRATE_VERSION"; + echo "Changelog version: $VERSION_IN_CHANGELOG"; + + test "$CRATE_VERSION" = "$VERSION_IN_CHANGELOG" - name: Ensure manifest and CHANGELOG are properly updated + if: > + github.event_name == 'pull_request' && + !startsWith(github.event.pull_request.title, 'chore') && + !startsWith(github.event.pull_request.title, 'refactor') && + !startsWith(github.event.pull_request.title, 'deps') && + !startsWith(github.event.pull_request.title, 'docs') && + !contains(github.event.pull_request.labels.*.name, 'internal-change') run: | git fetch origin master:master git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }} @@ -80,15 +101,6 @@ jobs: env: HEAD_SHA: ${{ github.event.pull_request.head.sha }} PR_BASE: ${{ github.event.pull_request.base.ref }} - ASSERT_CHANGELOG_UPDATED: | - ${{ - github.event_name == 'pull_request' && - !startsWith(github.event.pull_request.title, 'chore') && - !startsWith(github.event.pull_request.title, 'refactor') && - !startsWith(github.event.pull_request.title, 'deps') && - !startsWith(github.event.pull_request.title, 'docs') && - !contains(github.event.pull_request.labels.*.name, 'internal-change') - }} wasm_tests: name: Run all WASM tests diff --git a/scripts/ensure-version-bump-and-changelog.sh b/scripts/ensure-version-bump-and-changelog.sh index e40342997e8..a7a0992005a 100755 --- a/scripts/ensure-version-bump-and-changelog.sh +++ b/scripts/ensure-version-bump-and-changelog.sh @@ -10,25 +10,11 @@ MERGE_BASE=$(git merge-base "$HEAD_SHA" "$PR_BASE") # Find the merge base. This SRC_DIFF_TO_BASE=$(git diff "$HEAD_SHA".."$MERGE_BASE" --name-status -- "$DIR_TO_CRATE/src" "$DIR_TO_CRATE/Cargo.toml") CHANGELOG_DIFF=$(git diff "$HEAD_SHA".."$MERGE_BASE" --name-only -- "$DIR_TO_CRATE/CHANGELOG.md") -VERSION_IN_CHANGELOG=$(awk -F' ' '/^## [0-9]+\.[0-9]+\.[0-9]+/{print $2; exit}' "$DIR_TO_CRATE/CHANGELOG.md") -VERSION_IN_MANIFEST=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .version') - -# First, ensure version in Cargo.toml and CHANGELOG are in sync. This should always hold, regardless of whether the code in the crate was modified. -if [[ "$VERSION_IN_CHANGELOG" != "$VERSION_IN_MANIFEST" ]]; then - echo "Version in Cargo.toml ($VERSION_IN_MANIFEST) does not match version in CHANGELOG ($VERSION_IN_CHANGELOG)" - exit 1 -fi - # If the source files of this crate weren't touched in this PR, exit early. if [ -z "$SRC_DIFF_TO_BASE" ]; then exit 0; fi -# Exit early if we shouldn't assert for an updated changelog entry. -if [ "$ASSERT_CHANGELOG_UPDATED" == "false" ]; then - exit 0; -fi - # Code was touched, ensure changelog is updated too. if [ -z "$CHANGELOG_DIFF" ]; then echo "Files in $DIR_TO_CRATE have changed, please write a changelog entry in $DIR_TO_CRATE/CHANGELOG.md" @@ -36,7 +22,7 @@ if [ -z "$CHANGELOG_DIFF" ]; then fi # Code was touched, ensure the version used in the manifest hasn't been released yet. -if git tag | grep -q "^$CRATE-v${VERSION_IN_MANIFEST}$"; then - echo "v$VERSION_IN_MANIFEST of '$CRATE' has already been released, please bump the version." +if git tag | grep -q "^$CRATE-v${CRATE_VERSION}$"; then + echo "v$CRATE_VERSION of '$CRATE' has already been released, please bump the version." exit 1 fi From 680472813c7efcf013f8a55046a49e594f2646d2 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 28 Nov 2023 12:12:59 +1100 Subject: [PATCH 3/3] Set correct variables --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74a472ae59d..98517315f52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,6 +79,8 @@ jobs: - name: Enforce version in CHANGELOG.md matches version in manifest run: | + MANIFEST_PATH=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .manifest_path') + DIR_TO_CRATE=$(dirname "$MANIFEST_PATH") VERSION_IN_CHANGELOG=$(awk -F' ' '/^## [0-9]+\.[0-9]+\.[0-9]+/{print $2; exit}' "$DIR_TO_CRATE/CHANGELOG.md") echo "Package version: $CRATE_VERSION";