mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2024-12-26 09:20:35 +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: |
|
||||
.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
|
||||
|
|
|
@ -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
|
||||
|
|
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 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);
|
||||
// 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() {
|
||||
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()) {
|
||||
|
|
29
src/index.ts
29
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,18 @@ 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);
|
||||
|
||||
// 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() {
|
||||
|
@ -98,8 +96,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;
|
||||
|
|
Loading…
Reference in a new issue