Fetch the magic-nix-cache closure from S3

This commit is contained in:
Eelco Dolstra 2024-01-09 15:01:39 +01:00
parent 1cac1ad780
commit 3931213b43
2 changed files with 23 additions and 27 deletions

20
dist/index.js generated vendored
View file

@ -2,9 +2,8 @@ import * as fs$2 from 'node:fs/promises';
import * as os$2 from 'node:os'; import * as os$2 from 'node:os';
import os__default from 'node:os'; import os__default from 'node:os';
import * as path$1 from 'node:path'; import * as path$1 from 'node:path';
import { spawn } from 'node:child_process'; import { spawn, exec } from 'node:child_process';
import { openSync, createWriteStream } from 'node:fs'; import { openSync } from 'node:fs';
import { pipeline } from 'node:stream/promises';
import { setTimeout as setTimeout$1 } from 'timers/promises'; import { setTimeout as setTimeout$1 } from 'timers/promises';
import { promisify as promisify$1, inspect } from 'node:util'; import { promisify as promisify$1, inspect } from 'node:util';
import require$$0 from 'os'; import require$$0 from 'os';
@ -12138,14 +12137,14 @@ function getCacherUrl() {
} }
return `${urlPrefix}/latest/${binarySuffix}`; return `${urlPrefix}/latest/${binarySuffix}`;
} }
async function fetchAutoCacher(destination) { async function fetchAutoCacher() {
const stream = createWriteStream(destination, {
encoding: "binary",
mode: 0o755,
});
const binary_url = getCacherUrl(); const binary_url = getCacherUrl();
coreExports.info(`Fetching the Magic Nix Cache from ${binary_url}`); 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() { async function setUpAutoCache() {
const tmpdir = process.env['RUNNER_TEMP'] || os$2.tmpdir(); const tmpdir = process.env['RUNNER_TEMP'] || os$2.tmpdir();
@ -12167,8 +12166,7 @@ async function setUpAutoCache() {
daemonBin = coreExports.getInput('source-binary'); daemonBin = coreExports.getInput('source-binary');
} }
else { else {
daemonBin = `${daemonDir}/magic-nix-cache`; daemonBin = await fetchAutoCacher();
await fetchAutoCacher(daemonBin);
} }
var runEnv; var runEnv;
if (coreExports.isDebug()) { if (coreExports.isDebug()) {

View file

@ -3,11 +3,10 @@
import * as fs from 'node:fs/promises'; import * as fs from 'node:fs/promises';
import * as os from 'node:os'; import * as os from 'node:os';
import * as path from 'node:path'; import * as path from 'node:path';
import { spawn } from 'node:child_process'; import { spawn, exec } from 'node:child_process';
import { createWriteStream, openSync } from 'node:fs'; import { openSync } from 'node:fs';
import { pipeline } from 'node:stream/promises';
import { setTimeout } from 'timers/promises'; import { setTimeout } from 'timers/promises';
import { inspect } from 'node:util'; import { inspect, promisify } from 'node:util';
import * as core from '@actions/core'; import * as core from '@actions/core';
import { Tail } from 'tail'; import { Tail } from 'tail';
@ -59,19 +58,19 @@ function getCacherUrl() : string {
return `${urlPrefix}/latest/${binarySuffix}`; return `${urlPrefix}/latest/${binarySuffix}`;
} }
async function fetchAutoCacher(destination: string) { async function fetchAutoCacher() {
const stream = createWriteStream(destination, {
encoding: "binary",
mode: 0o755,
});
const binary_url = getCacherUrl(); const binary_url = getCacherUrl();
core.info(`Fetching the Magic Nix Cache from ${binary_url}`); core.info(`Fetching the Magic Nix Cache from ${binary_url}`);
return pipeline( const { stdout } = await promisify(exec)(`curl "${binary_url}" | xz -d | nix-store --import`);
gotClient.stream(binary_url),
stream 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() { async function setUpAutoCache() {
@ -98,8 +97,7 @@ async function setUpAutoCache() {
if (core.getInput('source-binary')) { if (core.getInput('source-binary')) {
daemonBin = core.getInput('source-binary'); daemonBin = core.getInput('source-binary');
} else { } else {
daemonBin = `${daemonDir}/magic-nix-cache`; daemonBin = await fetchAutoCacher();
await fetchAutoCacher(daemonBin);
} }
var runEnv; var runEnv;