From 428074b62c1577578835dcdb1f3ba0ca9c665c6a Mon Sep 17 00:00:00 2001 From: Daniel Kennedy Date: Wed, 25 Feb 2026 14:32:24 -0500 Subject: [PATCH] CI: clean up artifacts on successful runs --- .github/workflows/test.yml | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7ff1ed0..94316ef 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -385,3 +385,44 @@ jobs: } shell: pwsh + cleanup: + name: Cleanup Artifacts + needs: [build, merge] + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node 24 + uses: actions/setup-node@v4 + with: + node-version: 24.x + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Delete test artifacts + uses: actions/github-script@v7 + with: + script: | + const artifactClient = require('@actions/artifact'); + const artifact = artifactClient.default || artifactClient; + + const {artifacts} = await artifact.listArtifacts({latest: true}); + const keep = ['report.html']; + + for (const a of artifacts) { + if (keep.includes(a.name)) { + console.log(`Keeping artifact '${a.name}'`); + continue; + } + try { + await artifact.deleteArtifact(a.name); + console.log(`Deleted artifact '${a.name}'`); + } catch (err) { + console.log(`Could not delete artifact '${a.name}': ${err.message}`); + } + } +