Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
24 changes: 14 additions & 10 deletions .github/actions/check-merge-queue-changelogs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,27 @@ runs:
const number = parseInt(match[1], 10);
core.setOutput('pr-number', number);

- name: Get pull request branch
id: pr-branch
- name: Fetch pull request head commit
id: pr-head
shell: bash
env:
REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ steps.pr-number.outputs.pr-number }}
GH_TOKEN: ${{ inputs.github-token }}
run: |
BRANCH=$(gh api "/repos/${REPOSITORY}/pulls/${PR_NUMBER}" --jq=.head.ref)
echo "pr-branch=$BRANCH" >> "$GITHUB_OUTPUT"
set -euo pipefail

# The head branch of a fork pull request does not exist in this
# repository, so the head commit is only reachable through the pull
# request ref.
PR_REF="refs/remotes/pr/${PR_NUMBER}/head"
git fetch --no-tags origin "+refs/pull/${PR_NUMBER}/head:${PR_REF}"
echo "pr-ref=$PR_REF" >> "$GITHUB_OUTPUT"

- name: Check changelog changes
id: changelog-check
shell: bash
env:
BASE_REF: ${{ github.event.pull_request.base.ref || github.event.merge_group.base_ref }}
PR_BRANCH: ${{ steps.pr-branch.outputs.pr-branch }}
PR_REF: ${{ steps.pr-head.outputs.pr-ref }}
ACTION_PATH: ${{ github.action_path }}
run: |
set -euo pipefail
Expand All @@ -69,10 +73,10 @@ runs:
BASE_REF="${BASH_REMATCH[1]}"
fi

TARGET_REF=$(git merge-base "origin/$BASE_REF" "origin/$PR_BRANCH")
TARGET_REF=$(git merge-base "origin/$BASE_REF" "$PR_REF")
git fetch origin "$TARGET_REF"

UPDATED_CHANGELOGS=$(git diff --name-only "$TARGET_REF" "origin/$PR_BRANCH" | grep -E 'CHANGELOG\.md$' || true)
UPDATED_CHANGELOGS=$(git diff --name-only "$TARGET_REF" "$PR_REF" | grep -E 'CHANGELOG\.md$' || true)
if [ -n "$UPDATED_CHANGELOGS" ]; then
for FILE in $UPDATED_CHANGELOGS; do
if [ ! -f "$FILE" ]; then
Expand All @@ -87,7 +91,7 @@ runs:

echo "Checking changelog file: $FILE"
git show "$TARGET_REF":"$FILE" > /tmp/base-changelog.md
git show origin/"$PR_BRANCH":"$FILE" > /tmp/pr-changelog.md
git show "$PR_REF":"$FILE" > /tmp/pr-changelog.md

node "${ACTION_PATH}/check-changelog-diff.cjs" \
/tmp/base-changelog.md \
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/changelog-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ jobs:
uses: MetaMask/github-tools/.github/actions/check-changelog@v1
with:
base-branch: ${{ github.event.pull_request.base.ref }}
head-ref: ${{ github.head_ref }}
# The head branch of a fork pull request does not exist in this
# repository, but its head commit is always reachable through the
# pull request ref.
head-ref: refs/pull/${{ github.event.pull_request.number }}/head
labels: ${{ toJSON(github.event.pull_request.labels) }}
pr-number: ${{ github.event.pull_request.number }}
repo: ${{ github.repository }}