Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store-scan: improve error handling when listing the store fails #183

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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