Skip to content

Commit b6f04df

Browse files
committed
Determine target branch for comparison based on event name
1 parent 9c6ac2c commit b6f04df

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

.github/actions/check-release/action.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,27 @@ runs:
1414
with:
1515
fetch-depth: 0
1616

17+
- name: Get target reference
18+
id: get-target
19+
shell: bash
20+
env:
21+
EVENT_NAME: ${{ github.event_name }}
22+
run: |
23+
if [ "$EVENT_NAME" = "pull_request" ]; then
24+
echo "TARGET=$(git merge-base HEAD refs/remotes/origin/main)" >> "$GITHUB_OUTPUT"
25+
elif [ "$EVENT_NAME" = "merge_group" ]; then
26+
echo "TARGET=$(git rev-parse HEAD^)" >> "$GITHUB_OUTPUT"
27+
else
28+
echo "::error::This action only supports `pull_request` and `merge_group` events."
29+
exit 1
30+
fi
31+
1732
- name: Check commits for changes in released packages
1833
shell: bash
1934
env:
35+
GH_TOKEN: ${{ github.token }}
2036
PULL_REQUEST: ${{ inputs.pull-request }}
37+
TARGET: ${{ steps.get-target.outputs.TARGET }}
2138
run: |
2239
set -euo pipefail
2340
git fetch origin main
@@ -38,14 +55,14 @@ runs:
3855
fi
3956
done
4057
41-
# Get all files changed ahead of this PR.
58+
# Fetch the pull request branch to compare changes.
4259
PULL_REQUEST_BRANCH=$(gh pr view "$PULL_REQUEST" --json headRefName --template "{{ .headRefName }}")
43-
4460
echo "🔍 Checking for release conflicts with files changed ahead of PR branch \`$PULL_REQUEST_BRANCH\`..."
45-
4661
git fetch origin "$PULL_REQUEST_BRANCH"
47-
BEFORE=$(git merge-base "refs/remotes/origin/main" "$PULL_REQUEST_BRANCH")
48-
git diff --name-only "$BEFORE..refs/remotes/origin/main" > changed-files.txt
62+
63+
# Get all files changed ahead of this PR.
64+
BEFORE=$(git merge-base "refs/remotes/origin/main" "origin/$PULL_REQUEST_BRANCH")
65+
git diff --name-only "$BEFORE..$TARGET" > changed-files.txt
4966
5067
CONFLICTS=()
5168
for package in "${RELEASED_PACKAGES[@]}"; do

0 commit comments

Comments
 (0)