Repository navigation
132 lines (128 loc) · 6.22 KB
/
Copy pathrot.yml
File metadata and controls
132 lines (128 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Health check
# The sweeper only counts runs named exactly "Health check" as a full check.
# A one-repo run names its repo, so reports.py can see a recent check of that entry.
run-name: "${{ inputs.repo && format('Health check: {0}', inputs.repo) || 'Health check' }}"
# Re-checks every listed repo each Monday: warns stale ones, archives them 30
# days later, brings back the ones that recover, follows renames and removes
# repos that are gone (only once a second run a week later agrees).
on:
# Started on time by the scheduler Worker (scheduler/); a stalled one is restarted by the sweep.
workflow_dispatch:
inputs:
repo:
description: owner/name of one entry to re-check (blank checks them all)
required: false
type: string
permissions: {}
# Shared with submit.yml so rot and submission PRs never race on entries.json.
concurrency:
group: list-writes
cancel-in-progress: false
jobs:
rot:
runs-on: ubuntu-latest
timeout-minutes: 120
permissions:
contents: read
steps:
- uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- id: token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ vars.APP_CLIENT_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
permission-discussions: write
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
token: ${{ steps.token.outputs.token }}
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.12"
# Any API failure exits non-zero here, before a PR, a comment or a stats write.
# REPO_INPUT is validated in Python before use.
- id: plan
env:
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
REPO_INPUT: ${{ inputs.repo }}
run: python -m scripts.rot plan --out "$RUNNER_TEMP/plan.json" >> "$GITHUB_OUTPUT"
# Entries left undecided 3 weeks running get a needs-review issue. Its own token, so the one
# that can push never carries issues: write, and a failure here never stops the check.
- id: issues_token
if: steps.plan.outputs.review == 'true'
continue-on-error: true
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ vars.APP_CLIENT_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
permission-issues: write
- if: steps.issues_token.outputs.token != ''
continue-on-error: true
env:
GITHUB_TOKEN: ${{ steps.issues_token.outputs.token }}
run: python -m scripts.rot review --plan "$RUNNER_TEMP/plan.json"
- id: pr
if: steps.plan.outputs.changed == 'true'
env:
GH_TOKEN: ${{ steps.token.outputs.token }}
run: |
branch="rot/$GITHUB_RUN_ID"
subject="chore(list): weekly health check"
git switch -c "$branch"
git add data/entries.json
git -c user.name='devstreamhq-bot[bot]' \
-c user.email='353074438+devstreamhq-bot[bot]@users.noreply.github.com' \
commit -m "$subject"
git push origin "$branch"
python -m scripts.rot body --plan "$RUNNER_TEMP/plan.json" > "$RUNNER_TEMP/pr-body.md"
url=$(gh pr create --base main --head "$branch" --title "$subject" --body-file "$RUNNER_TEMP/pr-body.md")
echo "url=$url" >> "$GITHUB_OUTPUT"
# An explicit body stops GitHub adding its Co-authored-by trailer to the squash commit.
gh pr merge "$url" --auto --squash --subject "$subject" --body "Weekly health check."
# Holding the concurrency lock until the merge lands keeps the next writer off a stale entries.json.
# No merge means no comments and no stats writes.
- if: steps.plan.outputs.changed == 'true'
env:
GH_TOKEN: ${{ steps.token.outputs.token }}
PR_URL: ${{ steps.pr.outputs.url }}
run: |
for _ in $(seq 45); do
[ "$(gh pr view "$PR_URL" --json state --jq .state)" = MERGED ] && exit 0
sleep 20
done
# Closing also disarms auto-merge, so it can't land later behind our backs.
# It may have merged in the meantime, so look once more.
gh pr close "$PR_URL" || true # fails if it merged meanwhile; the check below decides
[ "$(gh pr view "$PR_URL" --json state --jq .state)" = MERGED ] && exit 0
echo "::error::$PR_URL did not merge within 15 minutes and is now closed"
exit 1
# Minted after the merge wait, so no later step runs on a token that expired during it.
- id: late_token
if: always() && steps.pr.outputs.url != ''
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ vars.APP_CLIENT_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
permission-discussions: write
- if: steps.plan.outputs.changed == 'true'
env:
GITHUB_TOKEN: ${{ steps.late_token.outputs.token || steps.token.outputs.token }}
run: python -m scripts.rot finish --plan "$RUNNER_TEMP/plan.json"
# Only after finish has moved a renamed entry's thread to its new key, or this would open a second one.
- if: steps.plan.outputs.changed == 'true'
env:
GITHUB_TOKEN: ${{ steps.late_token.outputs.token || steps.token.outputs.token }}
run: python -m scripts.on_merge
# A cancel or job timeout releases the lock, so the armed PR must not merge behind the next writer.
# Timeouts reach this step too: the runner re-evaluates later steps' if: on any job cancellation.
- if: cancelled() && steps.pr.outputs.url != ''
env:
GH_TOKEN: ${{ steps.late_token.outputs.token || steps.token.outputs.token }}
PR_URL: ${{ steps.pr.outputs.url }}
run: gh pr close "$PR_URL" || true # fails if it merged meanwhile