From 4e257478802e76e3f5ab1bca2e2466fc1e027665 Mon Sep 17 00:00:00 2001 From: Ben Wolsieffer Date: Wed, 20 Nov 2024 21:40:28 -0500 Subject: [PATCH] actions: try to make failed builds cache work --- .../actions/nix-ros-build-action/dist/index.js | 14 +++++++++----- .github/actions/nix-ros-build-action/src/main.ts | 16 ++++++++++------ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.github/actions/nix-ros-build-action/dist/index.js b/.github/actions/nix-ros-build-action/dist/index.js index 2980c2f236..a9df806147 100644 --- a/.github/actions/nix-ros-build-action/dist/index.js +++ b/.github/actions/nix-ros-build-action/dist/index.js @@ -80511,7 +80511,6 @@ class BuildGraph { } } async function main_instantiate(nixFile, rootAttribute, drvDir, system, parallelism = 4) { - await io.mkdirP(drvDir); const attrs = await listAttrs(nixFile, rootAttribute); const queue = new PQueue({ concurrency: parallelism }); return await queue.addAll(attrs.map(attr => async () => { @@ -80555,7 +80554,7 @@ async function main_instantiate(nixFile, rootAttribute, drvDir, system, parallel } })); } -async function build(drvPath, resultDir, cachixCache) { +async function build(drvPath, resultDir, cachixCache, cacheDir) { const cacheKey = "failed-" + external_path_.basename(drvPath, ".drv"); try { if (await isDrvCached(drvPath)) { @@ -80573,7 +80572,7 @@ async function build(drvPath, resultDir, cachixCache) { if (cache.isFeatureAvailable()) { // We don't actually store anything in the cache, just lookup the // derivation name - if (await cache.restoreCache(["/var/empty"], cacheKey, [], { lookupOnly: true }) !== undefined) { + if (await cache.restoreCache([cacheDir], cacheKey, [], { lookupOnly: true }) !== undefined) { core.debug(`found cached failure: ${drvPath}`); return { status: 'cached_failure', @@ -80600,7 +80599,7 @@ async function build(drvPath, resultDir, cachixCache) { if (typeof error === 'string') { try { if (cache.isFeatureAvailable()) { - await cache.saveCache(["/var/empty"], cacheKey); + await cache.saveCache([cacheDir], cacheKey); } } catch (e) { @@ -80632,6 +80631,11 @@ async function run() { const buildDir = "build"; const drvDir = external_path_.join(buildDir, 'drvs'); const resultDir = external_path_.join(buildDir, 'results'); + // Empty directory to make GitHub Actions cache happy + const cacheDir = external_path_.join(buildDir, 'cache'); + await io.mkdirP(drvDir); + await io.mkdirP(resultDir); + await io.mkdirP(cacheDir); const successes = []; const cachedSuccesses = []; const evalFailures = []; @@ -80686,7 +80690,7 @@ async function run() { }); return; } - const r = await build(node.drvPath, resultDir, cachixCache); + const r = await build(node.drvPath, resultDir, cachixCache, cacheDir); if (r.status === 'cached_success' || r.status === 'success') { buildGraph.succeeded(node); } diff --git a/.github/actions/nix-ros-build-action/src/main.ts b/.github/actions/nix-ros-build-action/src/main.ts index 6bb9b99740..1eaa3b6942 100644 --- a/.github/actions/nix-ros-build-action/src/main.ts +++ b/.github/actions/nix-ros-build-action/src/main.ts @@ -134,7 +134,6 @@ type EvalResult = EvalSuccess | EvalFailure | EvalError; async function instantiate(nixFile: string, rootAttribute: string, drvDir: string, system?: string, parallelism = 4): Promise { - await io.mkdirP(drvDir) const attrs = await nix.listAttrs(nixFile, rootAttribute) const queue = new PQueue({ concurrency: parallelism }) @@ -211,7 +210,7 @@ interface BuildError { type BuildResult = BuildSuccess | BuildCachedSuccess | BuildFailure | BuildCachedFailure | BuildError; -async function build(drvPath: string, resultDir: string, cachixCache: string): Promise { +async function build(drvPath: string, resultDir: string, cachixCache: string, cacheDir: string): Promise { const cacheKey = "failed-" + path.basename(drvPath, ".drv"); try { @@ -230,7 +229,7 @@ async function build(drvPath: string, resultDir: string, cachixCache: string): P if (cache.isFeatureAvailable()) { // We don't actually store anything in the cache, just lookup the // derivation name - if (await cache.restoreCache(["/var/empty"], cacheKey, [], { lookupOnly: true }) !== undefined) { + if (await cache.restoreCache([cacheDir], cacheKey, [], { lookupOnly: true }) !== undefined) { core.debug(`found cached failure: ${drvPath}`) return { status: 'cached_failure', @@ -259,7 +258,7 @@ async function build(drvPath: string, resultDir: string, cachixCache: string): P if (typeof error === 'string') { try { if (cache.isFeatureAvailable()) { - await cache.saveCache(["/var/empty"], cacheKey) + await cache.saveCache([cacheDir], cacheKey) } } catch (e: unknown) { core.warning(`failed to cache failed build for ${drvPath}: ${e}`) @@ -325,6 +324,12 @@ async function run() { const buildDir = "build" const drvDir = path.join(buildDir, 'drvs') const resultDir = path.join(buildDir, 'results') + // Empty directory to make GitHub Actions cache happy + const cacheDir = path.join(buildDir, 'cache') + + await io.mkdirP(drvDir) + await io.mkdirP(resultDir) + await io.mkdirP(cacheDir) const successes: SuccessResult[] = [] const cachedSuccesses: CachedSuccessResult[] = [] @@ -350,7 +355,6 @@ async function run() { } } - // Create graph of references used to order the builds const buildGraph = new BuildGraph(); for (const [drvPath, drv] of derivations) { @@ -389,7 +393,7 @@ async function run() { return; } - const r = await build(node.drvPath, resultDir, cachixCache) + const r = await build(node.drvPath, resultDir, cachixCache, cacheDir) if (r.status === 'cached_success' || r.status === 'success') { buildGraph.succeeded(node)