Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/cargo/wasm-bindgen-0.2.89
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 28, 2023
2 parents f211467 + 69fc1ac commit f79ffb7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,32 @@ 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: |
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";
echo "Changelog version: $VERSION_IN_CHANGELOG";
test "$CRATE_VERSION" = "$VERSION_IN_CHANGELOG"
- name: Ensure manifest and CHANGELOG are properly updated
if: >
Expand Down
13 changes: 2 additions & 11 deletions scripts/ensure-version-bump-and-changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ 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;
Expand All @@ -31,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

0 comments on commit f79ffb7

Please sign in to comment.