From 92bdd21660b31654c20cb722f2022bb05eedacc2 Mon Sep 17 00:00:00 2001 From: eitsupi Date: Sat, 4 Jul 2026 07:57:26 +0000 Subject: [PATCH] fix: preserve target-triple build artifacts --- .github/workflows/target-triple.yml | 85 +++++++++++++++++++ dist/{cache-COXGx-w3.js => cache-BnuDdkC4.js} | 2 +- dist/{cache-oK5XC6-w.js => cache-XOpvQMVD.js} | 2 +- ...leanup-BnmJoqJp.js => cleanup-By9HBZSo.js} | 18 ++-- dist/restore.js | 2 +- dist/save.js | 2 +- src/cleanup.ts | 16 ++-- 7 files changed, 110 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/target-triple.yml rename dist/{cache-COXGx-w3.js => cache-BnuDdkC4.js} (99%) rename dist/{cache-oK5XC6-w.js => cache-XOpvQMVD.js} (99%) rename dist/{cleanup-BnmJoqJp.js => cleanup-By9HBZSo.js} (99%) diff --git a/.github/workflows/target-triple.yml b/.github/workflows/target-triple.yml new file mode 100644 index 0000000..9ee3223 --- /dev/null +++ b/.github/workflows/target-triple.yml @@ -0,0 +1,85 @@ +name: target-triple + +on: [push, pull_request] + +permissions: {} + +jobs: + save: + if: github.repository == 'Swatinem/rust-cache' + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + + name: Save target-triple cache on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + persist-credentials: false + + - run: rustup toolchain install stable --profile minimal --no-self-update + + - name: Set host target + shell: bash + run: | + echo "RUST_TARGET=$(rustc -vV | sed -n 's/^host: //p')" >> "$GITHUB_ENV" + + - uses: ./ + with: + workspaces: tests + shared-key: target-triple-${{ matrix.os }}-${{ github.run_id }}-${{ github.run_attempt }} + add-job-id-key: "false" + add-rust-environment-hash-key: "false" + + - run: cargo check --target "$RUST_TARGET" + working-directory: tests + shell: bash + + restore: + if: github.repository == 'Swatinem/rust-cache' + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + + name: Restore target-triple cache on ${{ matrix.os }} + needs: save + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + persist-credentials: false + + - run: rustup toolchain install stable --profile minimal --no-self-update + + - name: Set host target + shell: bash + run: | + echo "RUST_TARGET=$(rustc -vV | sed -n 's/^host: //p')" >> "$GITHUB_ENV" + + - id: cache + uses: ./ + with: + workspaces: tests + shared-key: target-triple-${{ matrix.os }}-${{ github.run_id }}-${{ github.run_attempt }} + add-job-id-key: "false" + add-rust-environment-hash-key: "false" + save-if: "false" + + - name: Verify target-triple artifacts + env: + CACHE_HIT: ${{ steps.cache.outputs.cache-hit }} + shell: bash + run: | + if [[ "$CACHE_HIT" != "true" ]]; then + echo "The target-triple cache was not restored exactly." >&2 + exit 1 + fi + if ! compgen -G "tests/target/$RUST_TARGET/debug/deps/librust_cache-*" > /dev/null; then + echo "The target-triple artifacts were not restored." >&2 + exit 1 + fi diff --git a/dist/cache-COXGx-w3.js b/dist/cache-BnuDdkC4.js similarity index 99% rename from dist/cache-COXGx-w3.js rename to dist/cache-BnuDdkC4.js index c45f1a1..4b6b77d 100644 --- a/dist/cache-COXGx-w3.js +++ b/dist/cache-BnuDdkC4.js @@ -1,4 +1,4 @@ -import { v as commonjsGlobal, x as requireTunnel, y as getDefaultExportFromCjs, z as getAugmentedNamespace } from './cleanup-BnmJoqJp.js'; +import { v as commonjsGlobal, x as requireTunnel, y as getDefaultExportFromCjs, z as getAugmentedNamespace } from './cleanup-By9HBZSo.js'; import os__default from 'os'; import crypto__default from 'crypto'; import fs__default from 'fs'; diff --git a/dist/cache-oK5XC6-w.js b/dist/cache-XOpvQMVD.js similarity index 99% rename from dist/cache-oK5XC6-w.js rename to dist/cache-XOpvQMVD.js index 836963a..92aae8e 100644 --- a/dist/cache-oK5XC6-w.js +++ b/dist/cache-XOpvQMVD.js @@ -1,4 +1,4 @@ -import { f as debug, m as mkdirP, n as create, l as exec, w as which, o as warning, i as info, H as HttpCodes, p as HttpClientError, q as HttpClient, t as isDebug, u as setSecret, B as BearerCredentialHandler, e as error } from './cleanup-BnmJoqJp.js'; +import { f as debug, m as mkdirP, n as create, l as exec, w as which, o as warning, i as info, H as HttpCodes, p as HttpClientError, q as HttpClient, t as isDebug, u as setSecret, B as BearerCredentialHandler, e as error } from './cleanup-By9HBZSo.js'; import * as path from 'path'; import * as crypto$1 from 'crypto'; import * as fs from 'fs'; diff --git a/dist/cleanup-BnmJoqJp.js b/dist/cleanup-By9HBZSo.js similarity index 99% rename from dist/cleanup-BnmJoqJp.js rename to dist/cleanup-By9HBZSo.js index 988063a..80f5582 100644 --- a/dist/cleanup-BnmJoqJp.js +++ b/dist/cleanup-By9HBZSo.js @@ -34145,10 +34145,10 @@ async function getCacheProvider() { let cache; switch (cacheProvider) { case "github": - cache = await import('./cache-oK5XC6-w.js'); + cache = await import('./cache-XOpvQMVD.js'); break; case "warpbuild": - cache = await import('./cache-COXGx-w3.js').then(function (n) { return n.c; }); + cache = await import('./cache-BnuDdkC4.js').then(function (n) { return n.c; }); break; default: throw new Error(`The \`cache-provider\` \`${cacheProvider}\` is not valid.`); @@ -34596,14 +34596,18 @@ async function cleanTargetDir(targetDir, packages, checkTimestamp = false) { for await (const dirent of dir) { if (dirent.isDirectory()) { let dirName = path__default.join(dir.path, dirent.name); - // is it a profile dir, or a nested target dir? - let isNestedTarget = (await exists(path__default.join(dirName, "CACHEDIR.TAG"))) || (await exists(path__default.join(dirName, ".rustc_info.json"))); + // Target-triple directories do not contain Cargo's target directory + // markers, so identify profiles by their artifact directories as well. + const isProfile = dirent.name === "tests" || + (await exists(path__default.join(dirName, "build"))) || + (await exists(path__default.join(dirName, ".fingerprint"))) || + (await exists(path__default.join(dirName, "deps"))); try { - if (isNestedTarget) { - await cleanTargetDir(dirName, packages, checkTimestamp); + if (isProfile) { + await cleanProfileTarget(dirName, packages, checkTimestamp); } else { - await cleanProfileTarget(dirName, packages, checkTimestamp); + await cleanTargetDir(dirName, packages, checkTimestamp); } } catch { } diff --git a/dist/restore.js b/dist/restore.js index b169c60..d6ed955 100644 --- a/dist/restore.js +++ b/dist/restore.js @@ -1,4 +1,4 @@ -import { e as error, g as getCacheProvider, a as getInput, b as exportVariable, C as CacheConfig, i as info, c as cleanTargetDir, r as reportError, s as setOutput } from './cleanup-BnmJoqJp.js'; +import { e as error, g as getCacheProvider, a as getInput, b as exportVariable, C as CacheConfig, i as info, c as cleanTargetDir, r as reportError, s as setOutput } from './cleanup-By9HBZSo.js'; import 'os'; import 'crypto'; import 'fs'; diff --git a/dist/save.js b/dist/save.js index f010308..361c973 100644 --- a/dist/save.js +++ b/dist/save.js @@ -1,4 +1,4 @@ -import { e as error, g as getCacheProvider, a as getInput, d as isCacheUpToDate, i as info, C as CacheConfig, c as cleanTargetDir, f as debug, h as cleanRegistry, j as cleanBin, k as cleanGit, r as reportError, l as exec } from './cleanup-BnmJoqJp.js'; +import { e as error, g as getCacheProvider, a as getInput, d as isCacheUpToDate, i as info, C as CacheConfig, c as cleanTargetDir, f as debug, h as cleanRegistry, j as cleanBin, k as cleanGit, r as reportError, l as exec } from './cleanup-By9HBZSo.js'; import 'os'; import 'crypto'; import 'fs'; diff --git a/src/cleanup.ts b/src/cleanup.ts index 744ab72..3eb93bb 100644 --- a/src/cleanup.ts +++ b/src/cleanup.ts @@ -15,15 +15,19 @@ export async function cleanTargetDir(targetDir: string, packages: Packages, chec for await (const dirent of dir) { if (dirent.isDirectory()) { let dirName = path.join(dir.path, dirent.name); - // is it a profile dir, or a nested target dir? - let isNestedTarget = - (await exists(path.join(dirName, "CACHEDIR.TAG"))) || (await exists(path.join(dirName, ".rustc_info.json"))); + // Target-triple directories do not contain Cargo's target directory + // markers, so identify profiles by their artifact directories as well. + const isProfile = + dirent.name === "tests" || + (await exists(path.join(dirName, "build"))) || + (await exists(path.join(dirName, ".fingerprint"))) || + (await exists(path.join(dirName, "deps"))); try { - if (isNestedTarget) { - await cleanTargetDir(dirName, packages, checkTimestamp); - } else { + if (isProfile) { await cleanProfileTarget(dirName, packages, checkTimestamp); + } else { + await cleanTargetDir(dirName, packages, checkTimestamp); } } catch {} } else if (dirent.name !== "CACHEDIR.TAG") {