mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2024-12-23 05:22:07 +01:00
Merge pull request #5 from DeterminateSystems/eelcodolstra/fh-162-magic-nix-cache-action-test-pushing-to-flakehub
Test FlakeHub push
This commit is contained in:
commit
d6ee674f6e
5 changed files with 77 additions and 23 deletions
35
.github/workflows/cache-test.sh
vendored
35
.github/workflows/cache-test.sh
vendored
|
@ -1,12 +1,45 @@
|
|||
#!/bin/sh
|
||||
#! /usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -ux
|
||||
|
||||
seed=$(date)
|
||||
|
||||
log=$MAGIC_NIX_CACHE_DAEMONDIR/daemon.log
|
||||
|
||||
binary_cache=https://attic-test.fly.dev
|
||||
|
||||
# Check that the action initialized correctly.
|
||||
grep 'FlakeHub cache is enabled' $log
|
||||
grep 'Using cache' $log
|
||||
grep 'GitHub Action cache is enabled' $log
|
||||
|
||||
# Build something.
|
||||
outpath=$(nix-build .github/workflows/cache-tester.nix --argstr seed "$seed")
|
||||
|
||||
# Check that the path was enqueued to be pushed to the cache.
|
||||
grep "Enqueueing.*$outpath" $log
|
||||
|
||||
# Wait until it has been pushed succesfully.
|
||||
found=
|
||||
for ((i = 0; i < 60; i++)); do
|
||||
sleep 1
|
||||
if grep "✅ $(basename $outpath)" $log; then
|
||||
found=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ -z $found ]]; then
|
||||
echo "FlakeHub push did not happen." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check the FlakeHub binary cache to see if the path is really there.
|
||||
nix path-info --store "$binary_cache" $outpath
|
||||
|
||||
# FIXME: remove this once the daemon also uploads to GHA automatically.
|
||||
nix copy --to 'http://127.0.0.1:37515' "$outpath"
|
||||
|
||||
rm ./result
|
||||
nix store delete "$outpath"
|
||||
if [ -f "$outpath" ]; then
|
||||
|
|
12
.github/workflows/ci.yml
vendored
12
.github/workflows/ci.yml
vendored
|
@ -35,11 +35,15 @@ jobs:
|
|||
run-x86_64-linux:
|
||||
name: Run x86_64 Linux
|
||||
runs-on: ubuntu-22.04
|
||||
permissions:
|
||||
id-token: "write"
|
||||
contents: "read"
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install Nix
|
||||
uses: DeterminateSystems/nix-installer-action@main
|
||||
with:
|
||||
flakehub: true
|
||||
extra-conf: |
|
||||
narinfo-cache-negative-ttl = 0
|
||||
- name: Cache the store
|
||||
|
@ -51,11 +55,15 @@ jobs:
|
|||
run-x86_64-darwin:
|
||||
name: Run x86_64 Darwin
|
||||
runs-on: macos-12
|
||||
permissions:
|
||||
id-token: "write"
|
||||
contents: "read"
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install Nix
|
||||
uses: DeterminateSystems/nix-installer-action@main
|
||||
with:
|
||||
flakehub: true
|
||||
extra-conf: |
|
||||
narinfo-cache-negative-ttl = 0
|
||||
- name: Cache the store
|
||||
|
@ -68,11 +76,15 @@ jobs:
|
|||
name: Run aarch64 Darwin
|
||||
concurrency: build-ARM64-macOS
|
||||
runs-on: macos-latest-xlarge
|
||||
permissions:
|
||||
id-token: "write"
|
||||
contents: "read"
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install Nix
|
||||
uses: DeterminateSystems/nix-installer-action@main
|
||||
with:
|
||||
flakehub: true
|
||||
extra-conf: |
|
||||
narinfo-cache-negative-ttl = 0
|
||||
- name: Cache the store
|
||||
|
|
|
@ -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: 8
|
||||
default: 10
|
||||
source-revision:
|
||||
description: The revision of `nix-magic-nix-cache` to use. Conflicts with all other `source-*` options.
|
||||
required: false
|
||||
|
|
24
dist/index.js
generated
vendored
24
dist/index.js
generated
vendored
|
@ -12146,6 +12146,14 @@ async function fetchAutoCacher() {
|
|||
const last_path = paths.at(-2);
|
||||
return `${last_path}/bin/magic-nix-cache`;
|
||||
}
|
||||
function tailLog(daemonDir) {
|
||||
const log = new Tail_1(path$1.join(daemonDir, 'daemon.log'));
|
||||
coreExports.debug(`tailing daemon.log...`);
|
||||
log.on('line', (line) => {
|
||||
coreExports.info(line);
|
||||
});
|
||||
return log;
|
||||
}
|
||||
async function setUpAutoCache() {
|
||||
const tmpdir = process.env['RUNNER_TEMP'] || os$2.tmpdir();
|
||||
const required_env = ['ACTIONS_CACHE_URL', 'ACTIONS_RUNTIME_URL', 'ACTIONS_RUNTIME_TOKEN'];
|
||||
|
@ -12182,6 +12190,7 @@ async function setUpAutoCache() {
|
|||
// 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 log = tailLog(daemonDir);
|
||||
const notifyFd = 3;
|
||||
const daemon = spawn(daemonBin, [
|
||||
'--notify-fd', String(notifyFd),
|
||||
|
@ -12210,21 +12219,21 @@ async function setUpAutoCache() {
|
|||
}
|
||||
});
|
||||
daemon.on('exit', async (code, signal) => {
|
||||
const log = await fs$2.readFile(outputPath, 'utf-8');
|
||||
if (signal) {
|
||||
reject(new Error(`Daemon was killed by signal ${signal}: ${log}`));
|
||||
reject(new Error(`Daemon was killed by signal ${signal}`));
|
||||
}
|
||||
else if (code) {
|
||||
reject(new Error(`Daemon exited with code ${code}: ${log}`));
|
||||
reject(new Error(`Daemon exited with code ${code}`));
|
||||
}
|
||||
else {
|
||||
reject(new Error(`Daemon unexpectedly exited: ${log}`));
|
||||
reject(new Error(`Daemon unexpectedly exited`));
|
||||
}
|
||||
});
|
||||
});
|
||||
daemon.unref();
|
||||
coreExports.info('Launched Magic Nix Cache');
|
||||
coreExports.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
|
||||
log.unwatch();
|
||||
}
|
||||
async function notifyAutoCache() {
|
||||
const daemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
||||
|
@ -12255,12 +12264,7 @@ async function tearDownAutoCache() {
|
|||
if (!pid) {
|
||||
throw new Error("magic-nix-cache did not start successfully");
|
||||
}
|
||||
const log = new Tail_1(path$1.join(daemonDir, 'daemon.log'));
|
||||
coreExports.debug(`tailing daemon.log...`);
|
||||
log.on('line', (line) => {
|
||||
coreExports.debug(`got a log line`);
|
||||
coreExports.info(line);
|
||||
});
|
||||
const log = tailLog(daemonDir);
|
||||
try {
|
||||
coreExports.debug(`about to post to localhost`);
|
||||
const res = await gotClient.post(`http://${coreExports.getInput('listen')}/api/workflow-finish`).json();
|
||||
|
|
27
src/index.ts
27
src/index.ts
|
@ -72,6 +72,15 @@ async function fetchAutoCacher() {
|
|||
return `${last_path}/bin/magic-nix-cache`;
|
||||
}
|
||||
|
||||
function tailLog(daemonDir) {
|
||||
const log = new Tail(path.join(daemonDir, 'daemon.log'));
|
||||
core.debug(`tailing daemon.log...`);
|
||||
log.on('line', (line) => {
|
||||
core.info(line);
|
||||
});
|
||||
return log;
|
||||
}
|
||||
|
||||
async function setUpAutoCache() {
|
||||
const tmpdir = process.env['RUNNER_TEMP'] || os.tmpdir();
|
||||
const required_env = ['ACTIONS_CACHE_URL', 'ACTIONS_RUNTIME_URL', 'ACTIONS_RUNTIME_TOKEN'];
|
||||
|
@ -113,6 +122,7 @@ async function setUpAutoCache() {
|
|||
// 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 log = tailLog(daemonDir);
|
||||
const notifyFd = 3;
|
||||
const daemon = spawn(
|
||||
daemonBin,
|
||||
|
@ -150,13 +160,12 @@ async function setUpAutoCache() {
|
|||
});
|
||||
|
||||
daemon.on('exit', async (code, signal) => {
|
||||
const log: string = await fs.readFile(outputPath, 'utf-8');
|
||||
if (signal) {
|
||||
reject(new Error(`Daemon was killed by signal ${signal}: ${log}`));
|
||||
reject(new Error(`Daemon was killed by signal ${signal}`));
|
||||
} else if (code) {
|
||||
reject(new Error(`Daemon exited with code ${code}: ${log}`));
|
||||
reject(new Error(`Daemon exited with code ${code}`));
|
||||
} else {
|
||||
reject(new Error(`Daemon unexpectedly exited: ${log}`));
|
||||
reject(new Error(`Daemon unexpectedly exited`));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -165,6 +174,8 @@ async function setUpAutoCache() {
|
|||
|
||||
core.info('Launched Magic Nix Cache');
|
||||
core.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
|
||||
|
||||
log.unwatch();
|
||||
}
|
||||
|
||||
async function notifyAutoCache() {
|
||||
|
@ -201,13 +212,7 @@ async function tearDownAutoCache() {
|
|||
throw new Error("magic-nix-cache did not start successfully");
|
||||
}
|
||||
|
||||
const log = new Tail(path.join(daemonDir, 'daemon.log'));
|
||||
core.debug(`tailing daemon.log...`);
|
||||
log.on('line', (line) => {
|
||||
core.debug(`got a log line`);
|
||||
core.info(line);
|
||||
});
|
||||
|
||||
const log = tailLog(daemonDir);
|
||||
|
||||
try {
|
||||
core.debug(`about to post to localhost`);
|
||||
|
|
Loading…
Reference in a new issue