bump-plugin-shas.yml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. name: Bump plugin SHAs
  2. # Weekly sweep of marketplace.json — for each entry whose upstream repo has
  3. # moved past its pinned SHA, open a PR against main with updated SHAs. The
  4. # validate-marketplace workflow then runs on the PR to confirm the file is
  5. # still well-formed.
  6. #
  7. # Adapted from claude-plugins-community-internal's bump-plugin-shas.yml
  8. # for the single-file marketplace.json format. Key difference: all bumps
  9. # are batched into one PR (since they all modify the same file).
  10. on:
  11. schedule:
  12. - cron: '23 7 * * 1' # Monday 07:23 UTC
  13. workflow_dispatch:
  14. inputs:
  15. plugin:
  16. description: Only bump this plugin (for testing)
  17. required: false
  18. max_bumps:
  19. description: Cap on plugins bumped this run
  20. required: false
  21. default: '20'
  22. dry_run:
  23. description: Discover only, don't open PR
  24. type: boolean
  25. default: true
  26. concurrency:
  27. group: bump-plugin-shas
  28. cancel-in-progress: false
  29. permissions:
  30. contents: write
  31. pull-requests: write
  32. jobs:
  33. bump:
  34. runs-on: ubuntu-latest
  35. timeout-minutes: 15
  36. steps:
  37. - uses: actions/checkout@v4
  38. - name: Check for existing bump PR
  39. id: existing
  40. env:
  41. GH_TOKEN: ${{ github.token }}
  42. run: |
  43. existing=$(gh pr list --label sha-bump --state open --json number --jq 'length')
  44. echo "count=$existing" >> "$GITHUB_OUTPUT"
  45. if [ "$existing" -gt 0 ]; then
  46. echo "::notice::Open sha-bump PR already exists — skipping"
  47. fi
  48. - name: Ensure sha-bump label exists
  49. if: steps.existing.outputs.count == '0'
  50. env:
  51. GH_TOKEN: ${{ github.token }}
  52. run: gh label create sha-bump --color 0e8a16 --description "Automated SHA bump" 2>/dev/null || true
  53. - name: Overlay marketplace data from main
  54. if: steps.existing.outputs.count == '0'
  55. run: |
  56. git fetch origin main --depth=1 --quiet
  57. git checkout origin/main -- .claude-plugin/marketplace.json
  58. - name: Discover and apply SHA bumps
  59. if: steps.existing.outputs.count == '0'
  60. id: discover
  61. env:
  62. GH_TOKEN: ${{ github.token }}
  63. PR_BODY_PATH: /tmp/bump-pr-body.md
  64. PLUGIN: ${{ inputs.plugin }}
  65. MAX_BUMPS: ${{ inputs.max_bumps }}
  66. DRY_RUN: ${{ inputs.dry_run }}
  67. run: |
  68. args=(--max "${MAX_BUMPS:-20}")
  69. [[ -n "$PLUGIN" ]] && args+=(--plugin "$PLUGIN")
  70. [[ "$DRY_RUN" = "true" ]] && args+=(--dry-run)
  71. python3 .github/scripts/discover_bumps.py "${args[@]}"
  72. - uses: oven-sh/setup-bun@v2
  73. if: steps.existing.outputs.count == '0' && steps.discover.outputs.count != '0' && inputs.dry_run != true
  74. - name: Validate marketplace.json
  75. if: steps.existing.outputs.count == '0' && steps.discover.outputs.count != '0' && inputs.dry_run != true
  76. run: |
  77. bun .github/scripts/validate-marketplace.ts .claude-plugin/marketplace.json
  78. bun .github/scripts/check-marketplace-sorted.ts
  79. - name: Push bump branch
  80. if: steps.existing.outputs.count == '0' && steps.discover.outputs.count != '0' && inputs.dry_run != true
  81. id: push
  82. run: |
  83. branch="auto/bump-shas-$(date +%Y%m%d)"
  84. echo "branch=$branch" >> "$GITHUB_OUTPUT"
  85. git config user.name "github-actions[bot]"
  86. git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
  87. git checkout -b "$branch"
  88. git add .claude-plugin/marketplace.json
  89. git commit -m "Bump SHA pins for ${{ steps.discover.outputs.count }} plugin(s)
  90. Plugins: ${{ steps.discover.outputs.bumped_names }}"
  91. git push -u origin "$branch" --force-with-lease
  92. # GITHUB_TOKEN cannot create PRs (org policy: "Allow GitHub Actions to
  93. # create and approve pull requests" is disabled). Use the same GitHub App
  94. # that -internal's bump workflow uses.
  95. #
  96. # Prerequisite: app 2812036 must be installed on this repo. The PEM
  97. # secret must exist in this repo's settings (shared with -internal).
  98. - name: Generate bot token
  99. if: steps.push.outcome == 'success'
  100. id: app-token
  101. uses: actions/create-github-app-token@v1
  102. with:
  103. app-id: 2812036
  104. private-key: ${{ secrets.CLAUDE_DIRECTORY_BOT_PRIVATE_KEY }}
  105. owner: ${{ github.repository_owner }}
  106. repositories: ${{ github.event.repository.name }}
  107. - name: Create pull request
  108. if: steps.push.outcome == 'success'
  109. env:
  110. GH_TOKEN: ${{ steps.app-token.outputs.token }}
  111. run: |
  112. gh pr create \
  113. --base main \
  114. --head "${{ steps.push.outputs.branch }}" \
  115. --title "Bump SHA pins (${{ steps.discover.outputs.count }} plugins)" \
  116. --body-file /tmp/bump-pr-body.md \
  117. --label sha-bump