Skip to content
Merged
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
38 changes: 25 additions & 13 deletions .github/actions/check-skip-merge-queue/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ outputs:
runs:
using: composite
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Get pull request details
continue-on-error: true
id: pr-details
Expand Down Expand Up @@ -90,15 +85,32 @@ runs:
- name: Check if pull request is up-to-date with base branch
continue-on-error: true
id: up-to-date
shell: bash
uses: actions/github-script@v8
env:
BASE_REF: ${{ inputs.base-ref }}
PR_BRANCH: ${{ steps.pr-details.outputs.pr-branch }}
MERGE_QUEUE_POSITION: ${{ steps.pr-details.outputs.merge-queue-position }}
run: |
set -euo pipefail
if git merge-base --is-ancestor "origin/${BASE_REF}" "origin/${PR_BRANCH}" && [ "${MERGE_QUEUE_POSITION}" -eq 1 ]; then
echo "up-to-date=true" >> "$GITHUB_OUTPUT"
else
echo "up-to-date=false" >> "$GITHUB_OUTPUT"
fi
with:
github-token: ${{ inputs.github-token }}
script: |
const { BASE_REF, PR_BRANCH, MERGE_QUEUE_POSITION } = process.env;

if (parseInt(MERGE_QUEUE_POSITION, 10) !== 1) {
core.info(`Pull request is not first in the merge queue (position: ${MERGE_QUEUE_POSITION}).`);
core.setOutput('up-to-date', 'false');
return;
}

const comparison = await github.rest.repos.compareCommitsWithBasehead({
owner: context.repo.owner,
repo: context.repo.repo,
basehead: `${BASE_REF}...${PR_BRANCH}`,
});

if (comparison.data.status === 'identical' || comparison.data.status === 'ahead') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what case would it return ahead versus identical?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • identical: The base and head point to the same commit. Not sure when this would be the case, but it's safe to treat pull requests as up-to-date in this case.
  • ahead: The head includes all commits of the base, plus additional commits.
  • behind: The head is missing commits from the base.
  • diverged: Both the head and base contain additional commits compared to the merge base.

core.info(`Pull request branch "${PR_BRANCH}" is up-to-date with base branch "${BASE_REF}".`);
core.setOutput('up-to-date', 'true');
} else {
core.info(`Pull request branch "${PR_BRANCH}" is not up-to-date with base branch "${BASE_REF}".`);
core.setOutput('up-to-date', 'false');
}
Loading