-
Notifications
You must be signed in to change notification settings - Fork 17
67 lines (62 loc) · 2.29 KB
/
Copy pathaudit_disabled_workflows.yml
File metadata and controls
67 lines (62 loc) · 2.29 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
name: Audit disabled workflows
on:
push:
branches:
- dev
pull_request_target:
workflow_dispatch:
permissions:
actions: read
issues: write
jobs:
audit:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
steps:
- name: Find inactivity-disabled workflows and open an issue if any
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const workflows = await github.paginate(
github.rest.actions.listRepoWorkflows,
{ owner, repo, per_page: 100 }
);
const disabled = workflows.filter(w => w.state === 'disabled_inactivity');
if (disabled.length === 0) {
core.info('No workflows in disabled_inactivity state.');
return;
}
const title = '[CI] Workflow(s) auto-disabled by GitHub for inactivity';
const existing = await github.paginate(
github.rest.issues.listForRepo,
{ owner, repo, state: 'open', per_page: 100 }
);
if (existing.some(i => i.title === title)) {
core.info(`Open issue with title "${title}" already exists; skipping.`);
return;
}
const list = disabled
.map(w => `- **${w.name}** (\`${w.path}\`, id ${w.id})`)
.join('\n');
const body = [
'GitHub has auto-disabled the following workflow(s) for inactivity.',
'While in this state, the workflow does **not** run on any trigger,',
'including `pull_request` and `push`.',
'',
list,
'',
'To re-enable, run:',
'',
'```',
...disabled.map(w => `gh workflow enable ${w.id} --repo ${owner}/${repo}`),
'```',
'',
'Or click "Enable workflow" in the Actions tab.',
'',
`Detected by \`${context.workflow}\` on ${new Date().toISOString()}.`,
].join('\n');
await github.rest.issues.create({ owner, repo, title, body });
core.info(`Opened issue: ${title}`);