Commit 428074b6 authored by Daniel Kennedy's avatar Daniel Kennedy
Browse files

CI: clean up artifacts on successful runs

parent 15af3237
Loading
Loading
Loading
Loading
+41
Changes for .github/workflows/test.yml: 41 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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}`);
            }
          }