From 8d3bdd083c3ec4f6992cee6a6bd9723f93279bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20Dee=20=28J=C5=8Dshin=29?= Date: Sun, 18 May 2025 21:31:18 -0700 Subject: [PATCH] Better mtimes for github workflow build cache Saves and restores mtimes to a file, also covering the `o/` directory to hopefully preserve make dependency information better. --- .github/workflows/build.yml | 40 ++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6bd20ffab..dbd94b3f5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,22 +27,23 @@ jobs: # Full checkout needed for git-restore-mtime-bare. fetch-depth: 0 - # TODO(jart): fork this action. - - uses: chetan/git-restore-mtime-action@v2 - - - uses: actions/cache@v4 + - uses: actions/cache/restore@v4 + id: cache with: - path: .cosmocc/${{ env.COSMOCC_VERSION }} - key: cosmocc-${{ env.COSMOCC_VERSION }} - - - uses: actions/cache@v4 - with: - path: o - key: o-${{ matrix.mode }}-${{ env.COSMOCC_VERSION }}-${{ github.sha }} + path: | + .cosmocc/${{ env.COSMOCC_VERSION }} + o + key: ${{ env.COSMOCC_VERSION }}-${{ matrix.mode }}-${{ github.sha }} restore-keys: | - o-${{ matrix.mode }}-${{ env.COSMOCC_VERSION }}- - o-${{ matrix.mode }}- - o- + ${{ env.COSMOCC_VERSION }}-${{ matrix.mode }}- + ${{ env.COSMOCC_VERSION }}- + + - name: Restore mtimes + if: steps.cache.outputs.cache-hit == 'true' + run: | + while read mtime file; do + [ -f "$file" ] && touch -d "@$mtime" "$file" + done < o/.mtimes - name: support ape bins 1 run: sudo cp -a build/bootstrap/ape.elf /usr/bin/ape @@ -52,3 +53,14 @@ jobs: - name: make matrix run: V=0 make -j2 MODE=${{ matrix.mode }} + + - name: Save mtimes + run: | + find o -type f -exec stat -c "%Y %n" {} \; > o/.mtimes + + - uses: actions/cache/save@v4 + with: + path: | + .cosmocc + o + key: ${{ env.COSMOCC_VERSION }}-${{ matrix.mode }}-${{ github.sha }}