@codfish/actions 2.0.0 → 3.3.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/README.md +135 -64
- package/bin/generate-docs.js +10 -10
- package/comment/README.md +9 -9
- package/comment/action.yml +3 -3
- package/npm-publish-pr/README.md +319 -40
- package/npm-publish-pr/action.yml +271 -87
- package/package.json +19 -14
- package/setup-node-and-install/README.md +77 -34
- package/setup-node-and-install/action.yml +40 -5
- package/.github/codeql-config.yml +0 -21
- package/.github/dependabot.yml +0 -35
- package/.github/workflows/claude-code-review.yml +0 -43
- package/.github/workflows/claude.yml +0 -38
- package/.github/workflows/release.yml +0 -48
- package/.github/workflows/security.yml +0 -103
- package/.github/workflows/update-docs.yml +0 -38
- package/.github/workflows/validate.yml +0 -210
- package/.husky/pre-commit +0 -1
- package/.nvmrc +0 -1
- package/AGENT.md +0 -149
- package/CLAUDE.md +0 -3
- package/CONTRIBUTING.md +0 -316
- package/SECURITY.md +0 -208
- package/eslint.config.js +0 -8
- package/tests/fixtures/.node-version +0 -1
- package/tests/fixtures/.nvmrc +0 -1
- package/tests/fixtures/lockfiles/package-lock.json +0 -12
- package/tests/fixtures/lockfiles/pnpm-lock.yaml +0 -9
- package/tests/fixtures/lockfiles/yarn.lock +0 -7
- package/tests/fixtures/package-json/minimal.json +0 -4
- package/tests/fixtures/package-json/scoped.json +0 -6
- package/tests/fixtures/package-json/valid.json +0 -13
- package/tests/integration/comment/basic.bats +0 -95
- package/tests/integration/npm-pr-version/basic.bats +0 -438
- package/tests/integration/setup-node-and-install/basic.bats +0 -638
- package/tests/scripts/test-helpers.sh +0 -113
- package/tests/scripts/test-runner.sh +0 -115
|
@@ -1,638 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bats
|
|
2
|
-
|
|
3
|
-
load "../../scripts/test-helpers.sh"
|
|
4
|
-
|
|
5
|
-
setup() {
|
|
6
|
-
setup_github_env
|
|
7
|
-
TEST_DIR=$(mktemp -d)
|
|
8
|
-
cd "$TEST_DIR"
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
teardown() {
|
|
12
|
-
cd /
|
|
13
|
-
cleanup_test_env "$TEST_DIR"
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
@test "setup-node-and-install: detects npm with package-lock.json" {
|
|
17
|
-
# Setup test repo with npm lockfile
|
|
18
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
19
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/lockfiles/package-lock.json" .
|
|
20
|
-
|
|
21
|
-
# Test enhanced package manager detection
|
|
22
|
-
bash -c '
|
|
23
|
-
if [ -f "./pnpm-lock.yaml" ]; then
|
|
24
|
-
echo "package-manager=pnpm"
|
|
25
|
-
echo "lockfile-exists=true"
|
|
26
|
-
elif [ -f "./yarn.lock" ]; then
|
|
27
|
-
echo "package-manager=yarn"
|
|
28
|
-
echo "lockfile-exists=true"
|
|
29
|
-
elif [ -f "./package-lock.json" ]; then
|
|
30
|
-
echo "package-manager=npm"
|
|
31
|
-
echo "lockfile-exists=true"
|
|
32
|
-
else
|
|
33
|
-
echo "package-manager=npm"
|
|
34
|
-
echo "lockfile-exists=false"
|
|
35
|
-
fi
|
|
36
|
-
' > output.txt
|
|
37
|
-
|
|
38
|
-
assert_output_contains "package-manager=npm" "$(cat output.txt)"
|
|
39
|
-
assert_output_contains "lockfile-exists=true" "$(cat output.txt)"
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@test "setup-node-and-install: detects pnpm with pnpm-lock.yaml" {
|
|
43
|
-
# Setup test repo with pnpm lockfile
|
|
44
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
45
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/lockfiles/pnpm-lock.yaml" .
|
|
46
|
-
|
|
47
|
-
# Test package manager detection (updated with yarn support)
|
|
48
|
-
bash -c '
|
|
49
|
-
if [ -f "./pnpm-lock.yaml" ]; then
|
|
50
|
-
echo "package-manager=pnpm"
|
|
51
|
-
echo "lockfile-exists=true"
|
|
52
|
-
elif [ -f "./yarn.lock" ]; then
|
|
53
|
-
echo "package-manager=yarn"
|
|
54
|
-
echo "lockfile-exists=true"
|
|
55
|
-
elif [ -f "./package-lock.json" ]; then
|
|
56
|
-
echo "package-manager=npm"
|
|
57
|
-
echo "lockfile-exists=true"
|
|
58
|
-
else
|
|
59
|
-
echo "package-manager=npm"
|
|
60
|
-
echo "lockfile-exists=false"
|
|
61
|
-
fi
|
|
62
|
-
' > output.txt
|
|
63
|
-
|
|
64
|
-
assert_output_contains "package-manager=pnpm" "$(cat output.txt)"
|
|
65
|
-
assert_output_contains "lockfile-exists=true" "$(cat output.txt)"
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
@test "setup-node-and-install: detects .nvmrc file" {
|
|
69
|
-
# Setup test repo with .nvmrc
|
|
70
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
71
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/.nvmrc" .
|
|
72
|
-
|
|
73
|
-
# Test nvmrc detection
|
|
74
|
-
bash -c '
|
|
75
|
-
if [[ ! -f "./.nvmrc" && -z "$INPUT_NODE_VERSION" ]]; then
|
|
76
|
-
echo "node-version-missing=true"
|
|
77
|
-
else
|
|
78
|
-
echo "node-version-found=true"
|
|
79
|
-
if [ -f "./.nvmrc" ]; then
|
|
80
|
-
echo "nvmrc-version=$(cat .nvmrc)"
|
|
81
|
-
fi
|
|
82
|
-
fi
|
|
83
|
-
' > output.txt
|
|
84
|
-
|
|
85
|
-
assert_output_contains "node-version-found=true" "$(cat output.txt)"
|
|
86
|
-
assert_output_contains "nvmrc-version=18.20.0" "$(cat output.txt)"
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
@test "setup-node-and-install: detects yarn with yarn.lock" {
|
|
90
|
-
# Setup test repo with yarn lockfile
|
|
91
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
92
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/lockfiles/yarn.lock" .
|
|
93
|
-
|
|
94
|
-
# Test yarn detection
|
|
95
|
-
bash -c '
|
|
96
|
-
if [ -f "./pnpm-lock.yaml" ]; then
|
|
97
|
-
echo "package-manager=pnpm"
|
|
98
|
-
echo "lockfile-exists=true"
|
|
99
|
-
elif [ -f "./yarn.lock" ]; then
|
|
100
|
-
echo "package-manager=yarn"
|
|
101
|
-
echo "lockfile-exists=true"
|
|
102
|
-
elif [ -f "./package-lock.json" ]; then
|
|
103
|
-
echo "package-manager=npm"
|
|
104
|
-
echo "lockfile-exists=true"
|
|
105
|
-
else
|
|
106
|
-
echo "package-manager=npm"
|
|
107
|
-
echo "lockfile-exists=false"
|
|
108
|
-
fi
|
|
109
|
-
' > output.txt
|
|
110
|
-
|
|
111
|
-
assert_output_contains "package-manager=yarn" "$(cat output.txt)"
|
|
112
|
-
assert_output_contains "lockfile-exists=true" "$(cat output.txt)"
|
|
113
|
-
}
|
|
114
|
-
|
|
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
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
118
|
-
|
|
119
|
-
# No failure should occur; action no longer enforces node version presence
|
|
120
|
-
bash -c '
|
|
121
|
-
echo "validation-passed=true"
|
|
122
|
-
' > output.txt
|
|
123
|
-
|
|
124
|
-
assert_output_contains "validation-passed=true" "$(cat output.txt)"
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
@test "setup-node-and-install: detects .node-version file" {
|
|
128
|
-
# Setup test repo with .node-version
|
|
129
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
130
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/.node-version" .
|
|
131
|
-
|
|
132
|
-
# Test .node-version detection
|
|
133
|
-
bash -c '
|
|
134
|
-
if [[ ! -f "./.nvmrc" && ! -f "./.node-version" && -z "$INPUT_NODE_VERSION" ]]; then
|
|
135
|
-
echo "node-version-missing=true"
|
|
136
|
-
else
|
|
137
|
-
echo "node-version-found=true"
|
|
138
|
-
if [ -f "./.node-version" ]; then
|
|
139
|
-
echo "node-version-content=$(cat .node-version)"
|
|
140
|
-
fi
|
|
141
|
-
fi
|
|
142
|
-
' > output.txt
|
|
143
|
-
|
|
144
|
-
assert_output_contains "node-version-found=true" "$(cat output.txt)"
|
|
145
|
-
assert_output_contains "node-version-content=20.10.0" "$(cat output.txt)"
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
@test "setup-node-and-install: prioritizes .node-version over .nvmrc" {
|
|
149
|
-
# Setup test repo with both files
|
|
150
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
151
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/.nvmrc" .
|
|
152
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/.node-version" .
|
|
153
|
-
|
|
154
|
-
# Test priority logic (.node-version should win now)
|
|
155
|
-
bash -c '
|
|
156
|
-
if [ -f "./.nvmrc" ] && [ -f "./.node-version" ]; then
|
|
157
|
-
echo "Both files found, .node-version takes priority"
|
|
158
|
-
echo "node-version-file=$(cat .node-version)"
|
|
159
|
-
echo "nvmrc-version=$(cat .nvmrc)"
|
|
160
|
-
fi
|
|
161
|
-
' > output.txt
|
|
162
|
-
|
|
163
|
-
assert_output_contains "Both files found, .node-version takes priority" "$(cat output.txt)"
|
|
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)"
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
@test "setup-node-and-install: validates package.json existence" {
|
|
192
|
-
# Test without package.json
|
|
193
|
-
bash -c '
|
|
194
|
-
if [ ! -f "./package.json" ]; then
|
|
195
|
-
echo "ERROR: package.json not found"
|
|
196
|
-
exit 1
|
|
197
|
-
fi
|
|
198
|
-
' > output.txt 2>&1 || echo "exit-code=$?" >> output.txt
|
|
199
|
-
|
|
200
|
-
assert_output_contains "ERROR: package.json not found" "$(cat output.txt)"
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
@test "setup-node-and-install: validates empty .node-version file" {
|
|
204
|
-
# Setup test repo with empty .node-version
|
|
205
|
-
cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
|
|
206
|
-
touch .node-version # Create empty file
|
|
207
|
-
|
|
208
|
-
# Test empty .node-version validation
|
|
209
|
-
bash -c '
|
|
210
|
-
if [ -f "./.node-version" ] && [ ! -f "./.nvmrc" ]; then
|
|
211
|
-
node_version_file=$(cat .node-version | tr -d "\n\r" | xargs)
|
|
212
|
-
if [ -z "$node_version_file" ]; then
|
|
213
|
-
echo "ERROR: .node-version file is empty"
|
|
214
|
-
exit 1
|
|
215
|
-
fi
|
|
216
|
-
fi
|
|
217
|
-
' > output.txt 2>&1 || echo "exit-code=$?" >> output.txt
|
|
218
|
-
|
|
219
|
-
assert_output_contains "ERROR: .node-version file is empty" "$(cat output.txt)"
|
|
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
|
-
}
|