feat: merge-train/fairies (#25086) #13849
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Merge-Train Create PR | |
| on: | |
| push: | |
| branches: | |
| - 'merge-train/*' | |
| jobs: | |
| create-pr: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check if PR exists and create if needed | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} | |
| run: | | |
| branch="${{ github.ref_name }}" | |
| # Determine base branch. Most trains target next; trains suffixed | |
| # with -v<N> (e.g. spartan-v5, fairies-v5) target the matching | |
| # release line (v5-next) instead. | |
| base_branch="next" | |
| if [[ "$branch" =~ -v([0-9]+)$ ]]; then | |
| base_branch="v${BASH_REMATCH[1]}-next" | |
| fi | |
| # Skip if this is a merge commit (multiple parents) -- unless its | |
| # message references a PR (#123). A feature PR merged into the train | |
| # carries that reference ("Merge pull request #123 ..."); our own | |
| # mechanical base->train merges ("Merge branch 'next' into ...") do not. | |
| parent_count=$(git rev-list --parents -n 1 "${{ github.sha }}" | wc -w) | |
| if [[ $parent_count -gt 2 ]] && ! git show -s --format=%B "${{ github.sha }}" | grep -qE '#[0-9]+'; then | |
| echo "Skipping: This is a merge commit with no PR reference." | |
| exit 0 | |
| fi | |
| # Skip if this commit is already in the base branch | |
| if git merge-base --is-ancestor "${{ github.sha }}" "origin/$base_branch"; then | |
| echo "Skipping: This commit is already in the $base_branch branch" | |
| exit 0 | |
| fi | |
| # Check if PR already exists for this branch | |
| existing_pr=$(gh pr list --state open --head "$branch" --json number --jq '.[0].number // empty') | |
| if [[ -z "$existing_pr" ]]; then | |
| echo "No PR exists for $branch, creating one" | |
| # Create PR with ci-no-squash label | |
| labels="ci-no-squash" | |
| if [[ "$branch" == "merge-train/spartan" || "$branch" == "merge-train/spartan-v5" || "$branch" == "merge-train/ci" ]]; then | |
| labels="$labels,ci-full-no-test-cache" | |
| fi | |
| # Trains targeting a v<N>-next release line (v5-next) are | |
| # forward-ported into their base via the private-port-next driver. | |
| if [[ "$base_branch" =~ ^v[0-9]+-next$ ]]; then | |
| labels="$labels,private-port-next" | |
| fi | |
| gh pr create --base "$base_branch" --head "$branch" \ | |
| --title "feat: $branch" \ | |
| --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.")" \ | |
| --label "$labels" | |
| echo "Created PR for $branch" | |
| else | |
| echo "PR #$existing_pr already exists for $branch" | |
| fi |