From 35b2e152f02ebcfebed2d9dbc32562490e625c52 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 11 Jan 2024 16:06:47 +0100 Subject: [PATCH 1/6] Bump magic-nix-cache --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c2a9647..1f7bbd7 100644 --- a/action.yml +++ b/action.yml @@ -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 From 124dc2196ddf81817ab88bc1fe9ec3ee563747b1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 11 Jan 2024 16:55:51 +0100 Subject: [PATCH 2/6] Show daemon log output in setup --- dist/index.js | 25 +++++++++++++++---------- src/index.ts | 28 +++++++++++++++++----------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/dist/index.js b/dist/index.js index 798ea7a..0a1acc3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12146,6 +12146,15 @@ 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) => { + //core.debug(`got a log 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 +12191,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 +12220,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 +12265,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(); diff --git a/src/index.ts b/src/index.ts index 4542dab..e767125 100644 --- a/src/index.ts +++ b/src/index.ts @@ -72,6 +72,16 @@ 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.debug(`got a log 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 +123,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 +161,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 +175,8 @@ async function setUpAutoCache() { core.info('Launched Magic Nix Cache'); core.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir); + + log.unwatch(); } async function notifyAutoCache() { @@ -201,13 +213,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`); From 5249aeeabd32cd81b9fc6eb28bdc1726dea3a0f8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 11 Jan 2024 17:53:42 +0100 Subject: [PATCH 3/6] Enable flakehub --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11d456f..861a73b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,6 +40,7 @@ jobs: - name: Install Nix uses: DeterminateSystems/nix-installer-action@main with: + flakehub: true extra-conf: | narinfo-cache-negative-ttl = 0 - name: Cache the store @@ -56,6 +57,7 @@ jobs: - name: Install Nix uses: DeterminateSystems/nix-installer-action@main with: + flakehub: true extra-conf: | narinfo-cache-negative-ttl = 0 - name: Cache the store @@ -73,6 +75,7 @@ jobs: - name: Install Nix uses: DeterminateSystems/nix-installer-action@main with: + flakehub: true extra-conf: | narinfo-cache-negative-ttl = 0 - name: Cache the store From eb14f4bded200a6306ccf2164dd495157e55f097 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 11 Jan 2024 17:55:33 +0100 Subject: [PATCH 4/6] Pass id-token --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 861a73b..2239b9e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,9 @@ 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 @@ -52,6 +55,9 @@ 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 @@ -70,6 +76,9 @@ 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 From d51150dd47a40f6d3f4e2d6fd677eeccfd72c865 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 11 Jan 2024 18:14:06 +0100 Subject: [PATCH 5/6] Test pushing to FlakeHub --- .github/workflows/cache-test.sh | 35 ++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cache-test.sh b/.github/workflows/cache-test.sh index c1f7eb1..49e687b 100755 --- a/.github/workflows/cache-test.sh +++ b/.github/workflows/cache-test.sh @@ -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 From 8ee9ed5891b5311b9a49e0e400113ad1d9a4c356 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 15 Jan 2024 14:15:24 +0100 Subject: [PATCH 6/6] Cleanup --- dist/index.js | 1 - src/index.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 0a1acc3..59f809c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12150,7 +12150,6 @@ function tailLog(daemonDir) { const log = new Tail_1(path$1.join(daemonDir, 'daemon.log')); coreExports.debug(`tailing daemon.log...`); log.on('line', (line) => { - //core.debug(`got a log line`); coreExports.info(line); }); return log; diff --git a/src/index.ts b/src/index.ts index e767125..94e6178 100644 --- a/src/index.ts +++ b/src/index.ts @@ -76,7 +76,6 @@ function tailLog(daemonDir) { 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); }); return log;