Repository: denoland/deno
Pull request: ci: force caches to be uploaded on main with every commit

We should create a new build cache for each commit on main. It's leading to slower builds on PRs because the caches are only uploaded when the cargo.lock changes.

Changed files:
filename: .github/workflows/ci.generate.ts
patch: @@ -286,7 +286,13 @@ function createRestoreAndSaveCacheSteps(m: {
     uses: "cirruslabs/cache/save@v4",
     with: {
       path,
-      key: `${m.cacheKeyPrefix}-\${{ hashFiles('Cargo.lock') }}`,
+      // We force saving a new cache on every main run so that PRs can
+      // always be up to date with the freshest information. We do this
+      // unconditionally because we don't want caches that only need updating
+      // occassionally (like the cargo home cache) to be lost over time as
+      // other caches that need to be updated frequently (like the cargo build
+      // cache) get populated and purge old caches.
+      key: `${m.cacheKeyPrefix}-\${{ github.sha }}`,
     },
   });
   return { restoreCacheStep, saveCacheStep };

filename: .github/workflows/ci.yml
patch: @@ -219,7 +219,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-linux-x86_64-bench-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-linux-x86_64-bench-${{ github.sha }}'
   build-debug-macos-x86_64:
     name: build debug macos-x86_64
     needs:
@@ -335,7 +335,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-macos-x86_64-build-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-macos-x86_64-build-main-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: 'github.ref == ''refs/heads/main'' && !startsWith(github.ref, ''refs/tags/'')'
@@ -346,7 +346,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-macos-x86_64-debug-build-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-macos-x86_64-debug-build-main-${{ github.sha }}'
   test-debug-macos-x86_64:
     name: 'test ${{ matrix.test_crate }} debug macos-x86_64'
     needs:
@@ -495,7 +495,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-macos-x86_64-test-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-macos-x86_64-test-main-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: '!startsWith(github.ref, ''refs/tags/'') && matrix.test_crate == ''integration'' && github.ref == ''refs/heads/main'''
@@ -506,7 +506,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-macos-x86_64-debug-test-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-macos-x86_64-debug-test-main-${{ github.sha }}'
   build-release-macos-x86_64:
     name: build release macos-x86_64
     needs:
@@ -1000,7 +1000,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-macos-aarch64-build-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-macos-aarch64-build-main-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: 'github.ref == ''refs/heads/main'' && !startsWith(github.ref, ''refs/tags/'')'
@@ -1011,7 +1011,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-macos-aarch64-debug-build-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-macos-aarch64-debug-build-main-${{ github.sha }}'
   test-debug-macos-aarch64:
     name: 'test ${{ matrix.test_crate }} debug macos-aarch64'
     needs:
@@ -1169,7 +1169,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-macos-aarch64-test-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-macos-aarch64-test-main-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: '!startsWith(github.ref, ''refs/tags/'') && matrix.test_crate == ''integration'' && github.ref == ''refs/heads/main'''
@@ -1180,7 +1180,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-macos-aarch64-debug-test-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-macos-aarch64-debug-test-main-${{ github.sha }}'
   test-libs-debug-macos-aarch64:
     name: test libs debug macos-aarch64
     needs:
@@ -1287,7 +1287,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-macos-aarch64-test-libs-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-macos-aarch64-test-libs-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: '!startsWith(github.ref, ''refs/tags/'') && github.ref == ''refs/heads/main'''
@@ -1298,7 +1298,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-macos-aarch64-debug-test-libs-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-macos-aarch64-debug-test-libs-${{ github.sha }}'
   build-release-macos-aarch64:
     name: build release macos-aarch64
     needs:
@@ -1789,7 +1789,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-windows-x86_64-build-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-windows-x86_64-build-main-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: 'github.ref == ''refs/heads/main'' && !startsWith(github.ref, ''refs/tags/'')'
@@ -1800,7 +1800,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-windows-x86_64-debug-build-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-windows-x86_64-debug-build-main-${{ github.sha }}'
   test-debug-windows-x86_64:
     name: 'test ${{ matrix.test_crate }} debug windows-x86_64'
     needs:
@@ -1940,7 +1940,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-windows-x86_64-test-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-windows-x86_64-test-main-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: '!startsWith(github.ref, ''refs/tags/'') && matrix.test_crate == ''integration'' && github.ref == ''refs/heads/main'''
@@ -1951,7 +1951,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-windows-x86_64-debug-test-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-windows-x86_64-debug-test-main-${{ github.sha }}'
   test-libs-debug-windows-x86_64:
     name: test libs debug windows-x86_64
     needs:
@@ -2035,7 +2035,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-windows-x86_64-test-libs-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-windows-x86_64-test-libs-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: '!startsWith(github.ref, ''refs/tags/'') && github.ref == ''refs/heads/main'''
@@ -2046,7 +2046,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-windows-x86_64-debug-test-libs-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-windows-x86_64-debug-test-libs-${{ github.sha }}'
   build-release-windows-x86_64:
     name: build release windows-x86_64
     needs:
@@ -2537,7 +2537,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-windows-aarch64-build-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-windows-aarch64-build-main-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: 'github.ref == ''refs/heads/main'' && !startsWith(github.ref, ''refs/tags/'')'
@@ -2548,7 +2548,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-windows-aarch64-debug-build-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-windows-aarch64-debug-build-main-${{ github.sha }}'
   test-debug-windows-aarch64:
     name: 'test ${{ matrix.test_crate }} debug windows-aarch64'
     needs:
