mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2025-01-10 14:12: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:
|
||||
description: The PR of `magic-nix-cache` to use. Conflicts with all other `source-*` options.
|
||||
required: false
|
||||
default: 1
|
||||
default: 3
|
||||
source-revision:
|
||||
description: The revision of `nix-magic-nix-cache` to use. Conflicts with all other `source-*` options.
|
||||
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 {
|
||||
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 launch = spawn(daemonBin, [
|
||||
'--daemon-dir', daemonDir,
|
||||
const notifyFd = 3;
|
||||
const daemon = spawn(daemonBin, [
|
||||
'--notify-fd', String(notifyFd),
|
||||
'--listen', coreExports.getInput('listen'),
|
||||
'--upstream', coreExports.getInput('upstream-cache'),
|
||||
'--diagnostic-endpoint', coreExports.getInput('diagnostic-endpoint'),
|
||||
|
@ -12197,13 +12199,20 @@ async function setUpAutoCache() {
|
|||
] : []).concat(coreExports.getInput('use-gha-cache') === 'true' ? [
|
||||
'--use-gha-cache'
|
||||
] : []), {
|
||||
stdio: ['ignore', output, output],
|
||||
env: runEnv
|
||||
stdio: ['ignore', output, output, 'pipe'],
|
||||
env: runEnv,
|
||||
detached: true
|
||||
});
|
||||
const pidFile = path$1.join(daemonDir, 'daemon.pid');
|
||||
await fs$2.writeFile(pidFile, `${daemon.pid}`);
|
||||
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');
|
||||
console.log(log);
|
||||
if (signal) {
|
||||
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}`));
|
||||
}
|
||||
else {
|
||||
resolve();
|
||||
reject(new Error(`Daemon unexpectedly exited: ${log}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
daemon.unref();
|
||||
coreExports.info('Launched Magic Nix Cache');
|
||||
coreExports.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
|
||||
}
|
||||
|
|
29
src/index.ts
29
src/index.ts
|
@ -113,12 +113,14 @@ async function setUpAutoCache() {
|
|||
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 launch = spawn(
|
||||
const notifyFd = 3;
|
||||
const daemon = spawn(
|
||||
daemonBin,
|
||||
[
|
||||
'--daemon-dir', daemonDir,
|
||||
'--notify-fd', String(notifyFd),
|
||||
'--listen', core.getInput('listen'),
|
||||
'--upstream', core.getInput('upstream-cache'),
|
||||
'--diagnostic-endpoint', core.getInput('diagnostic-endpoint'),
|
||||
|
@ -134,25 +136,36 @@ async function setUpAutoCache() {
|
|||
'--use-gha-cache'
|
||||
] : []),
|
||||
{
|
||||
stdio: ['ignore', output, output],
|
||||
env: runEnv
|
||||
stdio: ['ignore', output, output, 'pipe'],
|
||||
env: runEnv,
|
||||
detached: true
|
||||
}
|
||||
);
|
||||
|
||||
const pidFile = path.join(daemonDir, 'daemon.pid');
|
||||
await fs.writeFile(pidFile, `${daemon.pid}`);
|
||||
|
||||
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');
|
||||
console.log(log);
|
||||
if (signal) {
|
||||
reject(new Error(`Daemon was killed by signal ${signal}: ${log}`));
|
||||
} else if (code) {
|
||||
reject(new Error(`Daemon exited with code ${code}: ${log}`));
|
||||
} else {
|
||||
resolve();
|
||||
reject(new Error(`Daemon unexpectedly exited: ${log}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
daemon.unref();
|
||||
|
||||
core.info('Launched Magic Nix Cache');
|
||||
core.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue