Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ on:
schedule:
- cron: '19 4,16 * * *' # Twice daily at 19 minutes after the hour (random/uncommon time)

env:
KBE_LABEL: 'Known Build Error'
STALE_LABEL: 'stale'
KEEP_OPEN_LABEL: 'keep-open'

permissions:
actions: write # For managing the operation state cache
issues: write
Expand All @@ -23,4 +28,66 @@ jobs:
days-before-issue-close: 30
days-before-pr-stale: 180 # 6 months
days-before-pr-close: 7
exempt-issue-labels: ${{ env.KBE_LABEL }}
operations-per-run: 4000

# Known Build Error issues with 0 hits for a month get labeled Stale,
# then actions/stale closes them after 7 days.
stale-known-build-errors:
if: github.repository_owner == 'dotnet' # Do not run on forks

runs-on: ubuntu-latest
steps:
# Step 1: Label/unlabel based on hit counts
- uses: actions/github-script@v7
with:
script: |
const issues = await github.paginate(
github.rest.issues.listForRepo,
{ owner: context.repo.owner, repo: context.repo.repo,
labels: process.env.KBE_LABEL, state: 'open', per_page: 100 });

for (const issue of issues) {
Comment thread
MichaelSimons marked this conversation as resolved.
if (issue.pull_request) continue;
if (issue.labels.some(l => l.name === process.env.KEEP_OPEN_LABEL)) continue;

// Parse the hit count summary table from the issue body.
// Format: |24-Hour Hit Count|7-Day Hit Count|1-Month Count|
// |---|---|---|
// |N|N|N|
const match = issue.body?.match(
/\|24-Hour Hit Count\|.*\n\|[-| ]+\n\|(\d+)\|(\d+)\|(\d+)\|/);
if (!match) continue;
const monthCount = parseInt(match[3], 10);

const hasStale = issue.labels.some(l => l.name === process.env.STALE_LABEL);

if (monthCount === 0 && !hasStale) {
// Zero hits for a month: mark as stale
await github.rest.issues.addLabels({
...context.repo, issue_number: issue.number,
labels: [process.env.STALE_LABEL] });
await github.rest.issues.createComment({
...context.repo, issue_number: issue.number,
body: 'This Known Build Error has had **0 hits in the past month** and has been labeled `stale`. ' +
'It will be auto-closed in 7 days if the hit count remains at 0. ' +
'Add the `' + process.env.KEEP_OPEN_LABEL + '` label to prevent auto-closure.' });
} else if (monthCount > 0 && hasStale) {
// Hits resumed: remove the stale label
await github.rest.issues.removeLabel({
...context.repo, issue_number: issue.number,
name: process.env.STALE_LABEL }).catch(() => {});
}
}

# Step 2: Close KBE issues that have been Stale for 7+ days
- uses: actions/stale@v9
with:
only-labels: ${{ env.KBE_LABEL }}
stale-issue-label: ${{ env.STALE_LABEL }}
close-issue-message: 'Closed automatically — this Known Build Error has had 0 hits for over a month.'
days-before-issue-stale: -1 # Don't auto-stale; step 1 handles that
days-before-issue-close: 7
days-before-pr-stale: -1
days-before-pr-close: -1
operations-per-run: 100
Loading