|
| 1 | +name: Reusable Stale PRs and Stale Issues |
| 2 | + |
| 3 | +# This workflow analyzes pull requests and issues to identify and close stale ones that have not had any activity for |
| 4 | +# a specified period. It will first add a stale label to the issue or PR, and if there is still no activity |
| 5 | +# after a specified duration, it will close the issue or PR. It can also delete the branch if the PR is closed. |
| 6 | +# It should be run on a nightly schedule. It's a thin wrapper with defaults set for https://github.com/actions/stale. |
| 7 | +# |
| 8 | +# Usage: |
| 9 | +# |
| 10 | +# name: Manage stale Issues and PRs |
| 11 | +# |
| 12 | +# on: |
| 13 | +# schedule: |
| 14 | +# - cron: "0 0 * * *" # Will be triggered every day at midnight UTC |
| 15 | +# jobs: |
| 16 | +# permissions: |
| 17 | +# actions: write |
| 18 | +# contents: write |
| 19 | +# issues: write |
| 20 | +# pull-requests: write |
| 21 | +# stale-prs: |
| 22 | +# uses: smartcontractkit/.github/.github/workflows/reusable-stale-prs-issues.yml@<ref> |
| 23 | +# with: |
| 24 | +# days-before-pr-stale: 30 # Optional, default value is "30" |
| 25 | +# secrets: |
| 26 | +# GH_TOKEN: $\{{ secrets.GITHUB_TOKEN }} # Remove the \ char to unescape. |
| 27 | + |
| 28 | +on: |
| 29 | + workflow_call: |
| 30 | + # See: https://github.com/actions/stale?tab=readme-ov-file#list-of-input-options for inputs. |
| 31 | + inputs: |
| 32 | + close-pr-message: |
| 33 | + description: | |
| 34 | + The message to post on the pull request when closing it. |
| 35 | + If none provided, will not comment when closing a pull requests. |
| 36 | +
|
| 37 | + We default to one within the action if this is not provided. |
| 38 | + required: false |
| 39 | + type: string |
| 40 | + delete-branch: |
| 41 | + description: "Delete the branch if the PR is closed" |
| 42 | + required: false |
| 43 | + type: boolean |
| 44 | + default: true |
| 45 | + days-before-issue-close: |
| 46 | + description: "Duration after which a stale issue will be closed" |
| 47 | + required: false |
| 48 | + type: string |
| 49 | + default: "" # unset |
| 50 | + days-before-issue-stale: |
| 51 | + description: "Duration after which an issue is considered stale" |
| 52 | + required: false |
| 53 | + type: string |
| 54 | + default: "-1" # disables marking issues as stale automatically |
| 55 | + days-before-pr-close: |
| 56 | + description: "Duration after which a stale PR will be closed" |
| 57 | + required: false |
| 58 | + type: string |
| 59 | + default: "7" |
| 60 | + days-before-pr-stale: |
| 61 | + description: "Duration after which a PR is considered stale" |
| 62 | + required: false |
| 63 | + type: string |
| 64 | + default: "30" # days |
| 65 | + exempt-all-pr-assignees: |
| 66 | + description: "Exempt all PRs with assignees from being considered stale" |
| 67 | + required: false |
| 68 | + type: boolean |
| 69 | + default: true |
| 70 | + exempt-draft-pr: |
| 71 | + description: "Exempt all draft PRs from being considered stale" |
| 72 | + required: false |
| 73 | + type: boolean |
| 74 | + default: false |
| 75 | + operations-per-run: |
| 76 | + description: | |
| 77 | + The maximum number of operations per run, used to control rate |
| 78 | + limiting (GitHub API CRUD related). |
| 79 | + required: false |
| 80 | + type: string |
| 81 | + default: "30" |
| 82 | + stale-pr-message: |
| 83 | + description: | |
| 84 | + The message to post on the pull request when tagging it. If none |
| 85 | + provided, will not mark pull requests stale. |
| 86 | +
|
| 87 | + We default to one within the action if this is not provided. |
| 88 | + required: false |
| 89 | + type: string |
| 90 | + secrets: |
| 91 | + GH_TOKEN: |
| 92 | + description: "GitHub token for authentication" |
| 93 | + required: true |
| 94 | + |
| 95 | +permissions: {} |
| 96 | + |
| 97 | +jobs: |
| 98 | + stale: |
| 99 | + runs-on: ubuntu-latest |
| 100 | + # See: https://github.com/actions/stale?tab=readme-ov-file#recommended-permissions |
| 101 | + permissions: |
| 102 | + actions: write |
| 103 | + contents: write # only for delete-branch option |
| 104 | + issues: write |
| 105 | + pull-requests: write |
| 106 | + |
| 107 | + steps: |
| 108 | + - uses: actions/stale@v10 |
| 109 | + env: |
| 110 | + CLOSE_PR_MESSAGE: | |
| 111 | + This PR has been automatically closed because it had been stale for > ${{ inputs.days-before-pr-stale }} days. |
| 112 | + If you wish to continue working on this PR, please reopen it to make any necessary changes. |
| 113 | + STALE_PR_MESSAGE: | |
| 114 | + This PR is stale because it has been open ${{ inputs.days-before-pr-stale }} days with no activity. |
| 115 | + Remove the `stale` label, comment, or update this PR to prevent this PR from being closed in ${{ inputs.days-before-pr-close }} days. |
| 116 | + with: |
| 117 | + repo-token: ${{ secrets.GH_TOKEN }} |
| 118 | + close-pr-message: ${{ inputs.close-pr-message || env.CLOSE_PR_MESSAGE }} |
| 119 | + days-before-issue-close: ${{ inputs.days-before-issue-close }} |
| 120 | + days-before-issue-stale: ${{ inputs.days-before-issue-stale }} |
| 121 | + days-before-pr-close: ${{ inputs.days-before-pr-close }} |
| 122 | + days-before-pr-stale: ${{ inputs.days-before-pr-stale }} |
| 123 | + delete-branch: ${{ inputs.delete-branch }} |
| 124 | + exempt-all-pr-assignees: ${{ inputs.exempt-all-pr-assignees }} |
| 125 | + exempt-draft-pr: ${{ inputs.exempt-draft-pr }} |
| 126 | + # Comma separated list of labels that exempt issues from being considered stale. |
| 127 | + exempt-pr-labels: "stale-exempt" |
| 128 | + operations-per-run: ${{ inputs.operations-per-run }} |
| 129 | + stale-pr-message: ${{ inputs.stale-pr-message || env.STALE_PR_MESSAGE }} |
0 commit comments