Skip to content

Commit

Permalink
store-scan: use runner or os temp dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
sandydoo committed May 7, 2024
1 parent 08dcf70 commit 662a883
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
9 changes: 6 additions & 3 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7842,9 +7842,9 @@ async function setup() {
}
}
core.saveState('pushMode', pushMode);
const tmpdir = process.env['RUNNER_TEMP'] ?? os.tmpdir();
switch (pushMode) {
case PushMode.Daemon: {
const tmpdir = process.env['RUNNER_TEMP'] ?? os.tmpdir();
const daemonDir = await fs.mkdtemp(path.join(tmpdir, 'cachix-daemon-'));
const daemonLog = (0, node_fs_1.openSync)(`${daemonDir}/daemon.log`, 'a');
const daemon = (0, node_child_process_1.spawn)(cachixBin, [
Expand Down Expand Up @@ -7877,7 +7877,9 @@ async function setup() {
}
case PushMode.StoreScan: {
// Remember existing store paths
await exec.exec("sh", ["-c", `${__dirname}/list-nix-store.sh > /tmp/store-path-pre-build`]);
const preBuildPathsFile = `${tmpdir}/store-path-pre-build`;
core.saveState('preBuildPathsFile', preBuildPathsFile);
await exec.exec("sh", ["-c", `${__dirname}/list-nix-store.sh > ${preBuildPathsFile}`]);
break;
}
default:
Expand Down Expand Up @@ -7930,7 +7932,8 @@ async function upload() {
break;
}
case PushMode.StoreScan: {
await exec.exec(`${__dirname}/push-paths.sh`, [cachixBin, cachixArgs, name, pushFilter]);
const preBuildPathsFile = core.getState('preBuildPathsFile');
await exec.exec(`${__dirname}/push-paths.sh`, [cachixBin, cachixArgs, name, preBuildPathsFile, pushFilter]);
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions dist/main/push-paths.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail

cachix=$1 cachixArgs=${2:--j8} cache=$3 pushFilter=$4
cachix=$1 cachixArgs=${2:--j8} cache=$3 preBuildPathsFile=$4 pushFilter=$5

filterPaths() {
local regex=$1
Expand All @@ -13,7 +13,7 @@ filterPaths() {
}

pathsToPush=""
preBuildPaths=$(sort /tmp/store-path-pre-build)
preBuildPaths=$(sort "$preBuildPathsFile")
if [ $? -eq 0 ]; then
postBuildPaths=$("$(dirname "$0")"/list-nix-store.sh | sort)
if [ $? -eq 0 ]; then
Expand All @@ -22,7 +22,7 @@ if [ $? -eq 0 ]; then
echo "::error::Failed to list post-build store paths."
fi
else
echo "::error::Failed to find pre-build store paths."
printf "::error::Failed to find pre-build store paths. Expected cached paths in %s\n" "$preBuildPathsFile"
fi

if [[ -n $pushFilter ]]; then
Expand Down
10 changes: 7 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ async function setup() {

core.saveState('pushMode', pushMode);

const tmpdir = process.env['RUNNER_TEMP'] ?? os.tmpdir();

switch (pushMode) {
case PushMode.Daemon: {
const tmpdir = process.env['RUNNER_TEMP'] ?? os.tmpdir();
const daemonDir = await fs.mkdtemp(path.join(tmpdir, 'cachix-daemon-'));
const daemonLog = openSync(`${daemonDir}/daemon.log`, 'a');

Expand Down Expand Up @@ -176,7 +177,9 @@ async function setup() {

case PushMode.StoreScan: {
// Remember existing store paths
await exec.exec("sh", ["-c", `${__dirname}/list-nix-store.sh > /tmp/store-path-pre-build`]);
const preBuildPathsFile = `${tmpdir}/store-path-pre-build`;
core.saveState('preBuildPathsFile', preBuildPathsFile);
await exec.exec("sh", ["-c", `${__dirname}/list-nix-store.sh > ${preBuildPathsFile}`]);
break;
}

Expand Down Expand Up @@ -244,7 +247,8 @@ async function upload() {
}

case PushMode.StoreScan: {
await exec.exec(`${__dirname}/push-paths.sh`, [cachixBin, cachixArgs, name, pushFilter]);
const preBuildPathsFile = core.getState('preBuildPathsFile');
await exec.exec(`${__dirname}/push-paths.sh`, [cachixBin, cachixArgs, name, preBuildPathsFile, pushFilter]);
break;
}
}
Expand Down

0 comments on commit 662a883

Please sign in to comment.