Skip to content

Commit

Permalink
ci: use dynamic PR base
Browse files Browse the repository at this point in the history
Previously, we would always compare the diff to master. This is wrong because not all PRs go into master. Instead, we now use the correct SHA of the PR base.

Pull-Request: #4785.
  • Loading branch information
thomaseizinger authored Nov 2, 2023
1 parent 96b4c4a commit 6b567e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
./scripts/ensure-version-bump-and-changelog.sh
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}

PR_BASE: ${{ github.event.pull_request.base.ref }}

wasm_tests:
name: Run all WASM tests
Expand Down
6 changes: 3 additions & 3 deletions scripts/ensure-version-bump-and-changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ 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.
MERGE_BASE=$(git merge-base "$HEAD_SHA" "$PR_BASE") # Find the merge base. This ensures we only diff what was actually added in the PR.

SRC_DIFF_TO_MASTER=$(git diff "$HEAD_SHA".."$MERGE_BASE" --name-status -- "$DIR_TO_CRATE/src" "$DIR_TO_CRATE/Cargo.toml")
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")
Expand All @@ -20,7 +20,7 @@ if [[ "$VERSION_IN_CHANGELOG" != "$VERSION_IN_MANIFEST" ]]; then
fi

# If the source files of this crate weren't touched in this PR, exit early.
if [ -z "$SRC_DIFF_TO_MASTER" ]; then
if [ -z "$SRC_DIFF_TO_BASE" ]; then
exit 0;
fi

Expand Down

0 comments on commit 6b567e9

Please sign in to comment.