Repository: denoland/deno
Pull request: ci: fix saving wpt cache

Tested on this PR.

<img width="289" height="112" alt="image" src="https://github.com/user-attachments/assets/1a2dbf30-13d7-4a31-871b-f2ac0cbf8a70" />


Changed files:
filename: .github/workflows/ci.generate.ts
patch: @@ -1171,6 +1171,15 @@ const buildJobs = buildItems.map((rawBuildItem) => {
   }
 
   if (buildItem.wpt.isPossiblyTrue()) {
+    const buildCacheSteps = createRestoreAndSaveCacheSteps({
+      name: "wpt and autobahn test run hashes",
+      path: [
+        "./target/wpt_input_hash",
+        "./target/autobahn_input_hash",
+      ],
+      cacheKeyPrefix:
+        `${cacheVersion}-wpt-target-${buildItem.os}-${buildItem.arch}-${buildItem.profile}`,
+    });
     additionalJobs.push(job(
       jobIdForJob("wpt"),
       {
@@ -1184,6 +1193,7 @@ const buildJobs = buildItems.map((rawBuildItem) => {
           cloneRepoStep,
           cloneStdSubmoduleStep,
           cloneSubmodule("./tests/wpt/suite"),
+          buildCacheSteps.restoreCacheStep,
           installDenoStep,
           installPythonStep,
           denoArtifact.download(),
@@ -1252,6 +1262,7 @@ const buildJobs = buildItems.map((rawBuildItem) => {
               "    ./tools/upload_wptfyi.js $(git rev-parse HEAD) --ghstatus",
             ],
           },
+          buildCacheSteps.saveCacheStep.if(isMainBranch.and(isNotTag)),
         ),
       },
     ));

filename: .github/workflows/ci.yml
patch: @@ -3815,6 +3815,15 @@ jobs:
       - name: Clone submodule ./tests/wpt/suite
         if: '!startsWith(github.ref, ''refs/tags/'')'
         run: git submodule update --init --recursive --depth=1 -- ./tests/wpt/suite
+      - name: Restore cache wpt and autobahn test run hashes
+        uses: cirruslabs/cache/restore@v4
+        if: '!startsWith(github.ref, ''refs/tags/'')'
+        with:
+          path: |-
+            ./target/wpt_input_hash
+            ./target/autobahn_input_hash
+          key: never_saved
+          restore-keys: 96-wpt-target-linux-x86_64-release-
       - name: Install Deno
         uses: denoland/setup-deno@v2
         if: '!startsWith(github.ref, ''refs/tags/'')'
@@ -3882,6 +3891,14 @@ jobs:
         run: |-
           ./target/release/deno run --allow-all --lock=tools/deno.lock.json \
               ./tools/upload_wptfyi.js $(git rev-parse HEAD) --ghstatus
+      - name: Cache wpt and autobahn test run hashes
+        uses: cirruslabs/cache/save@v4
+        if: '!startsWith(github.ref, ''refs/tags/'') && github.ref == ''refs/heads/main'''
+        with:
+          path: |-
+            ./target/wpt_input_hash
+            ./target/autobahn_input_hash
+          key: '96-wpt-target-linux-x86_64-release-${{ github.sha }}'
   build-debug-linux-x86_64:
     name: build debug linux-x86_64
     needs:

filename: ext/websocket/autobahn/fuzzingclient.js
patch: @@ -3,17 +3,21 @@
 // deno-lint-ignore-file
 
 import { $ } from "https://deno.land/x/dax@0.31.0/mod.ts";
-import { dirname, shouldSkipOnCi } from "../../../tools/util.js";
+import { join, ROOT_PATH, shouldSkipOnCi } from "../../../tools/util.js";
 
 $.setPrintCommand(true);
 const pwd = new URL(".", import.meta.url).pathname;
 
 const self = Deno.execPath();
 if (
-  await shouldSkipOnCi("autobahn", dirname(self), async (hasher) => {
-    await hasher.hashFile(self);
-    await hasher.hashDir(pwd);
-  })
+  await shouldSkipOnCi(
+    "autobahn",
+    join(ROOT_PATH, "target"),
+    async (hasher) => {
+      await hasher.hashFile(self);
+      await hasher.hashDir(pwd);
+    },
+  )
 ) {
   Deno.exit(0);
 }

filename: tests/wpt/runner/utils.ts
patch: @@ -50,7 +50,7 @@ async function getWptSubmoduleHash(): Promise<string> {
 }
 
 export function shouldSkipOnCi(): Promise<boolean> {
-  const targetDir = join(ROOT_PATH, "target", release ? "release" : "debug");
+  const targetDir = join(ROOT_PATH, "target");
   return shouldSkipOnCiGeneric("wpt", targetDir, async (hasher) => {
     const hashDenoBinaryTask = hasher.hashFile(denoBinary());
     const submoduleHash = await getWptSubmoduleHash();