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:
Eelco Dolstra 2024-01-15 14:18:04 +01:00 committed by GitHub
commit d6ee674f6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 23 deletions

View file

@ -1,12 +1,45 @@
#!/bin/sh #! /usr/bin/env bash
set -e set -e
set -ux set -ux
seed=$(date) 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") 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" nix copy --to 'http://127.0.0.1:37515' "$outpath"
rm ./result rm ./result
nix store delete "$outpath" nix store delete "$outpath"
if [ -f "$outpath" ]; then if [ -f "$outpath" ]; then

View file

@ -35,11 +35,15 @@ jobs:
run-x86_64-linux: run-x86_64-linux:
name: Run x86_64 Linux name: Run x86_64 Linux
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
permissions:
id-token: "write"
contents: "read"
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Install Nix - name: Install Nix
uses: DeterminateSystems/nix-installer-action@main uses: DeterminateSystems/nix-installer-action@main
with: with:
flakehub: true
extra-conf: | extra-conf: |
narinfo-cache-negative-ttl = 0 narinfo-cache-negative-ttl = 0
- name: Cache the store - name: Cache the store
@ -51,11 +55,15 @@ jobs:
run-x86_64-darwin: run-x86_64-darwin:
name: Run x86_64 Darwin name: Run x86_64 Darwin
runs-on: macos-12 runs-on: macos-12
permissions:
id-token: "write"
contents: "read"
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Install Nix - name: Install Nix
uses: DeterminateSystems/nix-installer-action@main uses: DeterminateSystems/nix-installer-action@main
with: with:
flakehub: true
extra-conf: | extra-conf: |
narinfo-cache-negative-ttl = 0 narinfo-cache-negative-ttl = 0
- name: Cache the store - name: Cache the store
@ -68,11 +76,15 @@ jobs:
name: Run aarch64 Darwin name: Run aarch64 Darwin
concurrency: build-ARM64-macOS concurrency: build-ARM64-macOS
runs-on: macos-latest-xlarge runs-on: macos-latest-xlarge
permissions:
id-token: "write"
contents: "read"
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Install Nix - name: Install Nix
uses: DeterminateSystems/nix-installer-action@main uses: DeterminateSystems/nix-installer-action@main
with: with:
flakehub: true
extra-conf: | extra-conf: |
narinfo-cache-negative-ttl = 0 narinfo-cache-negative-ttl = 0
- name: Cache the store - name: Cache the store

View file

@ -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: 8 default: 10
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

24
dist/index.js generated vendored
View file

@ -12146,6 +12146,14 @@ async function fetchAutoCacher() {
const last_path = paths.at(-2); const last_path = paths.at(-2);
return `${last_path}/bin/magic-nix-cache`; 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() { async function setUpAutoCache() {
const tmpdir = process.env['RUNNER_TEMP'] || os$2.tmpdir(); const tmpdir = process.env['RUNNER_TEMP'] || os$2.tmpdir();
const required_env = ['ACTIONS_CACHE_URL', 'ACTIONS_RUNTIME_URL', 'ACTIONS_RUNTIME_TOKEN']; 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. // Start the server. Once it is ready, it will notify us via file descriptor 3.
const outputPath = `${daemonDir}/daemon.log`; const outputPath = `${daemonDir}/daemon.log`;
const output = openSync(outputPath, 'a'); const output = openSync(outputPath, 'a');
const log = tailLog(daemonDir);
const notifyFd = 3; const notifyFd = 3;
const daemon = spawn(daemonBin, [ const daemon = spawn(daemonBin, [
'--notify-fd', String(notifyFd), '--notify-fd', String(notifyFd),
@ -12210,21 +12219,21 @@ async function setUpAutoCache() {
} }
}); });
daemon.on('exit', async (code, signal) => { daemon.on('exit', async (code, signal) => {
const log = await fs$2.readFile(outputPath, 'utf-8');
if (signal) { if (signal) {
reject(new Error(`Daemon was killed by signal ${signal}: ${log}`)); reject(new Error(`Daemon was killed by signal ${signal}`));
} }
else if (code) { else if (code) {
reject(new Error(`Daemon exited with code ${code}: ${log}`)); reject(new Error(`Daemon exited with code ${code}`));
} }
else { else {
reject(new Error(`Daemon unexpectedly exited: ${log}`)); reject(new Error(`Daemon unexpectedly exited`));
} }
}); });
}); });
daemon.unref(); 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);
log.unwatch();
} }
async function notifyAutoCache() { async function notifyAutoCache() {
const daemonDir = process.env[ENV_CACHE_DAEMONDIR]; const daemonDir = process.env[ENV_CACHE_DAEMONDIR];
@ -12255,12 +12264,7 @@ async function tearDownAutoCache() {
if (!pid) { if (!pid) {
throw new Error("magic-nix-cache did not start successfully"); throw new Error("magic-nix-cache did not start successfully");
} }
const log = new Tail_1(path$1.join(daemonDir, 'daemon.log')); const log = tailLog(daemonDir);
coreExports.debug(`tailing daemon.log...`);
log.on('line', (line) => {
coreExports.debug(`got a log line`);
coreExports.info(line);
});
try { try {
coreExports.debug(`about to post to localhost`); coreExports.debug(`about to post to localhost`);
const res = await gotClient.post(`http://${coreExports.getInput('listen')}/api/workflow-finish`).json(); const res = await gotClient.post(`http://${coreExports.getInput('listen')}/api/workflow-finish`).json();

View file

@ -72,6 +72,15 @@ async function fetchAutoCacher() {
return `${last_path}/bin/magic-nix-cache`; 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() { async function setUpAutoCache() {
const tmpdir = process.env['RUNNER_TEMP'] || os.tmpdir(); const tmpdir = process.env['RUNNER_TEMP'] || os.tmpdir();
const required_env = ['ACTIONS_CACHE_URL', 'ACTIONS_RUNTIME_URL', 'ACTIONS_RUNTIME_TOKEN']; 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. // Start the server. Once it is ready, it will notify us via file descriptor 3.
const outputPath = `${daemonDir}/daemon.log`; const outputPath = `${daemonDir}/daemon.log`;
const output = openSync(outputPath, 'a'); const output = openSync(outputPath, 'a');
const log = tailLog(daemonDir);
const notifyFd = 3; const notifyFd = 3;
const daemon = spawn( const daemon = spawn(
daemonBin, daemonBin,
@ -150,13 +160,12 @@ async function setUpAutoCache() {
}); });
daemon.on('exit', async (code, signal) => { daemon.on('exit', async (code, signal) => {
const log: string = await fs.readFile(outputPath, 'utf-8');
if (signal) { if (signal) {
reject(new Error(`Daemon was killed by signal ${signal}: ${log}`)); reject(new Error(`Daemon was killed by signal ${signal}`));
} else if (code) { } else if (code) {
reject(new Error(`Daemon exited with code ${code}: ${log}`)); reject(new Error(`Daemon exited with code ${code}`));
} else { } 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.info('Launched Magic Nix Cache');
core.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir); core.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
log.unwatch();
} }
async function notifyAutoCache() { async function notifyAutoCache() {
@ -201,13 +212,7 @@ async function tearDownAutoCache() {
throw new Error("magic-nix-cache did not start successfully"); throw new Error("magic-nix-cache did not start successfully");
} }
const log = new Tail(path.join(daemonDir, 'daemon.log')); const log = tailLog(daemonDir);
core.debug(`tailing daemon.log...`);
log.on('line', (line) => {
core.debug(`got a log line`);
core.info(line);
});
try { try {
core.debug(`about to post to localhost`); core.debug(`about to post to localhost`);