2222 runs-on : ubuntu-24.04
2323 timeout-minutes : 10
2424
25+ # List Workflow Runs: https://api.github.com/repos/jakoch/cpp-devbox/actions/workflows
2526 steps :
2627 - name : ✂ Remove cancelled or skipped workflow runs
2728 uses : actions/github-script@v8 # https://github.com/actions/github-script
@@ -151,6 +152,7 @@ jobs:
151152 // ignore errors
152153 }
153154 }
155+
154156 - name : ✂ Remove Dependabot workflow runs
155157 uses : actions/github-script@v8 # https://github.com/actions/github-script
156158 with :
@@ -193,4 +195,56 @@ jobs:
193195 console.warn(`⚠️ Failed to delete run ${runId}: ${error.message}`);
194196 }
195197 }
196- console.log("✅ Cleanup complete.");
198+ console.log("✅ Cleanup complete.");
199+
200+ - name : ✂ Remove pages-build-deployment (gh-pages) workflow runs
201+ uses : actions/github-script@v8 # https://github.com/actions/github-script
202+ with :
203+ github-token : ${{ secrets.GITHUB_TOKEN }}
204+ script : |
205+ const pages = 5;
206+ let runs_to_delete = [];
207+ // Get all workflows
208+ const { data: workflowsData } = await github.rest.actions.listRepoWorkflows({
209+ owner: context.repo.owner,
210+ repo: context.repo.repo
211+ });
212+ // Find workflow by name
213+ const workflowName = "pages-build-deployment";
214+ const workflow = workflowsData.workflows.find(w => w.name === workflowName);
215+ if (!workflow) {
216+ console.log(`❌ No workflow named ${workflowName} found.`);
217+ return;
218+ }
219+ const workflowId = workflow.id;
220+ console.log(`✅ Found workflow ID: ${workflowId}`);
221+ // Fetch workflow runs
222+ for (let page = 0; page < pages; page += 1) {
223+ const response = await github.rest.actions.listWorkflowRuns({
224+ owner: context.repo.owner,
225+ repo: context.repo.repo,
226+ workflow_id: workflowId, // Use dynamically fetched ID
227+ page: page,
228+ per_page: 50,
229+ });
230+ if (response.data.workflow_runs.length === 0) break;
231+ if (response.data.workflow_runs.length > 0) {
232+ for (const run of response.data.workflow_runs) {
233+ runs_to_delete.push([run.id, run.name]);
234+ }
235+ }
236+ if (response.data.workflow_runs.length < 50) break;
237+ }
238+ // Delete workflow runs
239+ for (const run of runs_to_delete) {
240+ console.log(`[Deleting] Run id ${run[0]} of '${run[1]}'.`);
241+ try {
242+ await github.rest.actions.deleteWorkflowRun({
243+ owner: context.repo.owner,
244+ repo: context.repo.repo,
245+ run_id: run[0]
246+ });
247+ } catch (error) {
248+ // ignore errors
249+ }
250+ }
0 commit comments