From 3931213b43c6b0a4e8ef2fe9fd11d15bbe1063e3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 9 Jan 2024 15:01:39 +0100 Subject: [PATCH 1/5] Fetch the magic-nix-cache closure from S3 --- dist/index.js | 20 +++++++++----------- src/index.ts | 30 ++++++++++++++---------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/dist/index.js b/dist/index.js index 9fe91b1..74dbbc8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2,9 +2,8 @@ import * as fs$2 from 'node:fs/promises'; import * as os$2 from 'node:os'; import os__default from 'node:os'; import * as path$1 from 'node:path'; -import { spawn } from 'node:child_process'; -import { openSync, createWriteStream } from 'node:fs'; -import { pipeline } from 'node:stream/promises'; +import { spawn, exec } from 'node:child_process'; +import { openSync } from 'node:fs'; import { setTimeout as setTimeout$1 } from 'timers/promises'; import { promisify as promisify$1, inspect } from 'node:util'; import require$$0 from 'os'; @@ -12138,14 +12137,14 @@ function getCacherUrl() { } return `${urlPrefix}/latest/${binarySuffix}`; } -async function fetchAutoCacher(destination) { - const stream = createWriteStream(destination, { - encoding: "binary", - mode: 0o755, - }); +async function fetchAutoCacher() { const binary_url = getCacherUrl(); coreExports.info(`Fetching the Magic Nix Cache from ${binary_url}`); - return pipeline(gotClient.stream(binary_url), stream); + const { stdout } = await promisify$1(exec)(`curl "${binary_url}" | xz -d | nix-store --import`); + const paths = stdout.split(os$2.EOL); + const last_path = paths.at(-2); + console.log(`stdout: ${last_path}`); + return `${last_path}/bin/magic-nix-cache`; } async function setUpAutoCache() { const tmpdir = process.env['RUNNER_TEMP'] || os$2.tmpdir(); @@ -12167,8 +12166,7 @@ async function setUpAutoCache() { daemonBin = coreExports.getInput('source-binary'); } else { - daemonBin = `${daemonDir}/magic-nix-cache`; - await fetchAutoCacher(daemonBin); + daemonBin = await fetchAutoCacher(); } var runEnv; if (coreExports.isDebug()) { diff --git a/src/index.ts b/src/index.ts index 79ade61..d1bc90b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,11 +3,10 @@ import * as fs from 'node:fs/promises'; import * as os from 'node:os'; import * as path from 'node:path'; -import { spawn } from 'node:child_process'; -import { createWriteStream, openSync } from 'node:fs'; -import { pipeline } from 'node:stream/promises'; +import { spawn, exec } from 'node:child_process'; +import { openSync } from 'node:fs'; import { setTimeout } from 'timers/promises'; -import { inspect } from 'node:util'; +import { inspect, promisify } from 'node:util'; import * as core from '@actions/core'; import { Tail } from 'tail'; @@ -59,19 +58,19 @@ function getCacherUrl() : string { return `${urlPrefix}/latest/${binarySuffix}`; } -async function fetchAutoCacher(destination: string) { - const stream = createWriteStream(destination, { - encoding: "binary", - mode: 0o755, - }); - +async function fetchAutoCacher() { const binary_url = getCacherUrl(); core.info(`Fetching the Magic Nix Cache from ${binary_url}`); - return pipeline( - gotClient.stream(binary_url), - stream - ); + const { stdout } = await promisify(exec)(`curl "${binary_url}" | xz -d | nix-store --import`); + + const paths = stdout.split(os.EOL); + + const last_path = paths.at(-2); + + console.log(`stdout: ${last_path}`); + + return `${last_path}/bin/magic-nix-cache`; } async function setUpAutoCache() { @@ -98,8 +97,7 @@ async function setUpAutoCache() { if (core.getInput('source-binary')) { daemonBin = core.getInput('source-binary'); } else { - daemonBin = `${daemonDir}/magic-nix-cache`; - await fetchAutoCacher(daemonBin); + daemonBin = await fetchAutoCacher(); } var runEnv; From 7fb9d0de49fada150b983b5f9bc73206842a7094 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 9 Jan 2024 18:50:18 +0100 Subject: [PATCH 2/5] Fix URL --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 49bf257..c2a9647 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: 3 + default: 8 source-revision: description: The revision of `nix-magic-nix-cache` to use. Conflicts with all other `source-*` options. required: false From 5e8c8cee1b0dacb84bd85bbba6f0e9637a3e6980 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 9 Jan 2024 18:51:52 +0100 Subject: [PATCH 3/5] Comment --- dist/index.js | 1 + src/index.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/dist/index.js b/dist/index.js index 74dbbc8..7ed5c28 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12142,6 +12142,7 @@ async function fetchAutoCacher() { coreExports.info(`Fetching the Magic Nix Cache from ${binary_url}`); const { stdout } = await promisify$1(exec)(`curl "${binary_url}" | xz -d | nix-store --import`); const paths = stdout.split(os$2.EOL); + // Since the export is in reverse topologically sorted order, magic-nix-cache is always the penultimate entry in the list (the empty string left by split being the last). const last_path = paths.at(-2); console.log(`stdout: ${last_path}`); return `${last_path}/bin/magic-nix-cache`; diff --git a/src/index.ts b/src/index.ts index d1bc90b..19d1866 100644 --- a/src/index.ts +++ b/src/index.ts @@ -66,6 +66,7 @@ async function fetchAutoCacher() { const paths = stdout.split(os.EOL); + // Since the export is in reverse topologically sorted order, magic-nix-cache is always the penultimate entry in the list (the empty string left by split being the last). const last_path = paths.at(-2); console.log(`stdout: ${last_path}`); From bbbaf0c54db7221073a92cc83350fed0e101317c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 9 Jan 2024 18:55:07 +0100 Subject: [PATCH 4/5] Test on macOS --- .github/workflows/ci.yml | 47 +++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5bf051..11d456f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,18 +48,35 @@ jobs: run: | .github/workflows/cache-test.sh - # run-x86_64-darwin: - # name: Run x86_64 Darwin - # runs-on: macos-12 - # steps: - # - uses: actions/checkout@v3 - # - name: Install Nix - # uses: DeterminateSystems/nix-installer-action@main - # with: - # extra-conf: | - # narinfo-cache-negative-ttl = 0 - # - name: Cache the store - # uses: ./ - # - name: Check the cache for liveness - # run: | - # .github/workflows/cache-test.sh + run-x86_64-darwin: + name: Run x86_64 Darwin + runs-on: macos-12 + steps: + - uses: actions/checkout@v3 + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + with: + extra-conf: | + narinfo-cache-negative-ttl = 0 + - name: Cache the store + uses: ./ + - name: Check the cache for liveness + run: | + .github/workflows/cache-test.sh + + run-aarch64-darwin: + name: Run aarch64 Darwin + concurrency: build-ARM64-macOS + runs-on: macos-latest-xlarge + steps: + - uses: actions/checkout@v3 + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + with: + extra-conf: | + narinfo-cache-negative-ttl = 0 + - name: Cache the store + uses: ./ + - name: Check the cache for liveness + run: | + .github/workflows/cache-test.sh From e86987a1e9fb03b4d5dd5447da16361fb59b212f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 9 Jan 2024 19:02:02 +0100 Subject: [PATCH 5/5] Remove debug line --- dist/index.js | 1 - src/index.ts | 2 -- 2 files changed, 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7ed5c28..798ea7a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12144,7 +12144,6 @@ async function fetchAutoCacher() { const paths = stdout.split(os$2.EOL); // Since the export is in reverse topologically sorted order, magic-nix-cache is always the penultimate entry in the list (the empty string left by split being the last). const last_path = paths.at(-2); - console.log(`stdout: ${last_path}`); return `${last_path}/bin/magic-nix-cache`; } async function setUpAutoCache() { diff --git a/src/index.ts b/src/index.ts index 19d1866..4542dab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -69,8 +69,6 @@ async function fetchAutoCacher() { // Since the export is in reverse topologically sorted order, magic-nix-cache is always the penultimate entry in the list (the empty string left by split being the last). const last_path = paths.at(-2); - console.log(`stdout: ${last_path}`); - return `${last_path}/bin/magic-nix-cache`; }