name: 'Usage of stale GitHub Action'
permissions:
contents: write # only for delete-branch option
issues: write
pull-requests: write
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/stale@v9
with:
stale-issue-message: >
'Message to comment on stale issues. If none provided, will not mark issues stale'
stale-pr-message: >
'Message to comment on stale PRs. If none provided, will not mark PRs stale'
stale
Marks issues and pull requests that have not had recent interaction
What is stale?
The GitHub Action for closing stale issues and PRs helps manage the lifecycle of contributions and discussions within a repository. This automation improves project maintenance by:
- Labeling issues and PRs as "Stale" after a specified period of inactivity.
- Automatically closing these stale items if the inactivity continues beyond an additional set duration.
- Resetting the stale status if there's any new activity, keeping relevant discussions open.
Benefits of Automating Stale Issue and PR Management
- Improved Efficiency: Automates the routine task of issue and PR triage, freeing up time for more critical development tasks.
- Enhanced Engagement: Encourages contributors to revisit and update or close their pending submissions.
- Project Clarity: Keeps the repository clean from old and unresolved issues or PRs, making it easier for maintainers and contributors to navigate and prioritize.
Configuring GitHub Actions to Manage Stale Issues and PRs with Different Timelines
For projects where issues tend to become irrelevant if not addressed or updated within a specific timeframe, we can set up an automated workflow to handle them accordingly. Here’s how you can configure GitHub Actions to mark issues as stale and close them if they remain inactive:
name: 'Close stale issues and PRs'
on:
schedule:
- cron: '30 1 * * *' # Scheduled to run at 1:30 AM every day
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
stale-issue-message: >
'This issue is stale because it has been open 30 days with no activity.'
days-before-stale: 30
days-before-close: 5
Configuring Different Timeouts for Issues and PRs, But Never Closing PRs
In some scenarios, you might want to treat issues and PRs differently, particularly to ensure that PRs are not closed automatically, giving contributors more time to address feedback.
name: 'Close stale issues and PR'
on:
schedule:
- cron: '30 1 * * *' # Scheduled to run at 1:30 AM every day
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
stale-issue-message: >
'This issue is stale because it has been open 30 days with no activity.'
stale-pr-message: >
'This PR is stale because it has been open 45 days with no activity.'
close-issue-message: >
'This issue was closed because it has been stalled for 5 days with no activity.'
days-before-stale: 30
days-before-close: 5
days-before-pr-close: -1 # PRs are marked as stale but not closed
How to Configure Labels and Date Restrictions for Stale Issues and PRs
For projects that require detailed tracking and management of issues and PRs, we can specify custom labels for stale issues/PRs and exempt certain items from being marked as stale based on their labels.
name: 'Close stale issues and PRs'
on:
schedule:
- cron: '30 1 * * *' # Scheduled to run at 1:30 AM every day
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
stale-issue-message: 'Stale issue message'
stale-pr-message: 'Stale pull request message'
stale-issue-label: 'no-issue-activity'
exempt-issue-labels: 'awaiting-approval,work-in-progress'
stale-pr-label: 'no-pr-activity'
exempt-pr-labels: 'awaiting-approval,work-in-progress'
only-labels: 'awaiting-feedback,awaiting-answers'
How to Prevent Stale Automation for PRs with Assignees
For projects that require maintaining active engagement on assigned PRs, we can configure the actions/stale
GitHub Action to ignore these PRs when performing stale checks. This ensures that PRs under active review or development are not closed automatically.
name: 'Close stale issues and PRs'
on:
schedule:
- cron: '30 1 * * *' # Scheduled to run at 1:30 AM every day
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
exempt-all-pr-assignees: true
Input Parameters for Configuring Stale Issue and PR Management
Input | Description |
---|---|
repo-token | A Personal Access Token (PAT) used for GitHub API authentication. |
days-before-stale | The number of days to wait before marking issues or PRs as stale due to inactivity. |
days-before-issue-stale | Specific number of days to wait before marking only issues as stale, overriding the general setting. |
days-before-pr-stale | Specific number of days to wait before marking only PRs as stale, overriding the general setting. |
days-before-close | The number of days to wait before closing issues or PRs marked as stale. |
days-before-issue-close | Specific number of days to wait before closing issues marked as stale, overriding the general setting. |
days-before-pr-close | Specific number of days to wait before closing PRs marked as stale, overriding the general setting. |
stale-issue-message | The message to post when an issue is marked as stale. |
stale-pr-message | The message to post when a PR is marked as stale. |
close-issue-message | The message to post when a stale issue is closed. |
close-pr-message | The message to post when a stale PR is closed. |
stale-issue-label | The label to apply to issues when they are marked as stale. |
close-issue-label | The label to apply to issues when they are closed after being stale. |
close-issue-reason | The reason provided when closing a stale issue. |
stale-pr-label | The label to apply to PRs when they are marked as stale. |
close-pr-label | The label to apply to PRs when they are closed after being stale. |
exempt-issue-labels | Labels that prevent issues from being marked as stale. |
exempt-pr-labels | Labels that prevent PRs from being marked as stale. |
only-labels | Labels that must all be present for an issue or PR to be checked for staleness. |
only-issue-labels | Specific labels that must all be present for issues only, overriding the general 'only-labels' setting. |
only-pr-labels | Specific labels that must all be present for PRs only, overriding the general 'only-labels' setting. |
any-of-labels | Labels where the presence of any will mark the issue or PR to be checked for staleness. |
any-of-issue-labels | Specific labels where the presence of any will mark issues only to be checked for staleness. |
any-of-pr-labels | Specific labels where the presence of any will mark PRs only to be checked for staleness. |
operations-per-run | The maximum number of operations the action can perform in one run. |
remove-stale-when-updated | Whether to remove the stale label when an update/comment occurs on the issue/PR. |
remove-issue-stale-when-updated | Whether to remove the stale label when an update/comment occurs on issues only. |
remove-pr-stale-when-updated | Whether to remove the stale label when an update/comment occurs on PRs only. |
labels-to-add-when-unstale | Labels to add to issues or PRs when they are no longer marked as stale. |
labels-to-remove-when-stale | Labels to remove from issues or PRs when they become stale. |
labels-to-remove-when-unstale | Labels to remove from issues or PRs when they are no longer marked as stale. |
debug-only | Whether to perform a dry-run without making any actual changes. |
ascending | Whether to fetch issues/PRs in ascending order based on creation date. |
start-date | Excludes issues/PRs created before this date from being marked as stale. |
delete-branch | Whether to delete the branch after closing a stale PR. |
exempt-milestones | Milestones that exempt issues/PRs from being marked as stale. |
exempt-issue-milestones | Specific milestones that exempt issues only from being marked as stale. |
exempt-pr-milestones | Specific milestones that exempt PRs only from being marked as stale. |
exempt-all-milestones | Exempts all issues and PRs with any milestones from being |