Skip to content

Auto-merge main-to-amd-staging after Multi-Arch CI (amd-staging) #459

Auto-merge main-to-amd-staging after Multi-Arch CI (amd-staging)

Auto-merge main-to-amd-staging after Multi-Arch CI (amd-staging) #459

# Runs after rockci_multi_arch_amd_staging.yml completes successfully, then enables auto-merge
# with merge commit. Avoids racing pull_request automerge before Multi-Arch CI has queued checks.
#
# Upstream workflow name must match exactly (see `name:` in that file):
# .github/workflows/rockci_multi_arch_amd_staging.yml → "Multi-Arch CI amd-staging"
#
# Requires: Variable ROCM_CCIAPP_APP_ID + Secret ROCM_CCIAPP_PRIVATE_KEY (same as other automerge).
# Repo must allow auto-merge for `gh pr merge --auto`.
name: Auto-merge main-to-amd-staging after Multi-Arch CI (amd-staging)
on:
workflow_run:
workflows: ["Multi-Arch CI amd-staging"]
types: [completed]
permissions:
contents: read
pull-requests: read
checks: read
concurrency:
group: automerge-after-rockci-${{ github.event.workflow_run.head_sha }}
cancel-in-progress: true
jobs:
merge-after-multi-arch-ci:
name: Queue auto-merge after successful Multi-Arch CI
runs-on: ubuntu-latest
if: >-
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.head_repository.full_name == github.repository &&
contains(github.event.workflow_run.display_title, 'merge main into amd-staging')
steps:
- uses: actions/create-github-app-token@v2
id: rocm-cciapp
if: ${{ vars.ROCM_CCIAPP_APP_ID != '' }}
with:
app-id: ${{ vars.ROCM_CCIAPP_APP_ID }}
private-key: ${{ secrets.ROCM_CCIAPP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- name: Resolve PR and enable auto-merge (merge commit)
env:
ROCM_CCIAPP_TOKEN: ${{ steps.rocm-cciapp.outputs.token }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
REPO: ${{ github.repository }}
PULL_REQUESTS_JSON: ${{ toJSON(github.event.workflow_run.pull_requests) }}
run: |
set -euo pipefail
if [ -z "${ROCM_CCIAPP_TOKEN:-}" ]; then
echo "::error::Set Variable ROCM_CCIAPP_APP_ID and Secret ROCM_CCIAPP_PRIVATE_KEY."
exit 1
fi
export GH_TOKEN="$ROCM_CCIAPP_TOKEN"
# Prefer workflow_run.pull_requests when GitHub attaches it (same-repo PRs).
PR=""
if command -v jq >/dev/null 2>&1; then
PR=$(echo "${PULL_REQUESTS_JSON}" | jq -r '
if . == null or . == [] then empty
elif type == "array" then .[0].number | tostring
else empty end' 2>/dev/null || true)
fi
if [ -z "${PR}" ] || [ "${PR}" = "null" ]; then
PR="$(gh pr list --repo "${REPO}" --head "${HEAD_BRANCH}" --base amd-staging --state open \
--json number -q '.[0].number // empty' 2>/dev/null || true)"
fi
if [ -z "${PR}" ] || [ "${PR}" = "null" ]; then
echo "No open PR found for head branch ${HEAD_BRANCH} → amd-staging; skipping."
exit 0
fi
BASE="$(gh pr view "${PR}" --repo "${REPO}" --json baseRefName -q .baseRefName)"
if [ "${BASE}" != "amd-staging" ]; then
echo "PR #${PR} base is ${BASE}, not amd-staging; skipping."
exit 0
fi
DRAFT="$(gh pr view "${PR}" --repo "${REPO}" --json isDraft -q .isDraft)"
if [ "${DRAFT}" = "true" ]; then
echo "PR #${PR} is draft; skipping."
exit 0
fi
echo "Enabling auto-merge (merge commit) for PR #${PR} (${REPO}) after successful Multi-Arch CI."
gh pr merge "${PR}" --repo "${REPO}" --merge --auto