Skip to content

Commit 46a805f

Browse files
authored
adding merge queue support to PR build workflow with redundant build skipping (#3781)
1 parent 4dd4b2e commit 46a805f

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

.github/workflows/pull-request-build.yml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Build SDK
22
on:
33
pull_request:
44
types: [ opened, synchronize, ready_for_review ]
5+
merge_group:
56

67
concurrency:
78
group: start-pull-request-build-${{ github.ref }}
@@ -15,15 +16,40 @@ env:
1516

1617
jobs:
1718
aws-sdk-pr-build:
18-
if: github.event.pull_request.draft == false
19+
if: github.event.pull_request.draft == false || github.event_name == 'merge_group'
1920
runs-on: ubuntu-latest
2021
permissions:
2122
id-token: write
2223
issues: write
2324
pull-requests: write
2425
contents: read
2526
steps:
27+
- name: Checkout merge group (shallow)
28+
if: github.event_name == 'merge_group'
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 2
32+
- name: Check if merge queue build is needed
33+
if: github.event_name == 'merge_group'
34+
id: queue-check
35+
env:
36+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
run: |
38+
HEAD_REF="${{ github.event.merge_group.head_ref }}"
39+
PR_NUM=$(echo "$HEAD_REF" | grep -oP 'pr-\K[0-9]+')
40+
PR_BASE_SHA=$(gh api repos/${{ github.repository }}/pulls/$PR_NUM --jq '.base.sha')
41+
PARENT_SHA=$(git rev-parse HEAD~1)
42+
echo "PR #$PR_NUM base SHA: $PR_BASE_SHA"
43+
echo "Merge group HEAD~1: $PARENT_SHA"
44+
if [ "$PARENT_SHA" == "$PR_BASE_SHA" ]; then
45+
echo "skip=true" >> "$GITHUB_OUTPUT"
46+
echo "First in queue, same base — PR build already validated this, skipping."
47+
else
48+
echo "skip=false" >> "$GITHUB_OUTPUT"
49+
echo "Other PRs ahead or base moved — build needed."
50+
fi
2651
- name: Configure AWS Credentials
52+
if: steps.queue-check.outputs.skip != 'true'
2753
uses: aws-actions/configure-aws-credentials@main
2854
with:
2955
role-to-assume: ${{ env.IAM_ROLE_ARN }}
@@ -32,17 +58,20 @@ jobs:
3258
aws-region: us-west-2
3359
role-duration-seconds: 7200
3460
- name: Download Build Script
61+
if: steps.queue-check.outputs.skip != 'true'
3562
run: |
3663
aws s3 cp s3://aws-sdk-builds-github-assets-prod-us-west-2/$SCRIPT_LOCATION ./$DOWNLOAD_FOLDER/$SCRIPT_LOCATION --no-progress
3764
chmod +x ./$DOWNLOAD_FOLDER/$SCRIPT_LOCATION
3865
- name: Build
66+
if: steps.queue-check.outputs.skip != 'true'
3967
env:
4068
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4169
REPO: ${{ github.repository }}
42-
HEAD_REF: ${{ github.event.pull_request.head.ref }}
43-
PR_NUMBER: ${{ github.event.pull_request.number }}
70+
HEAD_REF: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }}
71+
PR_NUMBER: ${{ github.event.pull_request.number || '0' }}
4472
RUN_ID: ${{ github.run_id }}
4573
run: |
74+
HEAD_REF="${HEAD_REF#refs/heads/}"
4675
./$DOWNLOAD_FOLDER/$SCRIPT_LOCATION \
4776
--repo "$REPO" \
4877
--branch "$HEAD_REF" \

0 commit comments

Comments
 (0)