|
6 | 6 | workflow_dispatch:
|
7 | 7 |
|
8 | 8 | jobs:
|
| 9 | + cleanup-cache: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + actions: write |
| 13 | + steps: |
| 14 | + - name: Cleanup old caches |
| 15 | + uses: actions/github-script@v7 |
| 16 | + with: |
| 17 | + script: | |
| 18 | + const retentionDays = 3; // Keep caches for 3 days |
| 19 | + const caches = await github.rest.actions.getActionsCacheList({ |
| 20 | + owner: context.repo.owner, |
| 21 | + repo: context.repo.repo |
| 22 | + }); |
| 23 | +
|
| 24 | + const now = new Date(); |
| 25 | + for (const cache of caches.data.actions_caches) { |
| 26 | + if (cache.key.startsWith('sccache-')) { |
| 27 | + const createdAt = new Date(cache.created_at); |
| 28 | + const ageInDays = (now - createdAt) / (1000 * 60 * 60 * 24); |
| 29 | +
|
| 30 | + if (ageInDays > retentionDays) { |
| 31 | + console.log(`Deleting old cache: ${cache.key}, created ${ageInDays.toFixed(1)} days ago`); |
| 32 | + await github.rest.actions.deleteActionsCacheByKey({ |
| 33 | + owner: context.repo.owner, |
| 34 | + repo: context.repo.repo, |
| 35 | + key: cache.key |
| 36 | + }); |
| 37 | + } else { |
| 38 | + console.log(`Keeping cache: ${cache.key}, created ${ageInDays.toFixed(1)} days ago`); |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | +
|
9 | 43 | warmup-unix:
|
| 44 | + needs: cleanup-cache |
10 | 45 | runs-on: ${{ matrix.os }}
|
11 | 46 | strategy:
|
12 | 47 | matrix:
|
@@ -38,11 +73,13 @@ jobs:
|
38 | 73 | uses: actions/cache@v4
|
39 | 74 | with:
|
40 | 75 | path: ${{ env.SCCACHE_DIR }}
|
41 |
| - key: sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }} |
| 76 | + key: sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}-${{ github.run_id }} |
42 | 77 | restore-keys: |
|
43 |
| - sccache-${{ runner.os }}-${{ matrix.device }}- |
| 78 | + sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}- |
| 79 | + sccache-${{ runner.os }}-${{ matrix.device }}- |
44 | 80 |
|
45 | 81 | warmup-win:
|
| 82 | + needs: cleanup-cache |
46 | 83 | runs-on: ${{ matrix.os }}
|
47 | 84 | strategy:
|
48 | 85 | matrix:
|
|
62 | 99 | uses: actions/cache@v4
|
63 | 100 | with:
|
64 | 101 | path: ${{ env.SCCACHE_DIR }}
|
65 |
| - key: sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }} |
| 102 | + key: sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}-${{ github.run_id }} |
66 | 103 | restore-keys: |
|
| 104 | + sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}- |
67 | 105 | sccache-${{ runner.os }}-${{ matrix.device }}-
|
0 commit comments