mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2025-01-10 22:22:03 +01:00
Merge pull request #3 from DeterminateSystems/async-push
Push to attic from the post-build-hook
This commit is contained in:
commit
1cac1ad780
4 changed files with 40 additions and 17 deletions
|
@ -23,7 +23,7 @@ inputs:
|
||||||
source-pr:
|
source-pr:
|
||||||
description: The PR of `magic-nix-cache` to use. Conflicts with all other `source-*` options.
|
description: The PR of `magic-nix-cache` to use. Conflicts with all other `source-*` options.
|
||||||
required: false
|
required: false
|
||||||
default: 1
|
default: 3
|
||||||
source-revision:
|
source-revision:
|
||||||
description: The revision of `nix-magic-nix-cache` to use. Conflicts with all other `source-*` options.
|
description: The revision of `nix-magic-nix-cache` to use. Conflicts with all other `source-*` options.
|
||||||
required: false
|
required: false
|
||||||
|
|
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
26
dist/index.js
generated
vendored
26
dist/index.js
generated
vendored
|
@ -12181,10 +12181,12 @@ async function setUpAutoCache() {
|
||||||
else {
|
else {
|
||||||
runEnv = process.env;
|
runEnv = process.env;
|
||||||
}
|
}
|
||||||
const outputPath = `${daemonDir}/parent.log`;
|
// Start the server. Once it is ready, it will notify us via file descriptor 3.
|
||||||
|
const outputPath = `${daemonDir}/daemon.log`;
|
||||||
const output = openSync(outputPath, 'a');
|
const output = openSync(outputPath, 'a');
|
||||||
const launch = spawn(daemonBin, [
|
const notifyFd = 3;
|
||||||
'--daemon-dir', daemonDir,
|
const daemon = spawn(daemonBin, [
|
||||||
|
'--notify-fd', String(notifyFd),
|
||||||
'--listen', coreExports.getInput('listen'),
|
'--listen', coreExports.getInput('listen'),
|
||||||
'--upstream', coreExports.getInput('upstream-cache'),
|
'--upstream', coreExports.getInput('upstream-cache'),
|
||||||
'--diagnostic-endpoint', coreExports.getInput('diagnostic-endpoint'),
|
'--diagnostic-endpoint', coreExports.getInput('diagnostic-endpoint'),
|
||||||
|
@ -12197,13 +12199,20 @@ async function setUpAutoCache() {
|
||||||
] : []).concat(coreExports.getInput('use-gha-cache') === 'true' ? [
|
] : []).concat(coreExports.getInput('use-gha-cache') === 'true' ? [
|
||||||
'--use-gha-cache'
|
'--use-gha-cache'
|
||||||
] : []), {
|
] : []), {
|
||||||
stdio: ['ignore', output, output],
|
stdio: ['ignore', output, output, 'pipe'],
|
||||||
env: runEnv
|
env: runEnv,
|
||||||
|
detached: true
|
||||||
});
|
});
|
||||||
|
const pidFile = path$1.join(daemonDir, 'daemon.pid');
|
||||||
|
await fs$2.writeFile(pidFile, `${daemon.pid}`);
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
launch.on('exit', async (code, signal) => {
|
daemon.stdio[notifyFd].on('data', (data) => {
|
||||||
|
if (data.toString().trim() == 'INIT') {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
daemon.on('exit', async (code, signal) => {
|
||||||
const log = await fs$2.readFile(outputPath, 'utf-8');
|
const log = await fs$2.readFile(outputPath, 'utf-8');
|
||||||
console.log(log);
|
|
||||||
if (signal) {
|
if (signal) {
|
||||||
reject(new Error(`Daemon was killed by signal ${signal}: ${log}`));
|
reject(new Error(`Daemon was killed by signal ${signal}: ${log}`));
|
||||||
}
|
}
|
||||||
|
@ -12211,10 +12220,11 @@ async function setUpAutoCache() {
|
||||||
reject(new Error(`Daemon exited with code ${code}: ${log}`));
|
reject(new Error(`Daemon exited with code ${code}: ${log}`));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
resolve();
|
reject(new Error(`Daemon unexpectedly exited: ${log}`));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
daemon.unref();
|
||||||
coreExports.info('Launched Magic Nix Cache');
|
coreExports.info('Launched Magic Nix Cache');
|
||||||
coreExports.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
|
coreExports.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
|
||||||
}
|
}
|
||||||
|
|
29
src/index.ts
29
src/index.ts
|
@ -113,12 +113,14 @@ async function setUpAutoCache() {
|
||||||
runEnv = process.env;
|
runEnv = process.env;
|
||||||
}
|
}
|
||||||
|
|
||||||
const outputPath = `${daemonDir}/parent.log`;
|
// Start the server. Once it is ready, it will notify us via file descriptor 3.
|
||||||
|
const outputPath = `${daemonDir}/daemon.log`;
|
||||||
const output = openSync(outputPath, 'a');
|
const output = openSync(outputPath, 'a');
|
||||||
const launch = spawn(
|
const notifyFd = 3;
|
||||||
|
const daemon = spawn(
|
||||||
daemonBin,
|
daemonBin,
|
||||||
[
|
[
|
||||||
'--daemon-dir', daemonDir,
|
'--notify-fd', String(notifyFd),
|
||||||
'--listen', core.getInput('listen'),
|
'--listen', core.getInput('listen'),
|
||||||
'--upstream', core.getInput('upstream-cache'),
|
'--upstream', core.getInput('upstream-cache'),
|
||||||
'--diagnostic-endpoint', core.getInput('diagnostic-endpoint'),
|
'--diagnostic-endpoint', core.getInput('diagnostic-endpoint'),
|
||||||
|
@ -134,25 +136,36 @@ async function setUpAutoCache() {
|
||||||
'--use-gha-cache'
|
'--use-gha-cache'
|
||||||
] : []),
|
] : []),
|
||||||
{
|
{
|
||||||
stdio: ['ignore', output, output],
|
stdio: ['ignore', output, output, 'pipe'],
|
||||||
env: runEnv
|
env: runEnv,
|
||||||
|
detached: true
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const pidFile = path.join(daemonDir, 'daemon.pid');
|
||||||
|
await fs.writeFile(pidFile, `${daemon.pid}`);
|
||||||
|
|
||||||
await new Promise<void>((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
launch.on('exit', async (code, signal) => {
|
daemon.stdio[notifyFd].on('data', (data) => {
|
||||||
|
if (data.toString().trim() == 'INIT') {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
daemon.on('exit', async (code, signal) => {
|
||||||
const log: string = await fs.readFile(outputPath, 'utf-8');
|
const log: string = await fs.readFile(outputPath, 'utf-8');
|
||||||
console.log(log);
|
|
||||||
if (signal) {
|
if (signal) {
|
||||||
reject(new Error(`Daemon was killed by signal ${signal}: ${log}`));
|
reject(new Error(`Daemon was killed by signal ${signal}: ${log}`));
|
||||||
} else if (code) {
|
} else if (code) {
|
||||||
reject(new Error(`Daemon exited with code ${code}: ${log}`));
|
reject(new Error(`Daemon exited with code ${code}: ${log}`));
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
reject(new Error(`Daemon unexpectedly exited: ${log}`));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
daemon.unref();
|
||||||
|
|
||||||
core.info('Launched Magic Nix Cache');
|
core.info('Launched Magic Nix Cache');
|
||||||
core.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
|
core.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue