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

ci: ensure Cargo.toml and CHANGELOG of published crates are updated #4620

Merged
merged 18 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
CRATE: ${{ matrix.crate }}
steps:
- uses: actions/checkout@v4
with:
fetch-tags: true
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved

- uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0

Expand Down Expand Up @@ -70,6 +72,15 @@ jobs:

test "$PACKAGE_VERSION" = "$SPECIFIED_VERSION"

- name: Ensure manifest and CHANGELOG are properly updated
if: github.event_name == 'pull_request'
run: |
git fetch origin master:master
./scripts/ensure-version-bump-and-changelog.sh
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}


wasm_tests:
name: Run all WASM tests
runs-on: ubuntu-latest
Expand Down
37 changes: 37 additions & 0 deletions scripts/ensure-version-bump-and-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -ex;

MANIFEST_PATH=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .manifest_path')
DIR_TO_CRATE=$(dirname "$MANIFEST_PATH")

MERGE_BASE=$(git merge-base "$HEAD_SHA" master) # Find the merge base. This ensures we only diff what was actually added in the PR.

DIFF_TO_MASTER=$(git diff "$HEAD_SHA".."$MERGE_BASE" --name-status -- "$DIR_TO_CRATE")
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')

# If this PR does not touch any files of this crate, don't perform any further checks.
if [ -z "$DIFF_TO_MASTER" ]; then
exit 0
fi

# Ensure CHANGELOG is updated if any files are touched.
if [ -z "$CHANGELOG_DIFF" ]; then
echo "Files in $DIR_TO_CRATE have changed, please write a changelog entry in $DIR_TO_CRATE/CHANGELOG.md"
exit 1
fi

# Ensure version in Cargo.toml and CHANGELOG are in sync.
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

# Ensure version used in manifest has not 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."
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
exit 1
fi
Loading