@@ -2688,7 +2688,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-windows-aarch64-test-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-windows-aarch64-test-main-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: '!startsWith(github.ref, ''refs/tags/'') && matrix.test_crate == ''integration'' && github.ref == ''refs/heads/main'''
@@ -2699,7 +2699,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-windows-aarch64-debug-test-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-windows-aarch64-debug-test-main-${{ github.sha }}'
   build-release-windows-aarch64:
     name: build release windows-aarch64
     needs:
@@ -3375,7 +3375,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-linux-x86_64-build-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-linux-x86_64-build-main-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: 'github.ref == ''refs/heads/main'' && !startsWith(github.ref, ''refs/tags/'')'
@@ -3386,7 +3386,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-linux-x86_64-release-build-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-linux-x86_64-release-build-main-${{ github.sha }}'
   test-release-linux-x86_64:
     name: 'test ${{ matrix.test_crate }} release linux-x86_64'
     needs:
@@ -3614,7 +3614,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-linux-x86_64-test-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-linux-x86_64-test-main-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: '!startsWith(github.ref, ''refs/tags/'') && matrix.test_crate == ''integration'' && github.ref == ''refs/heads/main'''
@@ -3625,7 +3625,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-linux-x86_64-release-test-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-linux-x86_64-release-test-main-${{ github.sha }}'
   wpt-release-linux-x86_64:
     name: wpt release linux-x86_64
     needs:
@@ -3915,7 +3915,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-linux-x86_64-build-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-linux-x86_64-build-main-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: 'github.ref == ''refs/heads/main'' && !startsWith(github.ref, ''refs/tags/'')'
@@ -3926,7 +3926,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-linux-x86_64-debug-build-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-linux-x86_64-debug-build-main-${{ github.sha }}'
   test-debug-linux-x86_64:
     name: 'test ${{ matrix.test_crate }} debug linux-x86_64'
     needs:
@@ -4156,7 +4156,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-linux-x86_64-test-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-linux-x86_64-test-main-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: '!startsWith(github.ref, ''refs/tags/'') && matrix.test_crate == ''integration'' && github.ref == ''refs/heads/main'''
@@ -4167,7 +4167,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-linux-x86_64-debug-test-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-linux-x86_64-debug-test-main-${{ github.sha }}'
   build-libs-debug-linux-x86_64:
     name: build libs debug linux-x86_64
     needs:
@@ -4248,7 +4248,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-linux-x86_64-build-libs-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-linux-x86_64-build-libs-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: '!startsWith(github.ref, ''refs/tags/'') && github.ref == ''refs/heads/main'''
@@ -4259,7 +4259,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-linux-x86_64-debug-build-libs-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-linux-x86_64-debug-build-libs-${{ github.sha }}'
   build-debug-linux-aarch64:
     name: build debug linux-aarch64
     needs:
@@ -4369,7 +4369,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-linux-aarch64-build-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-linux-aarch64-build-main-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: 'github.ref == ''refs/heads/main'' && !startsWith(github.ref, ''refs/tags/'')'
@@ -4380,7 +4380,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-linux-aarch64-debug-build-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-linux-aarch64-debug-build-main-${{ github.sha }}'
   test-debug-linux-aarch64:
     name: 'test ${{ matrix.test_crate }} debug linux-aarch64'
     needs:
@@ -4532,7 +4532,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-linux-aarch64-test-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-linux-aarch64-test-main-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: '!startsWith(github.ref, ''refs/tags/'') && matrix.test_crate == ''integration'' && github.ref == ''refs/heads/main'''
@@ -4543,7 +4543,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-linux-aarch64-debug-test-main-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-linux-aarch64-debug-test-main-${{ github.sha }}'
   test-libs-debug-linux-aarch64:
     name: test libs debug linux-aarch64
     needs:
@@ -4633,7 +4633,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-linux-aarch64-test-libs-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-linux-aarch64-test-libs-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: '!startsWith(github.ref, ''refs/tags/'') && github.ref == ''refs/heads/main'''
@@ -4644,7 +4644,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-linux-aarch64-debug-test-libs-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-linux-aarch64-debug-test-libs-${{ github.sha }}'
   build-release-linux-aarch64:
     name: build release linux-aarch64
     needs:
@@ -5250,7 +5250,7 @@ jobs:
             ~/.cargo/registry/index
             ~/.cargo/registry/cache
             ~/.cargo/git/db
-          key: '95-cargo-home-${{ matrix.os }}-${{ matrix.arch }}-lint-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-home-${{ matrix.os }}-${{ matrix.arch }}-lint-${{ github.sha }}'
       - name: Cache build output
         uses: cirruslabs/cache/save@v4
         if: 'github.ref == ''refs/heads/main'' && !startsWith(github.ref, ''refs/tags/'')'
@@ -5261,7 +5261,7 @@ jobs:
             !./target/*/gn_root
             !./target/*/*.zip
             !./target/*/*.tar.gz
-          key: '95-cargo-target-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.profile }}-lint-${{ hashFiles(''Cargo.lock'') }}'
+          key: '95-cargo-target-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.profile }}-lint-${{ github.sha }}'
   lint-ci-status:
     name: lint ci status
     needs: