Skip to content

Commit

Permalink
Merge pull request #183 from cachix/fix-179
Browse files Browse the repository at this point in the history
store-scan: improve error handling when listing the store fails
  • Loading branch information
domenkozar authored May 8, 2024
2 parents 991af99 + 662a883 commit 132bc97
Show file tree
Hide file tree
Showing 3 changed files with 27 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
17 changes: 14 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 @@ -12,10 +12,21 @@ filterPaths() {
done | xargs
}

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

if [[ -n $pushFilter ]]; then
pathsToPush=$(filterPaths $pushFilter "$pathsToPush")
pathsToPush=$(filterPaths $pushFilter "$pathsToPush")
fi

echo "$pathsToPush" | "$cachix" push $cachixArgs "$cache"
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 132bc97

Please sign in to comment.