Repository navigation
1191 lines (1084 loc) · 38 KB
/
Copy pathtest.yaml
File metadata and controls
1191 lines (1084 loc) · 38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: Test Action
on:
pull_request:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
jobs:
pnpm-commands:
name: 'pnpm command execution (${{ matrix.os }} / pnpm ${{ matrix.version }})'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
version: ['11.22.0', '12.5.1']
steps:
- uses: actions/checkout@v7
- id: pnpm
uses: ./
with:
version: ${{ matrix.version }}
runtime: node@24
- name: Test command execution and reject deprecation warnings
env:
PNPM_TEST_BIN: ${{ steps.pnpm.outputs.bin-dest }}/pnpm${{ runner.os == 'Windows' && '.exe' || '' }}
run: node --throw-deprecation --test src/pnpm-commands.test.mjs src/pnpm-install/lockfile.test.mjs
smoke:
# Direct binary download + pnpm on PATH across OSes and architectures.
name: 'Smoke (${{ matrix.os }} / pnpm ${{ matrix.version }})'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
version: '12.0.0'
- os: ubuntu-24.04-arm
version: '12.0.0'
- os: macos-latest
version: '12.0.0'
- os: windows-latest
version: '12.0.0'
steps:
- uses: actions/checkout@v7
- id: pnpm
uses: ./
with:
version: ${{ matrix.version }}
- name: 'Test: pnpm version on PATH matches request'
env:
BIN_DEST: ${{ steps.pnpm.outputs.bin-dest }}
REQUIRED: ${{ matrix.version }}
run: |
set -e
which pnpm
actual="$(pnpm --version)"
echo "pnpm --version: ${actual}"
if [ "${actual}" != "${REQUIRED}" ]; then
echo "Expected pnpm ${REQUIRED}, got ${actual}"
exit 1
fi
bin_dest_version="$("$BIN_DEST/pnpm" --version)"
if [ "${bin_dest_version}" != "${REQUIRED}" ]; then
echo "Expected ${REQUIRED} via bin_dest, got ${bin_dest_version}"
exit 1
fi
shell: bash
smoke-v11:
# v11's release archive bundles a Node-SEA launcher plus a sibling `dist/`,
# unlike v12's single self-contained binary. Verify the action downloads and
# lays it out correctly and puts pnpm on PATH across OSes/arches. (macos-latest
# is arm64; pnpm v11 ships no Intel-macOS binary, so no macos-13 entry here.)
name: 'Smoke pnpm 11 (${{ matrix.os }})'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v7
- id: pnpm
uses: ./
with:
version: '11.17.0'
install: false
- name: 'Test: pnpm 11 on PATH matches request'
env:
BIN_DEST: ${{ steps.pnpm.outputs.bin-dest }}
run: |
set -e
which pnpm
actual="$(pnpm --version)"
echo "pnpm --version: ${actual}"
if [ "${actual}" != "11.17.0" ]; then
echo "Expected pnpm 11.17.0, got ${actual}"
exit 1
fi
bin_dest_version="$("$BIN_DEST/pnpm" --version)"
if [ "${bin_dest_version}" != "11.17.0" ]; then
echo "Expected 11.17.0 via bin_dest, got ${bin_dest_version}"
exit 1
fi
shell: bash
cache-windows:
# pnpm can report a Windows store path with the extended-length `\\?\`
# prefix. Cache paths must use the regular drive-path form because the
# cache toolkit otherwise interprets `?` as a glob in the root segment.
#
# The pnpm version below is load-bearing, not stale: 12.0.0 reports a
# plain `D:\.pnpm-store\v11` for this store-dir, so only an older
# release still reproduces the prefix this job exists to cover. Do not
# bump it without checking that `pnpm store path` still starts `\\?\`.
name: 'Cache Windows extended-length store path'
runs-on: windows-latest
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- name: Configure store at the drive root
run: Set-Content -Path .npmrc -Value 'store-dir=/.pnpm-store'
- uses: ./
with:
version: '12.0.0-rc.0'
runtime: node@22
cache: true
- name: 'Test: pnpm reports an extended-length store path'
run: |
$storePath = pnpm store path
Write-Host "pnpm store path: $storePath"
if (-not $storePath.StartsWith('\\?\')) {
throw "Expected an extended-length store path, got: $storePath"
}
runtime-cache-prime:
name: 'Prime runtime cache'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: ./
with:
version: '11.22.0'
runtime: node@24.19.0
cache: true
- name: 'Test: moving selector cache keys'
run: pnpm test
runtime-cache-hit:
name: 'Restore runtime cache'
needs: runtime-cache-prime
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
# `pnpm runtime set` always fetches SHASUMS256.txt(.sig) and index.json
# from nodejs.org to verify the runtime, warm store or not, so the job
# cannot prove the restore happened by cutting the network. What it can
# prove is the key scheme: a second run of the same selector must land
# an exact hit on the key the first run saved under the resolved
# version, which only holds if the restore precedes the install.
- id: pnpm
uses: ./
with:
version: '11.22.0'
runtime: node@24.19.0
cache: true
install: false
- name: 'Test: runtime cache was restored'
env:
CACHE_HIT: ${{ steps.pnpm.outputs.cache-hit }}
run: |
set -e
if [ "${CACHE_HIT}" != "true" ]; then
echo "Expected a runtime cache hit, got: ${CACHE_HIT}"
exit 1
fi
actual="$(node --version)"
if [ "${actual}" != "v24.19.0" ]; then
echo "Expected node v24.19.0, got: ${actual}"
exit 1
fi
shell: bash
runtime-node-pnpm11:
# The whole premise of supporting v11 is that `pnpm runtime` works there.
# Install pnpm v11, install a runtime through it, and run `pnpm install`.
name: 'Runtime node + install on pnpm 11'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up a synthetic package.json
# Use a fresh manifest (and drop the repo lockfile) so `pnpm install`
# under v11 resolves cleanly rather than against a v12-authored lockfile.
run: |
rm -f pnpm-lock.yaml
cat > package.json <<'EOF'
{
"dependencies": {
"is-odd": "3.0.1"
}
}
EOF
shell: bash
- id: pnpm
uses: ./
with:
version: '11.17.0'
runtime: node@22
- name: 'Test: pnpm 11, node 22, and install all worked'
env:
OUT_NAME: ${{ steps.pnpm.outputs.runtime-name }}
OUT_VERSION: ${{ steps.pnpm.outputs.runtime-version }}
run: |
set -e
pnpm_version="$(pnpm --version)"
echo "pnpm --version: ${pnpm_version}"
case "${pnpm_version}" in
11.*) ;;
*) echo "Expected pnpm 11.x, got ${pnpm_version}"; exit 1 ;;
esac
which node
node_version="$(node --version)"
echo "node --version: ${node_version}"
case "${node_version}" in
v22.*) ;;
*) echo "Expected node v22.x, got ${node_version}"; exit 1 ;;
esac
if [ "${OUT_NAME}" != "node" ]; then
echo "Expected outputs.runtime-name=node, got ${OUT_NAME}"; exit 1
fi
case "${OUT_VERSION}" in
22.*) ;;
*) echo "Expected outputs.runtime-version=22.x, got ${OUT_VERSION}"; exit 1 ;;
esac
if [ ! -d node_modules/is-odd ]; then
echo "Expected pnpm install to populate node_modules/is-odd"; exit 1
fi
shell: bash
version-from-dist-tag:
# `version` may be an npm dist-tag; it is resolved against the main
# `pnpm` package's dist-tags.
name: 'Version from dist-tag (next-12)'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: ./
with:
version: next-12
install: false
- name: 'Test: dist-tag resolves to a 12.x version'
run: |
set -e
which pnpm
actual="$(pnpm --version)"
echo "pnpm --version: ${actual}"
case "${actual}" in
12.*) echo "ok" ;;
*) echo "Expected pnpm 12.x, got ${actual}"; exit 1 ;;
esac
shell: bash
version-range:
# `version` may be a semver range. While v12 only has prereleases the
# range resolution falls back to prerelease versions.
name: 'Version from semver range (^12.0.0-0)'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: ./
with:
version: '^12.0.0-0'
install: false
- name: 'Test: range resolves to a 12.x version'
run: |
set -e
actual="$(pnpm --version)"
echo "pnpm --version: ${actual}"
case "${actual}" in
12.*) echo "ok" ;;
*) echo "Expected pnpm 12.x, got ${actual}"; exit 1 ;;
esac
shell: bash
runtime-node:
# Explicit runtime input across OSes. Asserts node binary is on PATH and
# the action's outputs reflect what was installed.
name: 'Runtime node@${{ matrix.major }} (${{ matrix.os }})'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
major: '22'
- os: macos-latest
major: '22'
- os: windows-latest
major: '22'
steps:
- uses: actions/checkout@v7
- id: pnpm
uses: ./
with:
version: '12.0.0'
runtime: node@${{ matrix.major }}
- name: 'Test: node binary on PATH'
env:
MAJOR: ${{ matrix.major }}
run: |
set -e
which node
actual="$(node --version)"
echo "node --version: ${actual}"
case "${actual}" in
v${MAJOR}.*) echo "ok" ;;
*) echo "Expected node v${MAJOR}.x, got ${actual}"; exit 1 ;;
esac
shell: bash
- name: 'Test: outputs.runtime-name and outputs.runtime-version'
env:
OUT_NAME: ${{ steps.pnpm.outputs.runtime-name }}
OUT_VERSION: ${{ steps.pnpm.outputs.runtime-version }}
EXPECTED_VERSION: ${{ matrix.major }}
run: |
set -e
if [ "${OUT_NAME}" != "node" ]; then
echo "Expected outputs.runtime-name=node, got ${OUT_NAME}"
exit 1
fi
case "${OUT_VERSION}" in
"${EXPECTED_VERSION}".*) ;;
*) echo "Expected outputs.runtime-version=${EXPECTED_VERSION}.x, got ${OUT_VERSION}"; exit 1 ;;
esac
shell: bash
runtime-bun:
name: Runtime bun
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: ./
with:
version: '12.0.0'
runtime: bun@latest
- name: 'Test: bun on PATH'
run: |
set -e
which bun
bun --version
shell: bash
runtime-deno:
name: Runtime deno
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: ./
with:
version: '12.0.0'
runtime: deno@2
- name: 'Test: deno on PATH'
run: |
set -e
which deno
deno --version
shell: bash
runtime-from-devengines:
# No `runtime` input — the action should pick up devEngines.runtime from
# package.json and install every entry. Also asserts that `pnpm install` runs by
# default when a manifest is present.
name: 'Runtime from devEngines.runtime'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up package.json with devEngines.runtime
# Remove the action's own pnpm-lock.yaml so `pnpm install` doesn't
# hit a frozen-lockfile mismatch against the synthetic manifest.
run: |
rm -f pnpm-lock.yaml
cat > package.json <<'EOF'
{
"packageManager": "pnpm@12.0.0",
"devEngines": {
"runtime": [
{ "name": "bun", "version": "1.3.12", "onFail": "warn" },
{ "name": "node", "version": "24", "onFail": "warn" },
{ "name": "bun", "version": "1.3.13", "onFail": "warn" }
]
},
"dependencies": {
"is-odd": "3.0.1"
}
}
EOF
shell: bash
- id: pnpm
uses: ./
- name: 'Test: Bun and Node are installed and dependencies are resolved'
env:
OUT_NAME: ${{ steps.pnpm.outputs.runtime-name }}
OUT_VERSION: ${{ steps.pnpm.outputs.runtime-version }}
OUT_RUNTIMES: ${{ steps.pnpm.outputs.runtimes }}
run: |
set -e
which bun
bun_actual="$(bun --version)"
echo "bun --version: ${bun_actual}"
if [ "${bun_actual}" != "1.3.13" ]; then
echo "Expected bun 1.3.13, got ${bun_actual}"
exit 1
fi
which node
actual="$(node --version)"
echo "node --version: ${actual}"
case "${actual}" in
v24.*) ;;
*) echo "Expected node v24.x, got ${actual}"; exit 1 ;;
esac
if [ "${OUT_NAME}" != "bun" ]; then
echo "Expected outputs.runtime-name=bun, got ${OUT_NAME}"
exit 1
fi
if [ "${OUT_VERSION}" != "1.3.13" ]; then
echo "Expected outputs.runtime-version=1.3.13, got ${OUT_VERSION}"
exit 1
fi
# Declaration order is part of the contract, and each version must be
# the one that landed rather than the selector that was asked for.
first="$(printf '%s' "${OUT_RUNTIMES}" | jq -r '.[0].name + "@" + .[0].version')"
second="$(printf '%s' "${OUT_RUNTIMES}" | jq -r '.[1].name + "@" + .[1].version')"
count="$(printf '%s' "${OUT_RUNTIMES}" | jq -r 'length')"
if [ "${count}" != "2" ]; then
echo "Expected 2 entries in outputs.runtimes, got ${count}: ${OUT_RUNTIMES}"
exit 1
fi
if [ "${first}" != "bun@1.3.13" ]; then
echo "Expected outputs.runtimes[0]=bun@1.3.13, got ${first}"
exit 1
fi
case "${second}" in
node@24.*) ;;
*) echo "Expected outputs.runtimes[1]=node@24.x, got ${second}"; exit 1 ;;
esac
# `pnpm install` should have run automatically — node_modules must exist.
if [ ! -d node_modules/is-odd ]; then
echo "Expected pnpm install to have populated node_modules/is-odd"
exit 1
fi
shell: bash
runtime-overrides-devengines:
# Explicit `runtime` input conflicts with `devEngines.runtime` in
# package.json. The action should install the explicit version AND pass
# `--no-runtime` to pnpm install so the devEngines runtime doesn't shadow
# the matrix one.
name: 'Explicit runtime overrides devEngines.runtime'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up package.json with conflicting devEngines.runtime
run: |
rm -f pnpm-lock.yaml
cat > package.json <<'EOF'
{
"packageManager": "pnpm@12.0.0",
"devEngines": {
"runtime": { "name": "node", "version": "^20.0.0", "onFail": "download" }
},
"dependencies": {
"is-odd": "3.0.1"
}
}
EOF
shell: bash
- id: pnpm
uses: ./
with:
runtime: node@22
- name: 'Test: node 22 stays active after pnpm install'
run: |
set -e
actual="$(node --version)"
echo "node --version: ${actual}"
case "${actual}" in
v22.*) ;;
*) echo "Expected node v22.x after install (--no-runtime should have suppressed the devEngines runtime fetch), got ${actual}"; exit 1 ;;
esac
# pnpm install should still have run.
if [ ! -d node_modules/is-odd ]; then
echo "Expected pnpm install to have populated node_modules/is-odd"
exit 1
fi
shell: bash
runtime-survives-context-shims:
# pnpm 12 links the global `node` bin as a context-aware shim that would
# switch to the version the project pins in devEngines.runtime. The
# exported PNPM_CONFIG_GLOBAL_SHIMS must keep the installed runtime
# authoritative for every later step.
name: 'Installed runtime beats context-aware shims'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up package.json with conflicting devEngines.runtime
run: |
rm -f pnpm-lock.yaml
cat > package.json <<'EOF'
{
"packageManager": "pnpm@12.0.0",
"devEngines": {
"runtime": { "name": "node", "version": "20.19.0", "onFail": "download" }
}
}
EOF
shell: bash
- uses: ./
with:
runtime: node@22
- name: 'Test: node 22 runs inside the project'
run: |
set -e
actual="$(node --version)"
echo "node --version: ${actual}"
case "${actual}" in
v22.*) ;;
*) echo "Expected node v22.x, got ${actual} — the context-aware shim switched to the project's pin"; exit 1 ;;
esac
echo "PNPM_CONFIG_GLOBAL_SHIMS: ${PNPM_CONFIG_GLOBAL_SHIMS}"
if [ "${PNPM_CONFIG_GLOBAL_SHIMS}" != '{"node":false}' ]; then
echo 'Expected PNPM_CONFIG_GLOBAL_SHIMS={"node":false}'
exit 1
fi
shell: bash
context-shims-opt-out:
# The counterpart to the job above, and its canary: a workflow that sets
# the setting itself keeps pnpm's switching behaviour, so the project's
# pin wins. If this job stops switching, the job above is no longer
# proving anything. Both spellings pnpm accepts are covered, since
# honouring only one of them would silently override the other.
name: 'Workflow-set ${{ matrix.env_name }} is not overwritten'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
env_name: [PNPM_CONFIG_GLOBAL_SHIMS, pnpm_config_global_shims]
steps:
- uses: actions/checkout@v7
- name: Set up package.json with conflicting devEngines.runtime
run: |
rm -f pnpm-lock.yaml
cat > package.json <<'EOF'
{
"packageManager": "pnpm@12.0.0",
"devEngines": {
"runtime": { "name": "node", "version": "20.19.0", "onFail": "download" }
}
}
EOF
shell: bash
- name: Opt back into context-aware shims
env:
ENV_NAME: ${{ matrix.env_name }}
run: printf '%s={"node":"auto"}\n' "$ENV_NAME" >> "$GITHUB_ENV"
shell: bash
- uses: ./
with:
runtime: node@22
- name: "Test: the project's pin still wins"
run: |
set -e
echo "PNPM_CONFIG_GLOBAL_SHIMS: ${PNPM_CONFIG_GLOBAL_SHIMS}"
if [ "${PNPM_CONFIG_GLOBAL_SHIMS}" = '{"node":false}' ]; then
echo "The action overwrote the setting the workflow provided"
exit 1
fi
actual="$(node --version)"
echo "node --version: ${actual}"
case "${actual}" in
v20.19.0) ;;
*) echo "Expected node v20.19.0 from the context-aware shim, got ${actual}"; exit 1 ;;
esac
shell: bash
runtime-version-fallback:
# `runtime: node` without an `@<version>` suffix should fall back to the
# version declared in devEngines.runtime.
name: 'runtime version falls back to devEngines'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up package.json with devEngines.runtime version
run: |
rm -f pnpm-lock.yaml
cat > package.json <<'EOF'
{
"packageManager": "pnpm@12.0.0",
"devEngines": {
"runtime": { "name": "node", "version": "^20.0.0", "onFail": "download" }
}
}
EOF
shell: bash
- id: pnpm
uses: ./
with:
runtime: node
- name: 'Test: node 20 via fallback'
run: |
set -e
actual="$(node --version)"
echo "node --version: ${actual}"
case "${actual}" in
v20.*) ;;
*) echo "Expected node v20.x, got ${actual}"; exit 1 ;;
esac
shell: bash
node-version-file:
name: 'Node version file (${{ matrix.format }} / ${{ matrix.os }})'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
format: node-version
file: .node-version
version: 22.22.0
runtime: ''
- os: ubuntu-latest
format: tool-versions
file: .tool-versions
version: 24.19.0
runtime: ''
- os: windows-latest
format: nvmrc
file: .nvmrc
version: 22.22.0
runtime: node
- os: ubuntu-latest
format: explicit
file: custom-node-version
version: 22.22.0
runtime: ''
configured-file: custom-node-version
- os: ubuntu-latest
format: disabled
file: .node-version
version: invalid-version-that-must-not-be-read
runtime: ''
configured-file: 'false'
steps:
- uses: actions/checkout@v7
- name: Write version file in a subdirectory project
env:
FORMAT: ${{ matrix.format }}
VERSION_FILE: ${{ matrix.file }}
VERSION: ${{ matrix.version }}
run: |
set -e
mkdir project
if [ "${FORMAT}" = "tool-versions" ]; then
printf 'ruby 3.4.5\nnodejs %s\n' "${VERSION}" > "project/${VERSION_FILE}"
else
printf 'v%s # project runtime\n' "${VERSION}" > "project/${VERSION_FILE}"
fi
shell: bash
- id: pnpm
uses: ./
with:
version: '12.0.0'
working-directory: project
runtime: ${{ matrix.runtime }}
node-version-file: ${{ matrix.configured-file }}
install: false
- name: 'Test: version file selected Node.js'
env:
FORMAT: ${{ matrix.format }}
EXPECTED: v${{ matrix.version }}
OUTPUT_NAME: ${{ steps.pnpm.outputs.runtime-name }}
OUTPUT_VERSION: ${{ steps.pnpm.outputs.runtime-version }}
OUTPUT_RUNTIMES: ${{ steps.pnpm.outputs.runtimes }}
run: |
set -e
if [ "${FORMAT}" = "disabled" ]; then
if [ -n "${OUTPUT_NAME}" ] || [ -n "${OUTPUT_VERSION}" ] || [ "${OUTPUT_RUNTIMES}" != '[]' ]; then
echo "Expected no runtime installation with detection disabled"
exit 1
fi
exit 0
fi
actual="$(node --version)"
if [ "${actual}" != "${EXPECTED}" ]; then
echo "Expected ${EXPECTED}, got ${actual}"
exit 1
fi
if [ "${OUTPUT_NAME}" != "node" ] || [ "v${OUTPUT_VERSION}" != "${EXPECTED}" ]; then
echo "Unexpected runtime outputs: ${OUTPUT_NAME}@${OUTPUT_VERSION}"
exit 1
fi
shell: bash
install-false:
# `install: false` skips the auto-install step even though a manifest is
# present.
name: 'install: false skips pnpm install'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up package.json with a dependency
run: |
rm -f pnpm-lock.yaml
cat > package.json <<'EOF'
{
"packageManager": "pnpm@12.0.0",
"dependencies": {
"is-odd": "3.0.1"
}
}
EOF
shell: bash
- uses: ./
with:
version: '12.0.0'
install: false
- name: 'Test: node_modules was not populated'
run: |
set -e
if [ -d node_modules/is-odd ]; then
echo "Expected install: false to skip pnpm install, but node_modules/is-odd exists"
exit 1
fi
# pnpm itself should still be on PATH.
which pnpm
pnpm --version
shell: bash
no-runtime:
# No runtime input, no devEngines.runtime. Action installs pnpm only and
# leaves the runtime outputs empty. With no package.json, `pnpm install`
# is also skipped.
name: 'No runtime, no manifest'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- id: pnpm
uses: ./
with:
version: '12.0.0'
- name: 'Test: pnpm works, runtime outputs are empty'
env:
OUT_NAME: ${{ steps.pnpm.outputs.runtime-name }}
OUT_VERSION: ${{ steps.pnpm.outputs.runtime-version }}
OUT_RUNTIMES: ${{ steps.pnpm.outputs.runtimes }}
run: |
set -e
which pnpm
pnpm --version
if [ -n "${OUT_NAME}" ]; then
echo "Expected outputs.runtime-name to be empty, got '${OUT_NAME}'"
exit 1
fi
if [ -n "${OUT_VERSION}" ]; then
echo "Expected outputs.runtime-version to be empty, got '${OUT_VERSION}'"
exit 1
fi
if [ "${OUT_RUNTIMES}" != "[]" ]; then
echo "Expected outputs.runtimes=[], got '${OUT_RUNTIMES}'"
exit 1
fi
shell: bash
cache-lockfile-verification:
# The action caches pnpm's lockfile verification log, which lives in
# `cacheDir`. Newer pnpm reports that via `pnpm cache path`; older
# releases have no such subcommand and the action derives pnpm's
# per-platform default instead. Guard that derivation against pnpm's own.
name: 'Lockfile verification cache (${{ matrix.os }}, cache=${{ matrix.cache }})'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# The log is cached independently of the store, so the store-less
# configuration has to reach it too.
- os: ubuntu-latest
cache: false
- os: ubuntu-latest
cache: true
- os: macos-latest
cache: true
- os: windows-latest
cache: true
steps:
- uses: actions/checkout@v7
- name: Configure a supply-chain policy so the verification runs
# A one-minute floor activates the check without holding back any
# version this repo already locks.
run: |
printf '\nminimumReleaseAge: 1\n' >> pnpm-workspace.yaml
shell: bash
- uses: ./
with:
version: '12.0.0'
runtime: node@22
cache: ${{ matrix.cache }}
- name: 'Test: pnpm wrote the verification log where the action looks for it'
run: |
set -e
case "$RUNNER_OS" in
Linux) cacheDir="${XDG_CACHE_HOME:-$HOME/.cache}/pnpm" ;;
macOS) cacheDir="$HOME/Library/Caches/pnpm" ;;
Windows) cacheDir="$(cygpath -u "$LOCALAPPDATA")/pnpm-cache" ;;
*) echo "Unexpected RUNNER_OS: $RUNNER_OS"; exit 1 ;;
esac
echo "Expecting the verification log in ${cacheDir}"
if [ ! -f "${cacheDir}/lockfile-verified.jsonl" ]; then
echo "No lockfile-verified.jsonl there; the action would cache nothing"
ls -la "${cacheDir}" || true
exit 1
fi
shell: bash
working-directory:
# A project whose root is not the repository root. Running the install at
# the repository root would exit 0 having installed nothing, so assert the
# dependency actually landed. `cache: true` is part of the test: without
# `cache-dependency-path` rebasing onto the working directory it matches no
# lockfile and the restore throws outright.
name: 'Project in a subdirectory'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Move this project into docs/
run: |
set -e
mkdir -p docs
mv package.json pnpm-lock.yaml pnpm-workspace.yaml docs/
node -e "
const fs = require('fs')
const manifest = JSON.parse(fs.readFileSync('docs/package.json', 'utf8'))
manifest.packageManager = 'pnpm@12.0.0'
fs.writeFileSync('docs/package.json', JSON.stringify(manifest, null, 2))
"
shell: bash
- id: pnpm
uses: ./
with:
working-directory: docs
runtime: node@22
cache: true
- name: 'Test: the subdirectory project was installed'
run: |
set -e
if [ ! -d docs/node_modules/@actions/cache ]; then
echo "Expected pnpm install to populate docs/node_modules"
ls -la docs || true
exit 1
fi
if [ -d node_modules ]; then
echo "Did not expect node_modules at the repository root"
exit 1
fi
# `packageManager` was read from docs/package.json, not the root.
pnpm_version="$(pnpm --version)"
if [ "${pnpm_version}" != "12.0.0" ]; then
echo "Expected pnpm 12.0.0 from docs/package.json, got ${pnpm_version}"
exit 1
fi
shell: bash
working-directory-deprecated-input:
# `package-json-file` is deprecated but must keep working exactly as it
# did: the directory holding the file becomes the working directory, and
# an explicit `cache-dependency-path` stays relative to the repository
# root. Rebasing it onto the working directory would look for
# `web/web/pnpm-lock.yaml` and fail the restore.
name: 'Deprecated package-json-file still works'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Move this project into web/
run: |
set -e
mkdir -p web
mv package.json pnpm-lock.yaml pnpm-workspace.yaml web/
node -e "
const fs = require('fs')
const manifest = JSON.parse(fs.readFileSync('web/package.json', 'utf8'))
manifest.packageManager = 'pnpm@12.0.0'
fs.writeFileSync('web/package.json', JSON.stringify(manifest, null, 2))
"
shell: bash
- uses: ./
with:
package-json-file: web/package.json
cache: true
cache-dependency-path: web/pnpm-lock.yaml
- name: 'Test: the install ran in web/'
run: |
set -e
if [ ! -d web/node_modules/@actions/cache ]; then
echo "Expected pnpm install to populate web/node_modules"
ls -la web || true
exit 1
fi
pnpm_version="$(pnpm --version)"
if [ "${pnpm_version}" != "12.0.0" ]; then
echo "Expected pnpm 12.0.0 from web/package.json, got ${pnpm_version}"
exit 1
fi
shell: bash
require-lockfile:
# `require-lockfile` installs against an existing lockfile and fails when
# there is none — the case pnpm's CI default leaves open, since a plain
# install resolves from the registry and exits 0 instead.
name: 'require-lockfile'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up a manifest with a matching lockfile
run: |
set -e
rm -f pnpm-lock.yaml
cat > package.json <<'EOF'
{
"packageManager": "pnpm@12.0.0",
"dependencies": {
"is-odd": "3.0.1"
}
}