@@ -30,13 +30,13 @@ jobs:
30
30
script : |
31
31
const cancelled = await github.rest.actions.listWorkflowRunsForRepo({
32
32
owner: context.repo.owner,
33
- per_page: 100 ,
33
+ per_page: 50 ,
34
34
repo: context.repo.repo,
35
35
status: 'cancelled',
36
36
});
37
37
const skipped = await github.rest.actions.listWorkflowRunsForRepo({
38
38
owner: context.repo.owner,
39
- per_page: 100 ,
39
+ per_page: 50 ,
40
40
repo: context.repo.repo,
41
41
status: 'skipped',
42
42
});
@@ -70,17 +70,19 @@ jobs:
70
70
let response = await github.rest.actions.listWorkflowRuns({
71
71
owner: context.repo.owner,
72
72
page: page,
73
- per_page: 100 ,
73
+ per_page: 50 ,
74
74
repo: context.repo.repo,
75
75
workflow_id: workflow
76
76
});
77
+ if (response.data.workflow_runs.length === 0) break;
77
78
if (response.data.workflow_runs.length > 0) {
78
79
for (const run of response.data.workflow_runs) {
79
80
if (now - Date.parse(run.created_at) > ms_in_day * days_to_expiration) {
80
81
runs_to_delete.push([run.id, run.name]);
81
82
}
82
83
}
83
84
}
85
+ if (response.data.workflow_runs.length < 50) break;
84
86
}
85
87
}
86
88
for (const run of runs_to_delete) {
@@ -104,24 +106,96 @@ jobs:
104
106
script : |
105
107
const pages = 5;
106
108
let runs_to_delete = [];
109
+ // Get all workflows
110
+ const { data: workflowsData } = await github.rest.actions.listRepoWorkflows({
111
+ owner: context.repo.owner,
112
+ repo: context.repo.repo
113
+ });
114
+ // Find workflow by name
115
+ const workflowName = "Clean Workflow Runs";
116
+ const workflow = workflowsData.workflows.find(w => w.name === workflowName);
117
+ if (!workflow) {
118
+ console.log(`❌ No workflow named ${workflowName} found.`);
119
+ return;
120
+ }
121
+ const workflowId = workflow.id;
122
+ console.log(`✅ Found workflow ID: ${workflowId}`);
123
+ // Fetch workflow runs
107
124
for (let page = 0; page < pages; page += 1) {
108
- let response = await github.rest.actions.listWorkflowRuns({
125
+ const response = await github.rest.actions.listWorkflowRuns({
109
126
owner: context.repo.owner,
127
+ repo: context.repo.repo,
128
+ workflow_id: workflowId, // Use dynamically fetched ID
110
129
page: page,
111
- per_page: 100,
130
+ per_page: 50,
131
+ });
132
+ if (response.data.workflow_runs.length === 0) break;
133
+ if (response.data.workflow_runs.length > 0) {
134
+ for (const run of response.data.workflow_runs) {
135
+ runs_to_delete.push([run.id, run.name]);
136
+ }
137
+ }
138
+ if (response.data.workflow_runs.length < 50) break;
139
+ }
140
+ // Delete workflow runs
141
+ for (const run of runs_to_delete) {
142
+ console.log(`[Deleting] Run id ${run[0]} of '${run[1]}'.`);
143
+ try {
144
+ await github.rest.actions.deleteWorkflowRun({
145
+ owner: context.repo.owner,
146
+ repo: context.repo.repo,
147
+ run_id: run[0]
148
+ });
149
+ } catch (error) {
150
+ // ignore errors
151
+ }
152
+ }
153
+
154
+ - name : ✂ Remove Dependabot workflow runs
155
+ uses : actions/github-script@v7 # https://github.com/actions/github-script
156
+ with :
157
+ github-token : ${{ secrets.GITHUB_TOKEN }}
158
+ script : |
159
+ const pages = 5;
160
+ let runs_to_delete = [];
161
+ // Get all workflows
162
+ const { data: workflowsData } = await github.rest.actions.listRepoWorkflows({
163
+ owner: context.repo.owner,
164
+ repo: context.repo.repo
165
+ });
166
+ // Find workflow by name
167
+ const workflowName = "Dependabot Updates";
168
+ const workflow = workflowsData.workflows.find(w => w.name === workflowName);
169
+ if (!workflow) {
170
+ console.log(`❌ No workflow named ${workflowName} found.`);
171
+ return;
172
+ }
173
+ const workflowId = workflow.id;
174
+ console.log(`✅ Found workflow ID: ${workflowId}`);
175
+ // Fetch workflow runs
176
+ for (let page = 0; page < pages; page += 1) {
177
+ const response = await github.rest.actions.listWorkflowRuns({
178
+ owner: context.repo.owner,
112
179
repo: context.repo.repo,
113
- workflow_id: 'clean-workflows.yml'
180
+ workflow_id: workflowId, // Use dynamically fetched ID
181
+ page: page,
182
+ per_page: 50,
114
183
});
184
+ if (response.data.workflow_runs.length === 0) break;
115
185
if (response.data.workflow_runs.length > 0) {
116
186
for (const run of response.data.workflow_runs) {
187
+ if (run.triggering_actor?.login === 'dependabot[bot]') {
117
188
runs_to_delete.push([run.id, run.name]);
189
+ }
118
190
}
119
191
}
192
+ if (response.data.workflow_runs.length < 50) break;
120
193
}
194
+ // Delete workflow runs
121
195
for (const run of runs_to_delete) {
122
196
console.log(`[Deleting] Run id ${run[0]} of '${run[1]}'.`);
123
197
try {
124
- await github.actions.deleteWorkflowRun({
198
+ await github.rest. actions.deleteWorkflowRun({
125
199
owner: context.repo.owner,
126
200
repo: context.repo.repo,
127
201
run_id: run[0]
0 commit comments