|
| 1 | +name: 'Centralized Organization Stale Bot' |
| 2 | +permissions: {} |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run daily at 01:00 UTC |
| 6 | + - cron: '0 1 * * *' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + # Stage 1: Query the organization for all active repositories |
| 11 | + fetch-repositories: |
| 12 | + runs-on: 'ubuntu-latest' |
| 13 | + outputs: |
| 14 | + matrix: '${{ steps.set-matrix.outputs.repos }}' |
| 15 | + steps: |
| 16 | + - id: 'auth-minty' |
| 17 | + name: 'Authenticate to Google Cloud' |
| 18 | + uses: 'google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f' # ratchet:google-github-actions/auth@v2 |
| 19 | + with: |
| 20 | + create_credentials_file: false |
| 21 | + export_environment_variables: false |
| 22 | + workload_identity_provider: '${{ vars.TOKEN_MINTER_WIF_PROVIDER }}' |
| 23 | + service_account: '${{ vars.TOKEN_MINTER_WIF_SERVICE_ACCOUNT }}' |
| 24 | + token_format: 'id_token' |
| 25 | + id_token_audience: '${{ vars.TOKEN_MINTER_SERVICE_AUDIENCE }}' |
| 26 | + id_token_include_email: true |
| 27 | + |
| 28 | + - id: 'mint-github-token' |
| 29 | + uses: 'abcxyz/github-token-minter/.github/actions/minty@45c29ca3418ff3bb3ad5815d88a80536efeba21b' # ratchet:abcxyz/github-token-minter/.github/actions/minty@main |
| 30 | + with: |
| 31 | + id_token: '${{ steps.auth-minty.outputs.id_token }}' |
| 32 | + service_url: '${{ vars.TOKEN_MINTER_SERVICE_URL }}' |
| 33 | + requested_permissions: |- |
| 34 | + { |
| 35 | + "scope": "stale-bot", |
| 36 | + "repositories": ["*"], |
| 37 | + "org_name": "google-github-actions" |
| 38 | + } |
| 39 | +
|
| 40 | + - name: 'List active repositories' |
| 41 | + id: set-matrix |
| 42 | + env: |
| 43 | + GH_TOKEN: '${{ steps.mint-github-token.outputs.token }}' |
| 44 | + run: | |
| 45 | + # Query GitHub API for active, public, non-forked repositories and force single-line JSON to prevent GITHUB_OUTPUT truncation |
| 46 | + REPOS=$(gh api --paginate /orgs/google-github-actions/repos | jq -s 'add | [.[] | select(.archived == false and .private == false and .fork == false) | .name]' -c) |
| 47 | + echo "repos=${REPOS}" >> "$GITHUB_OUTPUT" |
| 48 | +
|
| 49 | + # Stage 2: Fan out official actions/stale across all discovered repositories |
| 50 | + apply-stale-rules: |
| 51 | + needs: fetch-repositories |
| 52 | + runs-on: 'ubuntu-latest' |
| 53 | + strategy: |
| 54 | + fail-fast: false |
| 55 | + matrix: |
| 56 | + repo: '${{ fromJson(needs.fetch-repositories.outputs.matrix) }}' |
| 57 | + |
| 58 | + steps: |
| 59 | + - id: 'auth-minty' |
| 60 | + name: 'Authenticate to Google Cloud' |
| 61 | + uses: 'google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f' # ratchet:google-github-actions/auth@v2 |
| 62 | + with: |
| 63 | + create_credentials_file: false |
| 64 | + export_environment_variables: false |
| 65 | + workload_identity_provider: '${{ vars.TOKEN_MINTER_WIF_PROVIDER }}' |
| 66 | + service_account: '${{ vars.TOKEN_MINTER_WIF_SERVICE_ACCOUNT }}' |
| 67 | + token_format: 'id_token' |
| 68 | + id_token_audience: '${{ vars.TOKEN_MINTER_SERVICE_AUDIENCE }}' |
| 69 | + id_token_include_email: true |
| 70 | + |
| 71 | + - id: 'mint-github-token' |
| 72 | + uses: 'abcxyz/github-token-minter/.github/actions/minty@45c29ca3418ff3bb3ad5815d88a80536efeba21b' # ratchet:abcxyz/github-token-minter/.github/actions/minty@main |
| 73 | + with: |
| 74 | + id_token: '${{ steps.auth-minty.outputs.id_token }}' |
| 75 | + service_url: '${{ vars.TOKEN_MINTER_SERVICE_URL }}' |
| 76 | + requested_permissions: |- |
| 77 | + { |
| 78 | + "scope": "stale-bot", |
| 79 | + "repositories": ["${{ matrix.repo }}"], |
| 80 | + "org_name": "google-github-actions" |
| 81 | + } |
| 82 | +
|
| 83 | + - name: 'Run official stale bot' |
| 84 | + uses: 'actions/stale@b5d41d4e1d5dceea10e7104786b73624c18a190f' # ratchet:actions/stale@v10.2.0 |
| 85 | + env: |
| 86 | + GITHUB_REPOSITORY: 'google-github-actions/${{ matrix.repo }}' |
| 87 | + with: |
| 88 | + repo-token: '${{ steps.mint-github-token.outputs.token }}' |
| 89 | + operations-per-run: 300 # Increased burndown limit for first execution |
| 90 | + |
| 91 | + # Issue configuration (60 days total: 53 inactive + 7 warning) |
| 92 | + days-before-issue-stale: 53 |
| 93 | + days-before-issue-close: 7 |
| 94 | + stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs.' |
| 95 | + stale-issue-label: 'stale' |
| 96 | + |
| 97 | + # PR configuration (30 days total: 23 inactive + 7 warning) |
| 98 | + days-before-pr-stale: 23 |
| 99 | + days-before-pr-close: 7 |
| 100 | + stale-pr-message: 'This pull request has been automatically marked as stale because it has not had recent activity. Please leave a comment to remove this status.' |
| 101 | + stale-pr-label: 'stale' |
0 commit comments