mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2024-12-26 17:30:34 +01:00
Merge pull request #4 from DeterminateSystems/fetch-closure
Fetch the magic-nix-cache closure from S3
This commit is contained in:
commit
574d324eb5
4 changed files with 55 additions and 43 deletions
47
.github/workflows/ci.yml
vendored
47
.github/workflows/ci.yml
vendored
|
@ -48,18 +48,35 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
.github/workflows/cache-test.sh
|
.github/workflows/cache-test.sh
|
||||||
|
|
||||||
# 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
|
||||||
# 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:
|
||||||
# extra-conf: |
|
extra-conf: |
|
||||||
# narinfo-cache-negative-ttl = 0
|
narinfo-cache-negative-ttl = 0
|
||||||
# - name: Cache the store
|
- name: Cache the store
|
||||||
# uses: ./
|
uses: ./
|
||||||
# - name: Check the cache for liveness
|
- name: Check the cache for liveness
|
||||||
# run: |
|
run: |
|
||||||
# .github/workflows/cache-test.sh
|
.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
|
||||||
|
|
|
@ -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: 3
|
default: 8
|
||||||
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
|
||||||
|
|
20
dist/index.js
generated
vendored
20
dist/index.js
generated
vendored
|
@ -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);
|
||||||
|
// 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);
|
||||||
|
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()) {
|
||||||
|
|
29
src/index.ts
29
src/index.ts
|
@ -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,18 @@ 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);
|
||||||
);
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
return `${last_path}/bin/magic-nix-cache`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setUpAutoCache() {
|
async function setUpAutoCache() {
|
||||||
|
@ -98,8 +96,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;
|
||||||
|
|
Loading…
Reference in a new issue