Skip to content

Commit

Permalink
actions: try to make failed builds cache work
Browse files Browse the repository at this point in the history
  • Loading branch information
lopsided98 committed Nov 21, 2024
1 parent 315a2ee commit 4e25747
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
14 changes: 9 additions & 5 deletions .github/actions/nix-ros-build-action/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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',
Expand All @@ -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) {
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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);
}
Expand Down
16 changes: 10 additions & 6 deletions .github/actions/nix-ros-build-action/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ type EvalResult = EvalSuccess | EvalFailure | EvalError;


async function instantiate(nixFile: string, rootAttribute: string, drvDir: string, system?: string, parallelism = 4): Promise<EvalResult[]> {
await io.mkdirP(drvDir)
const attrs = await nix.listAttrs(nixFile, rootAttribute)

const queue = new PQueue({ concurrency: parallelism })
Expand Down Expand Up @@ -211,7 +210,7 @@ interface BuildError {

type BuildResult = BuildSuccess | BuildCachedSuccess | BuildFailure | BuildCachedFailure | BuildError;

async function build(drvPath: string, resultDir: string, cachixCache: string): Promise<BuildResult> {
async function build(drvPath: string, resultDir: string, cachixCache: string, cacheDir: string): Promise<BuildResult> {
const cacheKey = "failed-" + path.basename(drvPath, ".drv");

try {
Expand All @@ -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',
Expand Down Expand Up @@ -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}`)
Expand Down Expand Up @@ -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[] = []
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4e25747

Please sign in to comment.