Skip to content

Commit

Permalink
Merge pull request #5 from DeterminateSystems/eelcodolstra/fh-162-mag…
Browse files Browse the repository at this point in the history
…ic-nix-cache-action-test-pushing-to-flakehub

Test FlakeHub push
  • Loading branch information
edolstra authored Jan 15, 2024
2 parents 574d324 + 8ee9ed5 commit d6ee674
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 23 deletions.
35 changes: 34 additions & 1 deletion .github/workflows/cache-test.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
#!/bin/sh
#! /usr/bin/env bash

set -e
set -ux

seed=$(date)

log=$MAGIC_NIX_CACHE_DAEMONDIR/daemon.log

binary_cache=https://attic-test.fly.dev

# Check that the action initialized correctly.
grep 'FlakeHub cache is enabled' $log
grep 'Using cache' $log
grep 'GitHub Action cache is enabled' $log

# Build something.
outpath=$(nix-build .github/workflows/cache-tester.nix --argstr seed "$seed")

# Check that the path was enqueued to be pushed to the cache.
grep "Enqueueing.*$outpath" $log

# Wait until it has been pushed succesfully.
found=
for ((i = 0; i < 60; i++)); do
sleep 1
if grep "$(basename $outpath)" $log; then
found=1
break
fi
done
if [[ -z $found ]]; then
echo "FlakeHub push did not happen." >&2
exit 1
fi

# Check the FlakeHub binary cache to see if the path is really there.
nix path-info --store "$binary_cache" $outpath

# FIXME: remove this once the daemon also uploads to GHA automatically.
nix copy --to 'http://127.0.0.1:37515' "$outpath"

rm ./result
nix store delete "$outpath"
if [ -f "$outpath" ]; then
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ jobs:
run-x86_64-linux:
name: Run x86_64 Linux
runs-on: ubuntu-22.04
permissions:
id-token: "write"
contents: "read"
steps:
- uses: actions/checkout@v3
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
with:
flakehub: true
extra-conf: |
narinfo-cache-negative-ttl = 0
- name: Cache the store
Expand All @@ -51,11 +55,15 @@ jobs:
run-x86_64-darwin:
name: Run x86_64 Darwin
runs-on: macos-12
permissions:
id-token: "write"
contents: "read"
steps:
- uses: actions/checkout@v3
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
with:
flakehub: true
extra-conf: |
narinfo-cache-negative-ttl = 0
- name: Cache the store
Expand All @@ -68,11 +76,15 @@ jobs:
name: Run aarch64 Darwin
concurrency: build-ARM64-macOS
runs-on: macos-latest-xlarge
permissions:
id-token: "write"
contents: "read"
steps:
- uses: actions/checkout@v3
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
with:
flakehub: true
extra-conf: |
narinfo-cache-negative-ttl = 0
- name: Cache the store
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 8
default: 10
source-revision:
description: The revision of `nix-magic-nix-cache` to use. Conflicts with all other `source-*` options.
required: false
Expand Down
24 changes: 14 additions & 10 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 16 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ async function fetchAutoCacher() {
return `${last_path}/bin/magic-nix-cache`;
}

function tailLog(daemonDir) {
const log = new Tail(path.join(daemonDir, 'daemon.log'));
core.debug(`tailing daemon.log...`);
log.on('line', (line) => {
core.info(line);
});
return log;
}

async function setUpAutoCache() {
const tmpdir = process.env['RUNNER_TEMP'] || os.tmpdir();
const required_env = ['ACTIONS_CACHE_URL', 'ACTIONS_RUNTIME_URL', 'ACTIONS_RUNTIME_TOKEN'];
Expand Down Expand Up @@ -113,6 +122,7 @@ async function setUpAutoCache() {
// Start the server. Once it is ready, it will notify us via file descriptor 3.
const outputPath = `${daemonDir}/daemon.log`;
const output = openSync(outputPath, 'a');
const log = tailLog(daemonDir);
const notifyFd = 3;
const daemon = spawn(
daemonBin,
Expand Down Expand Up @@ -150,13 +160,12 @@ async function setUpAutoCache() {
});

daemon.on('exit', async (code, signal) => {
const log: string = await fs.readFile(outputPath, 'utf-8');
if (signal) {
reject(new Error(`Daemon was killed by signal ${signal}: ${log}`));
reject(new Error(`Daemon was killed by signal ${signal}`));
} else if (code) {
reject(new Error(`Daemon exited with code ${code}: ${log}`));
reject(new Error(`Daemon exited with code ${code}`));
} else {
reject(new Error(`Daemon unexpectedly exited: ${log}`));
reject(new Error(`Daemon unexpectedly exited`));
}
});
});
Expand All @@ -165,6 +174,8 @@ async function setUpAutoCache() {

core.info('Launched Magic Nix Cache');
core.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);

log.unwatch();
}

async function notifyAutoCache() {
Expand Down Expand Up @@ -201,13 +212,7 @@ async function tearDownAutoCache() {
throw new Error("magic-nix-cache did not start successfully");
}

const log = new Tail(path.join(daemonDir, 'daemon.log'));
core.debug(`tailing daemon.log...`);
log.on('line', (line) => {
core.debug(`got a log line`);
core.info(line);
});

const log = tailLog(daemonDir);

try {
core.debug(`about to post to localhost`);
Expand Down

0 comments on commit d6ee674

Please sign in to comment.