From 3931213b43c6b0a4e8ef2fe9fd11d15bbe1063e3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 9 Jan 2024 15:01:39 +0100 Subject: [PATCH] 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;