Skip to content

Commit 991af99

Browse files
authored
Skip prep steps if using pathsToPush (#180)
* Skip prep steps if using `pathsToPush` * ci: add a test for pushPaths * Update test.yml * fix * fix * fix
1 parent 74587ee commit 991af99

File tree

4 files changed

+58
-12
lines changed

4 files changed

+58
-12
lines changed

.github/workflows/test.yml

+21
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ jobs:
6969
useDaemon: ${{ matrix.useDaemon }}
7070
- run: nix-build test.nix
7171

72+
push-paths:
73+
strategy:
74+
matrix:
75+
os: [ubuntu-latest, macos-latest]
76+
runs-on: ${{ matrix.os }}
77+
steps:
78+
- uses: actions/checkout@v4
79+
- run: yarn install --frozen-lockfile
80+
- run: yarn build
81+
- uses: cachix/install-nix-action@v26
82+
- id: paths
83+
run: |
84+
paths=$(nix-instantiate test.nix | tr '\n' ' ')
85+
echo "OUT_PATHS=$paths" >> $GITHUB_OUTPUT
86+
- name: Test pushPaths
87+
uses: ./
88+
with:
89+
name: cachix-action
90+
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
91+
pathsToPush: '${{ steps.paths.outputs.OUT_PATHS }}'
92+
7293
installCommand:
7394
strategy:
7495
matrix:

dist/main/index.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -7754,6 +7754,8 @@ var PushMode;
77547754
(function (PushMode) {
77557755
// Disable pushing entirely.
77567756
PushMode["None"] = "None";
7757+
// Push paths provided via the `pathsToPush` input.
7758+
PushMode["PushPaths"] = "PushPaths";
77577759
// Scans the entire store during the pre- and post-hooks and uploads the difference.
77587760
// This is a very simple method and is likely to work in any environment.
77597761
// There are two downsides:
@@ -7821,7 +7823,10 @@ async function setup() {
78217823
// Determine the push mode to use
78227824
let pushMode = PushMode.None;
78237825
if (hasPushTokens && !skipPush) {
7824-
if (useDaemon) {
7826+
if (pathsToPush) {
7827+
pushMode = PushMode.PushPaths;
7828+
}
7829+
else if (useDaemon) {
78257830
let supportsDaemonInterface = (cachixVersion) ? semver_1.default.gte(cachixVersion, '1.7.0') : false;
78267831
let supportsPostBuildHook = await isTrustedUser();
78277832
if (!supportsDaemonInterface) {
@@ -7846,7 +7851,7 @@ async function setup() {
78467851
'daemon', 'run',
78477852
'--socket', `${daemonDir}/daemon.sock`,
78487853
name,
7849-
...cachixArgs.split(' ').filter((arg) => arg !== ''),
7854+
...splitArgs(cachixArgs),
78507855
], {
78517856
stdio: ['ignore', daemonLog, daemonLog],
78527857
detached: true,
@@ -7895,6 +7900,10 @@ async function upload() {
78957900
}
78967901
break;
78977902
}
7903+
case PushMode.PushPaths: {
7904+
await exec.exec(cachixBin, ["push", ...splitArgs(cachixArgs), name, ...splitArgs(pathsToPush)]);
7905+
break;
7906+
}
78987907
case PushMode.Daemon: {
78997908
const daemonDir = process.env[ENV_CACHIX_DAEMON_DIR];
79007909
if (!daemonDir) {
@@ -7921,7 +7930,7 @@ async function upload() {
79217930
break;
79227931
}
79237932
case PushMode.StoreScan: {
7924-
await exec.exec(`${__dirname}/push-paths.sh`, [cachixBin, cachixArgs, name, pathsToPush, pushFilter]);
7933+
await exec.exec(`${__dirname}/push-paths.sh`, [cachixBin, cachixArgs, name, pushFilter]);
79257934
break;
79267935
}
79277936
}
@@ -8074,6 +8083,9 @@ function partitionUsersAndGroups(mixedUsers) {
80748083
});
80758084
return [users, groups];
80768085
}
8086+
function splitArgs(args) {
8087+
return args.split(' ').filter((arg) => arg !== '');
8088+
}
80778089
const isPost = !!core.getState('isPost');
80788090
// Main
80798091
try {

dist/main/push-paths.sh

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

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

66
filterPaths() {
77
local regex=$1
@@ -12,12 +12,10 @@ filterPaths() {
1212
done | xargs
1313
}
1414

15-
if [[ -z $pathsToPush ]]; then
16-
pathsToPush=$(comm -13 <(sort /tmp/store-path-pre-build) <("$(dirname "$0")"/list-nix-store.sh))
15+
pathsToPush=$(comm -13 <(sort /tmp/store-path-pre-build) <("$(dirname "$0")"/list-nix-store.sh))
1716

18-
if [[ -n $pushFilter ]]; then
19-
pathsToPush=$(filterPaths $pushFilter "$pathsToPush")
20-
fi
17+
if [[ -n $pushFilter ]]; then
18+
pathsToPush=$(filterPaths $pushFilter "$pathsToPush")
2119
fi
2220

2321
echo "$pathsToPush" | "$cachix" push $cachixArgs "$cache"

src/main.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const ENV_CACHIX_DAEMON_DIR = 'CACHIX_DAEMON_DIR';
3030
enum PushMode {
3131
// Disable pushing entirely.
3232
None = 'None',
33+
// Push paths provided via the `pathsToPush` input.
34+
PushPaths = 'PushPaths',
3335
// Scans the entire store during the pre- and post-hooks and uploads the difference.
3436
// This is a very simple method and is likely to work in any environment.
3537
// There are two downsides:
@@ -107,7 +109,9 @@ async function setup() {
107109
let pushMode = PushMode.None;
108110

109111
if (hasPushTokens && !skipPush) {
110-
if (useDaemon) {
112+
if (pathsToPush) {
113+
pushMode = PushMode.PushPaths;
114+
} else if (useDaemon) {
111115
let supportsDaemonInterface = (cachixVersion) ? semver.gte(cachixVersion, '1.7.0') : false;
112116
let supportsPostBuildHook = await isTrustedUser();
113117

@@ -138,7 +142,7 @@ async function setup() {
138142
'daemon', 'run',
139143
'--socket', `${daemonDir}/daemon.sock`,
140144
name,
141-
...cachixArgs.split(' ').filter((arg) => arg !== ''),
145+
...splitArgs(cachixArgs),
142146
],
143147
{
144148
stdio: ['ignore', daemonLog, daemonLog],
@@ -169,6 +173,7 @@ async function setup() {
169173

170174
break;
171175
}
176+
172177
case PushMode.StoreScan: {
173178
// Remember existing store paths
174179
await exec.exec("sh", ["-c", `${__dirname}/list-nix-store.sh > /tmp/store-path-pre-build`]);
@@ -200,6 +205,12 @@ async function upload() {
200205

201206
break;
202207
}
208+
209+
case PushMode.PushPaths: {
210+
await exec.exec(cachixBin, ["push", ...splitArgs(cachixArgs), name, ...splitArgs(pathsToPush)]);
211+
break;
212+
}
213+
203214
case PushMode.Daemon: {
204215
const daemonDir = process.env[ENV_CACHIX_DAEMON_DIR];
205216

@@ -233,7 +244,7 @@ async function upload() {
233244
}
234245

235246
case PushMode.StoreScan: {
236-
await exec.exec(`${__dirname}/push-paths.sh`, [cachixBin, cachixArgs, name, pathsToPush, pushFilter]);
247+
await exec.exec(`${__dirname}/push-paths.sh`, [cachixBin, cachixArgs, name, pushFilter]);
237248
break;
238249
}
239250
}
@@ -414,6 +425,10 @@ function partitionUsersAndGroups(mixedUsers: string[]): [string[], string[]] {
414425
return [users, groups];
415426
}
416427

428+
function splitArgs(args: string): string[] {
429+
return args.split(' ').filter((arg) => arg !== '');
430+
}
431+
417432
const isPost = !!core.getState('isPost');
418433

419434
// Main

0 commit comments

Comments
 (0)