Skip to content

Commit 8ffe6f0

Browse files
authored
fix(ci): merge queue upkeep hotfixes (#16358)
2 parents 5cc430b + b20b26e commit 8ffe6f0

2 files changed

Lines changed: 47 additions & 29 deletions

File tree

.github/workflows/merge-train-create-pr.yml

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,47 @@ jobs:
1111
permissions:
1212
contents: read
1313
pull-requests: write
14-
14+
1515
steps:
1616
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
17-
17+
with:
18+
fetch-depth: 0
19+
1820
- name: Check if PR exists and create if needed
1921
env:
2022
GITHUB_TOKEN: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }}
2123
run: |
22-
branch="${{ github.ref_name }}"
23-
24-
# Check if PR already exists for this branch
25-
existing_pr=$(gh pr list --state open --head "$branch" --json number --jq '.[0].number // empty')
26-
27-
if [[ -z "$existing_pr" ]]; then
28-
echo "No PR exists for $branch, creating one"
29-
30-
# Determine base branch (default to next)
31-
base_branch="next"
32-
33-
# Create PR with ci-no-squash label
34-
gh pr create --base "$base_branch" --head "$branch" \
35-
--title "feat: $branch" \
36-
--body "$(echo -e "See [merge-train-readme.md](https://github.com/${{ github.repository }}/blob/next/.github/workflows/merge-train-readme.md).\nThis is a merge-train.")" \
37-
--label "ci-no-squash"
38-
39-
echo "Created PR for $branch"
40-
else
41-
echo "PR #$existing_pr already exists for $branch"
42-
fi
24+
branch="${{ github.ref_name }}"
25+
26+
# Skip if this is a merge commit (check for multiple parents)
27+
parent_count=$(git rev-list --parents -n 1 "${{ github.sha }}" | wc -w)
28+
if [[ $parent_count -gt 2 ]]; then
29+
echo "Skipping: This is a merge commit."
30+
exit 0
31+
fi
32+
33+
# Skip if this commit is already in the next branch
34+
if git merge-base --is-ancestor "${{ github.sha }}" origin/next; then
35+
echo "Skipping: This commit is already in the next branch"
36+
exit 0
37+
fi
38+
39+
# Check if PR already exists for this branch
40+
existing_pr=$(gh pr list --state open --head "$branch" --json number --jq '.[0].number // empty')
41+
42+
if [[ -z "$existing_pr" ]]; then
43+
echo "No PR exists for $branch, creating one"
44+
45+
# Determine base branch (default to next)
46+
base_branch="next"
47+
48+
# Create PR with ci-no-squash label
49+
gh pr create --base "$base_branch" --head "$branch" \
50+
--title "feat: $branch" \
51+
--body "$(echo -e "See [merge-train-readme.md](https://github.com/${{ github.repository }}/blob/next/.github/workflows/merge-train-readme.md).\nThis is a merge-train.")" \
52+
--label "ci-no-squash"
53+
54+
echo "Created PR for $branch"
55+
else
56+
echo "PR #$existing_pr already exists for $branch"
57+
fi

scripts/merge-train/merge-next.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,15 @@ TRAIN_BRANCH="$1"
7373

7474
# Check if PR has auto-merge enabled
7575
pr_info=$(get_pr_for_branch "$TRAIN_BRANCH")
76-
if [[ -n "$pr_info" ]]; then
77-
pr_number=$(echo "$pr_info" | jq -r '.number // empty')
78-
if [[ -n "$pr_number" ]] && pr_has_auto_merge "$pr_number"; then
79-
echo "PR #$pr_number has auto-merge enabled, skipping merge from next"
80-
exit 0
81-
fi
76+
if [[ -z "$pr_info" || "$pr_info" == "null" ]]; then
77+
echo "No open PR found for branch $TRAIN_BRANCH, skipping merge"
78+
exit 0
79+
fi
80+
81+
pr_number=$(echo "$pr_info" | jq -r '.number // empty')
82+
if [[ -n "$pr_number" ]] && pr_has_auto_merge "$pr_number"; then
83+
echo "PR #$pr_number has auto-merge enabled, skipping merge from next"
84+
exit 0
8285
fi
8386

8487
# Check if branch exists

0 commit comments

Comments
 (0)