@codfish/actions 1.1.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/claude.yml +0 -1
- package/AGENT.md +21 -1
- package/README.md +22 -17
- package/SECURITY.md +2 -2
- package/bin/generate-docs.js +2 -2
- package/comment/README.md +5 -5
- package/npm-publish-pr/README.md +8 -8
- package/npm-publish-pr/action.yml +22 -15
- package/package.json +1 -1
- package/setup-node-and-install/README.md +23 -21
- package/setup-node-and-install/action.yml +98 -123
- package/tests/integration/comment/basic.bats +11 -11
- package/tests/integration/npm-pr-version/basic.bats +131 -46
- package/tests/integration/setup-node-and-install/basic.bats +471 -33
|
@@ -17,7 +17,7 @@ teardown() {
|
|
|
17
17
|
# Setup test repo with npm lockfile
|
|
18
18
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
19
19
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/lockfiles/package-lock.json" .
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
# Test enhanced package manager detection
|
|
22
22
|
bash -c '
|
|
23
23
|
if [ -f "./pnpm-lock.yaml" ]; then
|
|
@@ -34,7 +34,7 @@ teardown() {
|
|
|
34
34
|
echo "lockfile-exists=false"
|
|
35
35
|
fi
|
|
36
36
|
' > output.txt
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
assert_output_contains "package-manager=npm" "$(cat output.txt)"
|
|
39
39
|
assert_output_contains "lockfile-exists=true" "$(cat output.txt)"
|
|
40
40
|
}
|
|
@@ -43,7 +43,7 @@ teardown() {
|
|
|
43
43
|
# Setup test repo with pnpm lockfile
|
|
44
44
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
45
45
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/lockfiles/pnpm-lock.yaml" .
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
# Test package manager detection (updated with yarn support)
|
|
48
48
|
bash -c '
|
|
49
49
|
if [ -f "./pnpm-lock.yaml" ]; then
|
|
@@ -60,7 +60,7 @@ teardown() {
|
|
|
60
60
|
echo "lockfile-exists=false"
|
|
61
61
|
fi
|
|
62
62
|
' > output.txt
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
assert_output_contains "package-manager=pnpm" "$(cat output.txt)"
|
|
65
65
|
assert_output_contains "lockfile-exists=true" "$(cat output.txt)"
|
|
66
66
|
}
|
|
@@ -69,7 +69,7 @@ teardown() {
|
|
|
69
69
|
# Setup test repo with .nvmrc
|
|
70
70
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
71
71
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/.nvmrc" .
|
|
72
|
-
|
|
72
|
+
|
|
73
73
|
# Test nvmrc detection
|
|
74
74
|
bash -c '
|
|
75
75
|
if [[ ! -f "./.nvmrc" && -z "$INPUT_NODE_VERSION" ]]; then
|
|
@@ -81,7 +81,7 @@ teardown() {
|
|
|
81
81
|
fi
|
|
82
82
|
fi
|
|
83
83
|
' > output.txt
|
|
84
|
-
|
|
84
|
+
|
|
85
85
|
assert_output_contains "node-version-found=true" "$(cat output.txt)"
|
|
86
86
|
assert_output_contains "nvmrc-version=18.20.0" "$(cat output.txt)"
|
|
87
87
|
}
|
|
@@ -90,7 +90,7 @@ teardown() {
|
|
|
90
90
|
# Setup test repo with yarn lockfile
|
|
91
91
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
92
92
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/lockfiles/yarn.lock" .
|
|
93
|
-
|
|
93
|
+
|
|
94
94
|
# Test yarn detection
|
|
95
95
|
bash -c '
|
|
96
96
|
if [ -f "./pnpm-lock.yaml" ]; then
|
|
@@ -107,31 +107,28 @@ teardown() {
|
|
|
107
107
|
echo "lockfile-exists=false"
|
|
108
108
|
fi
|
|
109
109
|
' > output.txt
|
|
110
|
-
|
|
110
|
+
|
|
111
111
|
assert_output_contains "package-manager=yarn" "$(cat output.txt)"
|
|
112
112
|
assert_output_contains "lockfile-exists=true" "$(cat output.txt)"
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
@test "setup-node-and-install:
|
|
116
|
-
# Setup test repo without .nvmrc or node-version input
|
|
115
|
+
@test "setup-node-and-install: does not fail when no node version specified" {
|
|
116
|
+
# Setup test repo without .nvmrc or .node-version or node-version input
|
|
117
117
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
118
|
-
|
|
119
|
-
#
|
|
118
|
+
|
|
119
|
+
# No failure should occur; action no longer enforces node version presence
|
|
120
120
|
bash -c '
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
' > output.txt 2>&1 || echo "exit-code=$?" >> output.txt
|
|
126
|
-
|
|
127
|
-
assert_output_contains "node-version-missing=true" "$(cat output.txt)"
|
|
121
|
+
echo "validation-passed=true"
|
|
122
|
+
' > output.txt
|
|
123
|
+
|
|
124
|
+
assert_output_contains "validation-passed=true" "$(cat output.txt)"
|
|
128
125
|
}
|
|
129
126
|
|
|
130
127
|
@test "setup-node-and-install: detects .node-version file" {
|
|
131
128
|
# Setup test repo with .node-version
|
|
132
129
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
133
130
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/.node-version" .
|
|
134
|
-
|
|
131
|
+
|
|
135
132
|
# Test .node-version detection
|
|
136
133
|
bash -c '
|
|
137
134
|
if [[ ! -f "./.nvmrc" && ! -f "./.node-version" && -z "$INPUT_NODE_VERSION" ]]; then
|
|
@@ -143,29 +140,52 @@ teardown() {
|
|
|
143
140
|
fi
|
|
144
141
|
fi
|
|
145
142
|
' > output.txt
|
|
146
|
-
|
|
143
|
+
|
|
147
144
|
assert_output_contains "node-version-found=true" "$(cat output.txt)"
|
|
148
145
|
assert_output_contains "node-version-content=20.10.0" "$(cat output.txt)"
|
|
149
146
|
}
|
|
150
147
|
|
|
151
|
-
@test "setup-node-and-install: prioritizes .
|
|
148
|
+
@test "setup-node-and-install: prioritizes .node-version over .nvmrc" {
|
|
152
149
|
# Setup test repo with both files
|
|
153
150
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
154
151
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/.nvmrc" .
|
|
155
152
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/.node-version" .
|
|
156
|
-
|
|
157
|
-
# Test priority logic
|
|
153
|
+
|
|
154
|
+
# Test priority logic (.node-version should win now)
|
|
158
155
|
bash -c '
|
|
159
156
|
if [ -f "./.nvmrc" ] && [ -f "./.node-version" ]; then
|
|
160
|
-
echo "Both files found, .
|
|
161
|
-
echo "nvmrc-version=$(cat .nvmrc)"
|
|
157
|
+
echo "Both files found, .node-version takes priority"
|
|
162
158
|
echo "node-version-file=$(cat .node-version)"
|
|
159
|
+
echo "nvmrc-version=$(cat .nvmrc)"
|
|
163
160
|
fi
|
|
164
161
|
' > output.txt
|
|
165
|
-
|
|
166
|
-
assert_output_contains "Both files found, .
|
|
167
|
-
assert_output_contains "nvmrc-version=18.20.0" "$(cat output.txt)"
|
|
162
|
+
|
|
163
|
+
assert_output_contains "Both files found, .node-version takes priority" "$(cat output.txt)"
|
|
168
164
|
assert_output_contains "node-version-file=20.10.0" "$(cat output.txt)"
|
|
165
|
+
assert_output_contains "nvmrc-version=18.20.0" "$(cat output.txt)"
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@test "setup-node-and-install: detects volta.node in package.json" {
|
|
169
|
+
# Setup test repo with volta.node
|
|
170
|
+
tmp_pkg=$(mktemp)
|
|
171
|
+
cat > "$tmp_pkg" <<'JSON'
|
|
172
|
+
{
|
|
173
|
+
"name": "example",
|
|
174
|
+
"version": "1.0.0",
|
|
175
|
+
"volta": { "node": "24.3.4" }
|
|
176
|
+
}
|
|
177
|
+
JSON
|
|
178
|
+
cp "$tmp_pkg" package.json
|
|
179
|
+
|
|
180
|
+
# Test volta.node detection
|
|
181
|
+
bash -c '
|
|
182
|
+
volta_node=$(jq -r ".volta.node // empty" package.json 2>/dev/null || true)
|
|
183
|
+
if [ -n "$volta_node" ]; then
|
|
184
|
+
echo "volta-node=$volta_node"
|
|
185
|
+
fi
|
|
186
|
+
' > output.txt
|
|
187
|
+
|
|
188
|
+
assert_output_contains "volta-node=24.3.4" "$(cat output.txt)"
|
|
169
189
|
}
|
|
170
190
|
|
|
171
191
|
@test "setup-node-and-install: validates package.json existence" {
|
|
@@ -176,7 +196,7 @@ teardown() {
|
|
|
176
196
|
exit 1
|
|
177
197
|
fi
|
|
178
198
|
' > output.txt 2>&1 || echo "exit-code=$?" >> output.txt
|
|
179
|
-
|
|
199
|
+
|
|
180
200
|
assert_output_contains "ERROR: package.json not found" "$(cat output.txt)"
|
|
181
201
|
}
|
|
182
202
|
|
|
@@ -184,7 +204,7 @@ teardown() {
|
|
|
184
204
|
# Setup test repo with empty .node-version
|
|
185
205
|
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
186
206
|
touch .node-version # Create empty file
|
|
187
|
-
|
|
207
|
+
|
|
188
208
|
# Test empty .node-version validation
|
|
189
209
|
bash -c '
|
|
190
210
|
if [ -f "./.node-version" ] && [ ! -f "./.nvmrc" ]; then
|
|
@@ -195,6 +215,424 @@ teardown() {
|
|
|
195
215
|
fi
|
|
196
216
|
fi
|
|
197
217
|
' > output.txt 2>&1 || echo "exit-code=$?" >> output.txt
|
|
198
|
-
|
|
218
|
+
|
|
199
219
|
assert_output_contains "ERROR: .node-version file is empty" "$(cat output.txt)"
|
|
200
|
-
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
@test "setup-node-and-install: cache-hit output defaults to false" {
|
|
223
|
+
# Test that cache-hit output defaults to false when setup-node cache miss
|
|
224
|
+
bash -c '
|
|
225
|
+
# Simulate setup-node cache miss
|
|
226
|
+
setup_node_cache_hit="false"
|
|
227
|
+
|
|
228
|
+
# Simulate the simplified output logic from action.yml
|
|
229
|
+
if [ "$setup_node_cache_hit" = "true" ]; then
|
|
230
|
+
cache_hit="true"
|
|
231
|
+
else
|
|
232
|
+
cache_hit="false"
|
|
233
|
+
fi
|
|
234
|
+
echo "cache-hit=$cache_hit"
|
|
235
|
+
' > output.txt
|
|
236
|
+
|
|
237
|
+
assert_output_contains "cache-hit=false" "$(cat output.txt)"
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
@test "setup-node-and-install: cache-hit output true when setup-node has cache hit" {
|
|
241
|
+
# Test cache-hit output when setup-node step has cache hit
|
|
242
|
+
bash -c '
|
|
243
|
+
# Simulate setup-node cache hit
|
|
244
|
+
setup_node_cache_hit="true"
|
|
245
|
+
|
|
246
|
+
# Simulate the simplified output logic from action.yml
|
|
247
|
+
if [ "$setup_node_cache_hit" = "true" ]; then
|
|
248
|
+
cache_hit="true"
|
|
249
|
+
else
|
|
250
|
+
cache_hit="false"
|
|
251
|
+
fi
|
|
252
|
+
echo "cache-hit=$cache_hit"
|
|
253
|
+
' > output.txt
|
|
254
|
+
|
|
255
|
+
assert_output_contains "cache-hit=true" "$(cat output.txt)"
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
@test "setup-node-and-install: node_modules cache separate from cache-hit output" {
|
|
259
|
+
# Test that node_modules cache doesn't affect the cache-hit output
|
|
260
|
+
bash -c '
|
|
261
|
+
# Simulate setup-node cache miss but node_modules cache hit
|
|
262
|
+
setup_node_cache_hit="false"
|
|
263
|
+
node_modules_cache_hit="true"
|
|
264
|
+
|
|
265
|
+
# cache-hit output only reflects setup-node, not node_modules cache
|
|
266
|
+
if [ "$setup_node_cache_hit" = "true" ]; then
|
|
267
|
+
cache_hit="true"
|
|
268
|
+
else
|
|
269
|
+
cache_hit="false"
|
|
270
|
+
fi
|
|
271
|
+
echo "cache-hit=$cache_hit"
|
|
272
|
+
echo "node-modules-cache-hit=$node_modules_cache_hit"
|
|
273
|
+
echo "note=cache-hit output only reflects setup-node cache"
|
|
274
|
+
' > output.txt
|
|
275
|
+
|
|
276
|
+
assert_output_contains "cache-hit=false" "$(cat output.txt)"
|
|
277
|
+
assert_output_contains "node-modules-cache-hit=true" "$(cat output.txt)"
|
|
278
|
+
assert_output_contains "note=cache-hit output only reflects setup-node cache" "$(cat output.txt)"
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
@test "setup-node-and-install: input node-version overrides all other sources" {
|
|
282
|
+
# Test that input takes highest priority
|
|
283
|
+
tmp_pkg=$(mktemp)
|
|
284
|
+
cat > "$tmp_pkg" <<'JSON'
|
|
285
|
+
{
|
|
286
|
+
"name": "example",
|
|
287
|
+
"version": "1.0.0",
|
|
288
|
+
"volta": { "node": "24.3.4" }
|
|
289
|
+
}
|
|
290
|
+
JSON
|
|
291
|
+
cp "$tmp_pkg" package.json
|
|
292
|
+
echo "18.20.0" > .nvmrc
|
|
293
|
+
echo "20.10.0" > .node-version
|
|
294
|
+
|
|
295
|
+
# Test priority: input > .node-version > .nvmrc > volta.node
|
|
296
|
+
bash -c '
|
|
297
|
+
INPUT_NODE_VERSION="22.1.0"
|
|
298
|
+
resolved_version=""
|
|
299
|
+
|
|
300
|
+
if [ -n "${INPUT_NODE_VERSION}" ]; then
|
|
301
|
+
resolved_version="$INPUT_NODE_VERSION"
|
|
302
|
+
echo "source=input"
|
|
303
|
+
elif [ -f "./.node-version" ]; then
|
|
304
|
+
file_version=$(cat ./.node-version | tr -d "\\n\\r" | xargs)
|
|
305
|
+
if [ -n "$file_version" ]; then
|
|
306
|
+
resolved_version="$file_version"
|
|
307
|
+
echo "source=node-version"
|
|
308
|
+
fi
|
|
309
|
+
elif [ -f "./.nvmrc" ]; then
|
|
310
|
+
nvmrc_version=$(cat ./.nvmrc | tr -d "\\n\\r" | xargs)
|
|
311
|
+
if [ -n "$nvmrc_version" ]; then
|
|
312
|
+
resolved_version="$nvmrc_version"
|
|
313
|
+
echo "source=nvmrc"
|
|
314
|
+
fi
|
|
315
|
+
else
|
|
316
|
+
volta_node=$(jq -r ".volta.node // empty" package.json 2>/dev/null || true)
|
|
317
|
+
if [ -n "$volta_node" ]; then
|
|
318
|
+
resolved_version="$volta_node"
|
|
319
|
+
echo "source=volta"
|
|
320
|
+
fi
|
|
321
|
+
fi
|
|
322
|
+
|
|
323
|
+
echo "resolved-version=$resolved_version"
|
|
324
|
+
' > output.txt
|
|
325
|
+
|
|
326
|
+
assert_output_contains "source=input" "$(cat output.txt)"
|
|
327
|
+
assert_output_contains "resolved-version=22.1.0" "$(cat output.txt)"
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
@test "setup-node-and-install: node-version overrides nvmrc and volta" {
|
|
331
|
+
# Test .node-version priority when no input
|
|
332
|
+
tmp_pkg=$(mktemp)
|
|
333
|
+
cat > "$tmp_pkg" <<'JSON'
|
|
334
|
+
{
|
|
335
|
+
"name": "example",
|
|
336
|
+
"version": "1.0.0",
|
|
337
|
+
"volta": { "node": "24.3.4" }
|
|
338
|
+
}
|
|
339
|
+
JSON
|
|
340
|
+
cp "$tmp_pkg" package.json
|
|
341
|
+
echo "18.20.0" > .nvmrc
|
|
342
|
+
echo "20.10.0" > .node-version
|
|
343
|
+
|
|
344
|
+
# Test without input
|
|
345
|
+
bash -c '
|
|
346
|
+
INPUT_NODE_VERSION=""
|
|
347
|
+
resolved_version=""
|
|
348
|
+
|
|
349
|
+
if [ -n "${INPUT_NODE_VERSION}" ]; then
|
|
350
|
+
resolved_version="$INPUT_NODE_VERSION"
|
|
351
|
+
echo "source=input"
|
|
352
|
+
elif [ -f "./.node-version" ]; then
|
|
353
|
+
file_version=$(cat ./.node-version | tr -d "\\n\\r" | xargs)
|
|
354
|
+
if [ -n "$file_version" ]; then
|
|
355
|
+
resolved_version="$file_version"
|
|
356
|
+
echo "source=node-version"
|
|
357
|
+
fi
|
|
358
|
+
elif [ -f "./.nvmrc" ]; then
|
|
359
|
+
nvmrc_version=$(cat ./.nvmrc | tr -d "\\n\\r" | xargs)
|
|
360
|
+
if [ -n "$nvmrc_version" ]; then
|
|
361
|
+
resolved_version="$nvmrc_version"
|
|
362
|
+
echo "source=nvmrc"
|
|
363
|
+
fi
|
|
364
|
+
else
|
|
365
|
+
volta_node=$(jq -r ".volta.node // empty" package.json 2>/dev/null || true)
|
|
366
|
+
if [ -n "$volta_node" ]; then
|
|
367
|
+
resolved_version="$volta_node"
|
|
368
|
+
echo "source=volta"
|
|
369
|
+
fi
|
|
370
|
+
fi
|
|
371
|
+
|
|
372
|
+
echo "resolved-version=$resolved_version"
|
|
373
|
+
' > output.txt
|
|
374
|
+
|
|
375
|
+
assert_output_contains "source=node-version" "$(cat output.txt)"
|
|
376
|
+
assert_output_contains "resolved-version=20.10.0" "$(cat output.txt)"
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
@test "setup-node-and-install: nvmrc overrides volta when no node-version" {
|
|
380
|
+
# Test .nvmrc priority when no input or .node-version
|
|
381
|
+
tmp_pkg=$(mktemp)
|
|
382
|
+
cat > "$tmp_pkg" <<'JSON'
|
|
383
|
+
{
|
|
384
|
+
"name": "example",
|
|
385
|
+
"version": "1.0.0",
|
|
386
|
+
"volta": { "node": "24.3.4" }
|
|
387
|
+
}
|
|
388
|
+
JSON
|
|
389
|
+
cp "$tmp_pkg" package.json
|
|
390
|
+
echo "18.20.0" > .nvmrc
|
|
391
|
+
# No .node-version file
|
|
392
|
+
|
|
393
|
+
bash -c '
|
|
394
|
+
INPUT_NODE_VERSION=""
|
|
395
|
+
resolved_version=""
|
|
396
|
+
|
|
397
|
+
if [ -n "${INPUT_NODE_VERSION}" ]; then
|
|
398
|
+
resolved_version="$INPUT_NODE_VERSION"
|
|
399
|
+
echo "source=input"
|
|
400
|
+
elif [ -f "./.node-version" ]; then
|
|
401
|
+
file_version=$(cat ./.node-version | tr -d "\\n\\r" | xargs)
|
|
402
|
+
if [ -n "$file_version" ]; then
|
|
403
|
+
resolved_version="$file_version"
|
|
404
|
+
echo "source=node-version"
|
|
405
|
+
fi
|
|
406
|
+
elif [ -f "./.nvmrc" ]; then
|
|
407
|
+
nvmrc_version=$(cat ./.nvmrc | tr -d "\\n\\r" | xargs)
|
|
408
|
+
if [ -n "$nvmrc_version" ]; then
|
|
409
|
+
resolved_version="$nvmrc_version"
|
|
410
|
+
echo "source=nvmrc"
|
|
411
|
+
fi
|
|
412
|
+
else
|
|
413
|
+
volta_node=$(jq -r ".volta.node // empty" package.json 2>/dev/null || true)
|
|
414
|
+
if [ -n "$volta_node" ]; then
|
|
415
|
+
resolved_version="$volta_node"
|
|
416
|
+
echo "source=volta"
|
|
417
|
+
fi
|
|
418
|
+
fi
|
|
419
|
+
|
|
420
|
+
echo "resolved-version=$resolved_version"
|
|
421
|
+
' > output.txt
|
|
422
|
+
|
|
423
|
+
assert_output_contains "source=nvmrc" "$(cat output.txt)"
|
|
424
|
+
assert_output_contains "resolved-version=18.20.0" "$(cat output.txt)"
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
@test "setup-node-and-install: volta used as last resort" {
|
|
428
|
+
# Test volta.node as fallback when no other sources
|
|
429
|
+
tmp_pkg=$(mktemp)
|
|
430
|
+
cat > "$tmp_pkg" <<'JSON'
|
|
431
|
+
{
|
|
432
|
+
"name": "example",
|
|
433
|
+
"version": "1.0.0",
|
|
434
|
+
"volta": { "node": "24.3.4" }
|
|
435
|
+
}
|
|
436
|
+
JSON
|
|
437
|
+
cp "$tmp_pkg" package.json
|
|
438
|
+
# No .nvmrc or .node-version files
|
|
439
|
+
|
|
440
|
+
bash -c '
|
|
441
|
+
INPUT_NODE_VERSION=""
|
|
442
|
+
resolved_version=""
|
|
443
|
+
|
|
444
|
+
if [ -n "${INPUT_NODE_VERSION}" ]; then
|
|
445
|
+
resolved_version="$INPUT_NODE_VERSION"
|
|
446
|
+
echo "source=input"
|
|
447
|
+
elif [ -f "./.node-version" ]; then
|
|
448
|
+
file_version=$(cat ./.node-version | tr -d "\\n\\r" | xargs)
|
|
449
|
+
if [ -n "$file_version" ]; then
|
|
450
|
+
resolved_version="$file_version"
|
|
451
|
+
echo "source=node-version"
|
|
452
|
+
fi
|
|
453
|
+
elif [ -f "./.nvmrc" ]; then
|
|
454
|
+
nvmrc_version=$(cat ./.nvmrc | tr -d "\\n\\r" | xargs)
|
|
455
|
+
if [ -n "$nvmrc_version" ]; then
|
|
456
|
+
resolved_version="$nvmrc_version"
|
|
457
|
+
echo "source=nvmrc"
|
|
458
|
+
fi
|
|
459
|
+
else
|
|
460
|
+
volta_node=$(jq -r ".volta.node // empty" package.json 2>/dev/null || true)
|
|
461
|
+
if [ -n "$volta_node" ]; then
|
|
462
|
+
resolved_version="$volta_node"
|
|
463
|
+
echo "source=volta"
|
|
464
|
+
fi
|
|
465
|
+
fi
|
|
466
|
+
|
|
467
|
+
echo "resolved-version=$resolved_version"
|
|
468
|
+
if [ -z "$resolved_version" ]; then
|
|
469
|
+
echo "no-version-found=true"
|
|
470
|
+
fi
|
|
471
|
+
' > output.txt
|
|
472
|
+
|
|
473
|
+
assert_output_contains "source=volta" "$(cat output.txt)"
|
|
474
|
+
assert_output_contains "resolved-version=24.3.4" "$(cat output.txt)"
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
@test "setup-node-and-install: no node version found scenario" {
|
|
478
|
+
# Test behavior when no node version source is available
|
|
479
|
+
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
480
|
+
# No version files or volta config
|
|
481
|
+
|
|
482
|
+
bash -c '
|
|
483
|
+
INPUT_NODE_VERSION=""
|
|
484
|
+
resolved_version=""
|
|
485
|
+
|
|
486
|
+
if [ -n "${INPUT_NODE_VERSION}" ]; then
|
|
487
|
+
resolved_version="$INPUT_NODE_VERSION"
|
|
488
|
+
echo "source=input"
|
|
489
|
+
elif [ -f "./.node-version" ]; then
|
|
490
|
+
file_version=$(cat ./.node-version | tr -d "\\n\\r" | xargs)
|
|
491
|
+
if [ -n "$file_version" ]; then
|
|
492
|
+
resolved_version="$file_version"
|
|
493
|
+
echo "source=node-version"
|
|
494
|
+
fi
|
|
495
|
+
elif [ -f "./.nvmrc" ]; then
|
|
496
|
+
nvmrc_version=$(cat ./.nvmrc | tr -d "\\n\\r" | xargs)
|
|
497
|
+
if [ -n "$nvmrc_version" ]; then
|
|
498
|
+
resolved_version="$nvmrc_version"
|
|
499
|
+
echo "source=nvmrc"
|
|
500
|
+
fi
|
|
501
|
+
else
|
|
502
|
+
volta_node=$(jq -r ".volta.node // empty" package.json 2>/dev/null || true)
|
|
503
|
+
if [ -n "$volta_node" ]; then
|
|
504
|
+
resolved_version="$volta_node"
|
|
505
|
+
echo "source=volta"
|
|
506
|
+
fi
|
|
507
|
+
fi
|
|
508
|
+
|
|
509
|
+
echo "resolved-version=$resolved_version"
|
|
510
|
+
if [ -z "$resolved_version" ]; then
|
|
511
|
+
echo "no-version-found=true"
|
|
512
|
+
fi
|
|
513
|
+
' > output.txt
|
|
514
|
+
|
|
515
|
+
assert_output_contains "no-version-found=true" "$(cat output.txt)"
|
|
516
|
+
assert_output_contains "resolved-version=" "$(cat output.txt)"
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
@test "setup-node-and-install: install commands run on node_modules cache miss" {
|
|
520
|
+
# Test that install steps run when node_modules cache is missed
|
|
521
|
+
bash -c '
|
|
522
|
+
package_manager="npm"
|
|
523
|
+
lockfile_exists="true"
|
|
524
|
+
node_modules_cache_hit="false"
|
|
525
|
+
|
|
526
|
+
# Simulate the conditional logic from action.yml
|
|
527
|
+
should_install="false"
|
|
528
|
+
if [ "$package_manager" = "npm" ] && [ "$node_modules_cache_hit" != "true" ]; then
|
|
529
|
+
should_install="true"
|
|
530
|
+
echo "npm-install=will-run"
|
|
531
|
+
fi
|
|
532
|
+
|
|
533
|
+
if [ "$package_manager" = "yarn" ] && [ "$node_modules_cache_hit" != "true" ]; then
|
|
534
|
+
should_install="true"
|
|
535
|
+
echo "yarn-install=will-run"
|
|
536
|
+
fi
|
|
537
|
+
|
|
538
|
+
if [ "$package_manager" = "pnpm" ] && [ "$node_modules_cache_hit" != "true" ]; then
|
|
539
|
+
should_install="true"
|
|
540
|
+
echo "pnpm-install=will-run"
|
|
541
|
+
fi
|
|
542
|
+
|
|
543
|
+
echo "cache-hit=$node_modules_cache_hit"
|
|
544
|
+
echo "should-install=$should_install"
|
|
545
|
+
' > output.txt
|
|
546
|
+
|
|
547
|
+
assert_output_contains "npm-install=will-run" "$(cat output.txt)"
|
|
548
|
+
assert_output_contains "cache-hit=false" "$(cat output.txt)"
|
|
549
|
+
assert_output_contains "should-install=true" "$(cat output.txt)"
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
@test "setup-node-and-install: install commands skip on node_modules cache hit" {
|
|
553
|
+
# Test that install steps are skipped when node_modules cache is hit
|
|
554
|
+
bash -c '
|
|
555
|
+
package_manager="pnpm"
|
|
556
|
+
lockfile_exists="true"
|
|
557
|
+
node_modules_cache_hit="true"
|
|
558
|
+
|
|
559
|
+
# Simulate the conditional logic from action.yml
|
|
560
|
+
should_install="false"
|
|
561
|
+
if [ "$package_manager" = "npm" ] && [ "$node_modules_cache_hit" != "true" ]; then
|
|
562
|
+
should_install="true"
|
|
563
|
+
echo "npm-install=will-run"
|
|
564
|
+
fi
|
|
565
|
+
|
|
566
|
+
if [ "$package_manager" = "yarn" ] && [ "$node_modules_cache_hit" != "true" ]; then
|
|
567
|
+
should_install="true"
|
|
568
|
+
echo "yarn-install=will-run"
|
|
569
|
+
fi
|
|
570
|
+
|
|
571
|
+
if [ "$package_manager" = "pnpm" ] && [ "$node_modules_cache_hit" != "true" ]; then
|
|
572
|
+
should_install="true"
|
|
573
|
+
echo "pnpm-install=will-run"
|
|
574
|
+
fi
|
|
575
|
+
|
|
576
|
+
if [ "$should_install" = "false" ]; then
|
|
577
|
+
echo "install-skipped=cache-hit"
|
|
578
|
+
fi
|
|
579
|
+
|
|
580
|
+
echo "cache-hit=$node_modules_cache_hit"
|
|
581
|
+
echo "should-install=$should_install"
|
|
582
|
+
' > output.txt
|
|
583
|
+
|
|
584
|
+
assert_output_contains "install-skipped=cache-hit" "$(cat output.txt)"
|
|
585
|
+
assert_output_contains "cache-hit=true" "$(cat output.txt)"
|
|
586
|
+
assert_output_contains "should-install=false" "$(cat output.txt)"
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
@test "setup-node-and-install: conditional install works for all package managers" {
|
|
590
|
+
# Test that all package managers respect the cache condition
|
|
591
|
+
bash -c '
|
|
592
|
+
node_modules_cache_hit="false"
|
|
593
|
+
|
|
594
|
+
# Test each package manager
|
|
595
|
+
for pm in npm yarn pnpm; do
|
|
596
|
+
should_install="false"
|
|
597
|
+
if [ "$pm" = "npm" ] && [ "$node_modules_cache_hit" != "true" ]; then
|
|
598
|
+
should_install="true"
|
|
599
|
+
elif [ "$pm" = "yarn" ] && [ "$node_modules_cache_hit" != "true" ]; then
|
|
600
|
+
should_install="true"
|
|
601
|
+
elif [ "$pm" = "pnpm" ] && [ "$node_modules_cache_hit" != "true" ]; then
|
|
602
|
+
should_install="true"
|
|
603
|
+
fi
|
|
604
|
+
echo "$pm-will-install=$should_install"
|
|
605
|
+
done
|
|
606
|
+
|
|
607
|
+
echo "cache-miss-scenario=all-managers-will-install"
|
|
608
|
+
' > output.txt
|
|
609
|
+
|
|
610
|
+
assert_output_contains "npm-will-install=true" "$(cat output.txt)"
|
|
611
|
+
assert_output_contains "yarn-will-install=true" "$(cat output.txt)"
|
|
612
|
+
assert_output_contains "pnpm-will-install=true" "$(cat output.txt)"
|
|
613
|
+
assert_output_contains "cache-miss-scenario=all-managers-will-install" "$(cat output.txt)"
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
@test "setup-node-and-install: node_modules cache only applies with lockfile" {
|
|
617
|
+
# Test that node_modules cache is only used when lockfile exists
|
|
618
|
+
bash -c '
|
|
619
|
+
lockfile_exists_with_lock="true"
|
|
620
|
+
lockfile_exists_without_lock="false"
|
|
621
|
+
|
|
622
|
+
# Simulate cache step condition: if lockfile exists
|
|
623
|
+
if [ "$lockfile_exists_with_lock" = "true" ]; then
|
|
624
|
+
echo "node-modules-cache=enabled"
|
|
625
|
+
else
|
|
626
|
+
echo "node-modules-cache=disabled"
|
|
627
|
+
fi
|
|
628
|
+
|
|
629
|
+
if [ "$lockfile_exists_without_lock" = "true" ]; then
|
|
630
|
+
echo "no-lockfile-cache=enabled"
|
|
631
|
+
else
|
|
632
|
+
echo "no-lockfile-cache=disabled"
|
|
633
|
+
fi
|
|
634
|
+
' > output.txt
|
|
635
|
+
|
|
636
|
+
assert_output_contains "node-modules-cache=enabled" "$(cat output.txt)"
|
|
637
|
+
assert_output_contains "no-lockfile-cache=disabled" "$(cat output.txt)"
|
|
638
|
+
}
|