mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2024-12-26 01:12:17 +01:00
Merge pull request #2 from DeterminateSystems/attic-v2
Add support for pushing to attic
This commit is contained in:
commit
8a8688f336
4 changed files with 61 additions and 33 deletions
15
action.yml
15
action.yml
|
@ -4,6 +4,10 @@ branding:
|
|||
color: "purple"
|
||||
description: "Free, no-configuration Nix cache. Cut CI time by 50% or more by caching to GitHub Actions' cache."
|
||||
inputs:
|
||||
use-gha-cache:
|
||||
description: "Whether to upload build results to the GitHub Actions cache."
|
||||
default: true
|
||||
required: false
|
||||
listen:
|
||||
description: The host and port to listen on.
|
||||
default: 127.0.0.1:37515
|
||||
|
@ -19,6 +23,7 @@ inputs:
|
|||
source-pr:
|
||||
description: The PR of `magic-nix-cache` to use. Conflicts with all other `source-*` options.
|
||||
required: false
|
||||
default: 1
|
||||
source-revision:
|
||||
description: The revision of `nix-magic-nix-cache` to use. Conflicts with all other `source-*` options.
|
||||
required: false
|
||||
|
@ -31,6 +36,16 @@ inputs:
|
|||
diagnostic-endpoint:
|
||||
description: "Diagnostic endpoint url where diagnostics and performance data is sent. To disable set this to an empty string."
|
||||
default: "https://install.determinate.systems/magic-nix-cache/perf"
|
||||
use-flakehub:
|
||||
description: "Whether to upload build results to FlakeHub."
|
||||
default: true
|
||||
required: false
|
||||
flakehub-cache-server:
|
||||
description: "The FlakeHub binary cache server."
|
||||
default: "https://attic-test.fly.dev"
|
||||
flakehub-api-server:
|
||||
description: "The FlakeHub API server."
|
||||
default: "https://api.flakehub.com"
|
||||
|
||||
runs:
|
||||
using: "node16"
|
||||
|
|
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
38
dist/index.js
generated
vendored
38
dist/index.js
generated
vendored
|
@ -3,7 +3,7 @@ import * as os$2 from 'node:os';
|
|||
import os__default from 'node:os';
|
||||
import * as path$1 from 'node:path';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { openSync, writeSync, close, createWriteStream } from 'node:fs';
|
||||
import { openSync, createWriteStream } from 'node:fs';
|
||||
import { pipeline } from 'node:stream/promises';
|
||||
import { setTimeout as setTimeout$1 } from 'timers/promises';
|
||||
import { promisify as promisify$1, inspect } from 'node:util';
|
||||
|
@ -12120,7 +12120,7 @@ function getCacherUrl() {
|
|||
const runnerArch = process.env.RUNNER_ARCH;
|
||||
const runnerOs = process.env.RUNNER_OS;
|
||||
const binarySuffix = `${runnerArch}-${runnerOs}`;
|
||||
const urlPrefix = `https://install.determinate.systems/magic-nix-cache`;
|
||||
const urlPrefix = `https://magic-nix-cache-priv20231208150408868500000001.s3.us-east-2.amazonaws.com`;
|
||||
if (coreExports.getInput('source-url')) {
|
||||
return coreExports.getInput('source-url');
|
||||
}
|
||||
|
@ -12128,7 +12128,7 @@ function getCacherUrl() {
|
|||
return `${urlPrefix}/tag/${coreExports.getInput('source-tag')}/${binarySuffix}`;
|
||||
}
|
||||
if (coreExports.getInput('source-pr')) {
|
||||
return `${urlPrefix}/pr/${coreExports.getInput('source-pr')}/${binarySuffix}`;
|
||||
return `${urlPrefix}/pr_${coreExports.getInput('source-pr')}/magic-nix-cache-${binarySuffix}`;
|
||||
}
|
||||
if (coreExports.getInput('source-branch')) {
|
||||
return `${urlPrefix}/branch/${coreExports.getInput('source-branch')}/${binarySuffix}`;
|
||||
|
@ -12144,7 +12144,7 @@ async function fetchAutoCacher(destination) {
|
|||
mode: 0o755,
|
||||
});
|
||||
const binary_url = getCacherUrl();
|
||||
coreExports.debug(`Fetching the Magic Nix Cache from ${binary_url}`);
|
||||
coreExports.info(`Fetching the Magic Nix Cache from ${binary_url}`);
|
||||
return pipeline(gotClient.stream(binary_url), stream);
|
||||
}
|
||||
async function setUpAutoCache() {
|
||||
|
@ -12181,35 +12181,41 @@ async function setUpAutoCache() {
|
|||
else {
|
||||
runEnv = process.env;
|
||||
}
|
||||
const output = openSync(`${daemonDir}/parent.log`, 'a');
|
||||
const outputPath = `${daemonDir}/parent.log`;
|
||||
const output = openSync(outputPath, 'a');
|
||||
const launch = spawn(daemonBin, [
|
||||
'--daemon-dir', daemonDir,
|
||||
'--listen', coreExports.getInput('listen'),
|
||||
'--upstream', coreExports.getInput('upstream-cache'),
|
||||
'--diagnostic-endpoint', coreExports.getInput('diagnostic-endpoint')
|
||||
], {
|
||||
'--diagnostic-endpoint', coreExports.getInput('diagnostic-endpoint'),
|
||||
'--nix-conf', `${process.env["HOME"]}/.config/nix/nix.conf`
|
||||
].concat(coreExports.getInput('use-flakehub') === 'true' ? [
|
||||
'--use-flakehub',
|
||||
'--flakehub-cache-server', coreExports.getInput('flakehub-cache-server'),
|
||||
'--flakehub-api-server', coreExports.getInput('flakehub-api-server'),
|
||||
'--flakehub-api-server-netrc', path$1.join(process.env['RUNNER_TEMP'], 'determinate-nix-installer-netrc'),
|
||||
] : []).concat(coreExports.getInput('use-gha-cache') === 'true' ? [
|
||||
'--use-gha-cache'
|
||||
] : []), {
|
||||
stdio: ['ignore', output, output],
|
||||
env: runEnv
|
||||
});
|
||||
await new Promise((resolve, reject) => {
|
||||
launch.on('exit', (code, signal) => {
|
||||
launch.on('exit', async (code, signal) => {
|
||||
const log = await fs$2.readFile(outputPath, 'utf-8');
|
||||
console.log(log);
|
||||
if (signal) {
|
||||
reject(new Error(`Daemon was killed by signal ${signal}`));
|
||||
reject(new Error(`Daemon was killed by signal ${signal}: ${log}`));
|
||||
}
|
||||
else if (code) {
|
||||
reject(new Error(`Daemon exited with code ${code}`));
|
||||
reject(new Error(`Daemon exited with code ${code}: ${log}`));
|
||||
}
|
||||
else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
await fs$2.mkdir(`${process.env["HOME"]}/.config/nix`, { recursive: true });
|
||||
const nixConf = openSync(`${process.env["HOME"]}/.config/nix/nix.conf`, 'a');
|
||||
writeSync(nixConf, `${"\n"}extra-substituters = http://${coreExports.getInput('listen')}/?trusted=1&compression=zstd¶llel-compression=true${"\n"}`);
|
||||
writeSync(nixConf, `fallback = true${"\n"}`);
|
||||
close(nixConf);
|
||||
coreExports.debug('Launched Magic Nix Cache');
|
||||
coreExports.info('Launched Magic Nix Cache');
|
||||
coreExports.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
|
||||
}
|
||||
async function notifyAutoCache() {
|
||||
|
|
41
src/index.ts
41
src/index.ts
|
@ -4,7 +4,7 @@ import * as fs from 'node:fs/promises';
|
|||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { createWriteStream, openSync, writeSync, close } from 'node:fs';
|
||||
import { createWriteStream, openSync } from 'node:fs';
|
||||
import { pipeline } from 'node:stream/promises';
|
||||
import { setTimeout } from 'timers/promises';
|
||||
import { inspect } from 'node:util';
|
||||
|
@ -34,7 +34,7 @@ function getCacherUrl() : string {
|
|||
const runnerArch = process.env.RUNNER_ARCH;
|
||||
const runnerOs = process.env.RUNNER_OS;
|
||||
const binarySuffix = `${runnerArch}-${runnerOs}`;
|
||||
const urlPrefix = `https://install.determinate.systems/magic-nix-cache`;
|
||||
const urlPrefix = `https://magic-nix-cache-priv20231208150408868500000001.s3.us-east-2.amazonaws.com`;
|
||||
|
||||
if (core.getInput('source-url')) {
|
||||
return core.getInput('source-url');
|
||||
|
@ -45,7 +45,7 @@ function getCacherUrl() : string {
|
|||
}
|
||||
|
||||
if (core.getInput('source-pr')) {
|
||||
return `${urlPrefix}/pr/${core.getInput('source-pr')}/${binarySuffix}`;
|
||||
return `${urlPrefix}/pr_${core.getInput('source-pr')}/magic-nix-cache-${binarySuffix}`;
|
||||
}
|
||||
|
||||
if (core.getInput('source-branch')) {
|
||||
|
@ -66,7 +66,7 @@ async function fetchAutoCacher(destination: string) {
|
|||
});
|
||||
|
||||
const binary_url = getCacherUrl();
|
||||
core.debug(`Fetching the Magic Nix Cache from ${binary_url}`);
|
||||
core.info(`Fetching the Magic Nix Cache from ${binary_url}`);
|
||||
|
||||
return pipeline(
|
||||
gotClient.stream(binary_url),
|
||||
|
@ -113,15 +113,26 @@ async function setUpAutoCache() {
|
|||
runEnv = process.env;
|
||||
}
|
||||
|
||||
const output = openSync(`${daemonDir}/parent.log`, 'a');
|
||||
const outputPath = `${daemonDir}/parent.log`;
|
||||
const output = openSync(outputPath, 'a');
|
||||
const launch = spawn(
|
||||
daemonBin,
|
||||
[
|
||||
'--daemon-dir', daemonDir,
|
||||
'--listen', core.getInput('listen'),
|
||||
'--upstream', core.getInput('upstream-cache'),
|
||||
'--diagnostic-endpoint', core.getInput('diagnostic-endpoint')
|
||||
],
|
||||
'--diagnostic-endpoint', core.getInput('diagnostic-endpoint'),
|
||||
'--nix-conf', `${process.env["HOME"]}/.config/nix/nix.conf`
|
||||
].concat(
|
||||
core.getInput('use-flakehub') === 'true' ? [
|
||||
'--use-flakehub',
|
||||
'--flakehub-cache-server', core.getInput('flakehub-cache-server'),
|
||||
'--flakehub-api-server', core.getInput('flakehub-api-server'),
|
||||
'--flakehub-api-server-netrc', path.join(process.env['RUNNER_TEMP'], 'determinate-nix-installer-netrc'),
|
||||
] : []).concat(
|
||||
core.getInput('use-gha-cache') === 'true' ? [
|
||||
'--use-gha-cache'
|
||||
] : []),
|
||||
{
|
||||
stdio: ['ignore', output, output],
|
||||
env: runEnv
|
||||
|
@ -129,24 +140,20 @@ async function setUpAutoCache() {
|
|||
);
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
launch.on('exit', (code, signal) => {
|
||||
launch.on('exit', async (code, signal) => {
|
||||
const log: string = await fs.readFile(outputPath, 'utf-8');
|
||||
console.log(log);
|
||||
if (signal) {
|
||||
reject(new Error(`Daemon was killed by signal ${signal}`));
|
||||
reject(new Error(`Daemon was killed by signal ${signal}: ${log}`));
|
||||
} else if (code) {
|
||||
reject(new Error(`Daemon exited with code ${code}`));
|
||||
reject(new Error(`Daemon exited with code ${code}: ${log}`));
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
await fs.mkdir(`${process.env["HOME"]}/.config/nix`, { recursive: true });
|
||||
const nixConf = openSync(`${process.env["HOME"]}/.config/nix/nix.conf`, 'a');
|
||||
writeSync(nixConf, `${"\n"}extra-substituters = http://${core.getInput('listen')}/?trusted=1&compression=zstd¶llel-compression=true${"\n"}`);
|
||||
writeSync(nixConf, `fallback = true${"\n"}`);
|
||||
close(nixConf);
|
||||
|
||||
core.debug('Launched Magic Nix Cache');
|
||||
core.info('Launched Magic Nix Cache');
|
||||
core.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue