auto-approve-release-please.yml•1.93 kB
name: auto-approve release-please PRs
on:
pull_request:
types: [opened, labeled, synchronize, reopened, ready_for_review]
workflow_dispatch:
permissions:
contents: read
pull-requests: write
jobs:
auto-approve:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: Approve release-please PRs when labeled
env:
GH_TOKEN: ${{ secrets.AUTO_APPROVE_TOKEN }}
run: |
set -euo pipefail
if [ -z "${GH_TOKEN:-}" ]; then
echo "AUTO_APPROVE_TOKEN is not configured; skipping auto-approve to avoid self-approval errors"
exit 0
fi
PR_NUMBER='${{ github.event.pull_request.number }}'
REPO='${{ github.repository }}'
if [ -z "$PR_NUMBER" ]; then
echo "Not a pull_request event; skipping"
exit 0
fi
author=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json author -q .author.login)
head_ref=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json headRefName -q .headRefName)
title=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json title -q .title)
echo "author=$author head_ref=$head_ref title=$title"
if ! gh pr view "$PR_NUMBER" --repo "$REPO" --json labels -q '.labels[].name' | grep -Fx "autorelease: pending" >/dev/null; then
echo "Label 'autorelease: pending' not present; skipping"
exit 0
fi
if [ "$author" = "github-actions[bot]" ] || [ "$author" = "app/github-actions" ] || echo "$head_ref" | grep -q '^release-please--branches--' || echo "$title" | grep -q '^chore\(main\): release '; then
echo "Approving PR #$PR_NUMBER with AUTO_APPROVE_TOKEN actor"
gh pr review "$PR_NUMBER" --repo "$REPO" --approve || true
else
echo "PR does not match release-please criteria; skipping approval"
fi