Files
orca/.github/workflows/readme-downloads-badge.yml
Jinwoo Hong 8ca8a7b7ab ci: auto-merge the README downloads badge PR (#38658)
* ci: auto-merge the README downloads badge PR

main is PR-only, so the badge workflow's PR sat unmerged and the badge stopped updating. Enable auto-merge (squash) on the PR after each update; it merges once 'PR checks passed' succeeds.

* ci: auto-merge the badge PR by its URL

Merge the PR the step created or found (scoped to main) rather than resolving the branch name again.

* ci: ignore fork PRs when finding the badge PR

A fork PR can reuse the badge branch name; only the bot's own same-repo PR may get auto-merge.
2026-11-05 19:32:27 -05:00

90 lines
3.1 KiB
YAML

name: README Downloads Badge
on:
workflow_dispatch:
schedule:
- cron: '17 */6 * * *'
release:
types:
- published
- edited
- deleted
permissions:
contents: read
concurrency:
group: readme-downloads-badge
cancel-in-progress: false
jobs:
update:
# Badge updates belong to the upstream repository.
if: github.repository == 'stablyai/orca'
runs-on: ubuntu-latest
steps:
- name: Generate badge update token
id: app-token
uses: actions/create-github-app-token@v3
with:
app-id: 2590194
private-key: ${{ secrets.BUFO_BOT_PRIVATE_KEY }}
owner: stablyai
repositories: orca
permission-contents: write
permission-pull-requests: write
- name: Checkout main
uses: actions/checkout@v6
with:
ref: main
token: ${{ steps.app-token.outputs.token }}
- name: Render downloads badge
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: node .github/scripts/render-readme-downloads-badge.mjs
- name: Propose badge update
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
set -euo pipefail
if git diff --quiet -- docs/assets/readme-downloads.svg; then
echo "Downloads badge is already current."
exit 0
fi
branch="automation/readme-downloads-badge"
expected="$(git ls-remote --heads origin "refs/heads/$branch" | cut -f1)"
git checkout -b "$branch"
git config user.name "buf0-bot[bot]"
git config user.email "252831055+buf0-bot[bot]@users.noreply.github.com"
git add docs/assets/readme-downloads.svg
git commit -m "Update README downloads badge"
git push --force-with-lease="refs/heads/$branch:$expected" origin "HEAD:refs/heads/$branch"
# Why: a fork PR can reuse this branch name; auto-merge must only ever target the bot's own PR.
existing="$(gh pr list --repo "$GITHUB_REPOSITORY" --state open --base main --head "$branch" --json url,isCrossRepository --jq '[.[] | select(.isCrossRepository == false)][0].url // empty')"
if [ -n "$existing" ]; then
echo "Updated $existing"
pr_url="$existing"
else
body="$RUNNER_TEMP/readme-downloads-pr.md"
cat > "$body" <<'BODY'
## ELI5
Refresh the README downloads badge with the current release download count.
## Visual Proof
N/A — generated badge count only; no application UI change.
## Testing
Generated from published release assets by the README Downloads Badge workflow.
BODY
pr_url="$(gh pr create --repo "$GITHUB_REPOSITORY" --base main --head "$branch" \
--title "Update README downloads badge" --body-file "$body")"
fi
# Why: main only accepts PRs, so the badge PR merges itself once its required check passes.
gh pr merge "$pr_url" --repo "$GITHUB_REPOSITORY" --auto --squash