44 workflow_call :
55 inputs :
66 scope :
7- description : ' NPM package scope (e.g., @iexec)'
8- default : ' @iexec'
7+ description : " NPM package scope (e.g., @iexec)"
8+ default : " @iexec"
99 type : string
1010 node-version :
11- description : ' Node.js version to use'
12- default : ' 20 '
11+ description : " Node.js version to use"
12+ default : " 20 "
1313 type : string
1414 registry :
15- description : ' NPM registry URL'
16- default : ' https://registry.npmjs.org'
15+ description : " NPM registry URL"
16+ default : " https://registry.npmjs.org"
1717 type : string
1818 access :
19- description : ' Package access (public/restricted)'
20- default : ' public'
19+ description : " Package access (public/restricted)"
20+ default : " public"
2121 type : string
2222 provenance :
23- description : ' Enable npm provenance'
23+ description : " Enable npm provenance"
2424 default : true
2525 type : boolean
2626 install-command :
27- description : ' Install dependencies command'
28- default : ' npm ci'
27+ description : " Install dependencies command"
28+ default : " npm ci"
2929 type : string
3030 build-command :
31- description : ' Build package command'
32- default : ' npm run build'
31+ description : " Build package command"
32+ default : " npm run build"
3333 type : string
3434 run-tests :
35- description : ' Execute unit tests step'
35+ description : " Execute unit tests step"
3636 default : false
3737 type : boolean
3838 test-command :
39- description : ' Run unit tests command'
40- default : ' npm test --if-present'
39+ description : " Run unit tests command"
40+ default : " npm test --if-present"
4141 type : string
4242 lint-command :
43- description : ' Run linting command'
44- default : ' npm run lint --if-present'
43+ description : " Run linting command"
44+ default : " npm run lint --if-present"
4545 type : string
4646 type-check-command :
47- description : ' Run type-checking command'
48- default : ' npm run check-types --if-present'
47+ description : " Run type-checking command"
48+ default : " npm run check-types --if-present"
4949 type : string
5050 format-check-command :
51- description : ' Run format-checking command'
52- default : ' npm run check-format --if-present'
51+ description : " Run format-checking command"
52+ default : " npm run check-format --if-present"
5353 type : string
5454 environment :
55- description : ' GitHub environment'
56- default : ' production'
55+ description : " GitHub environment"
56+ default : " production"
5757 type : string
5858 tag :
59- description : ' npm publish tag (e.g., latest, nightly)'
60- default : ' '
59+ description : " npm publish tag (e.g., latest, nightly)"
60+ default : " "
6161 type : string
6262 tag-prefix :
63- description : ' Prefix for Git tag'
64- default : ' v '
63+ description : " Prefix for Git tag"
64+ default : " v "
6565 type : string
6666 working-directory :
67- description : ' Directory containing package.json'
68- default : ' '
67+ description : " Directory containing package.json"
68+ default : " "
6969 type : string
7070 artifact-name :
71- description : ' Name of an artifact to download before the build (leave empty to skip)'
72- default : ' '
71+ description : " Name of an artifact to download before the build (leave empty to skip)"
72+ default : " "
7373 type : string
7474 artifact-path :
75- description : ' Destination path for the downloaded artifact'
76- default : ' '
75+ description : " Destination path for the downloaded artifact"
76+ default : " "
7777 type : string
7878 version :
79- description : ' Version to publish (leave empty to use package.json version)'
80- default : ' '
79+ description : " Version to publish (leave empty to use package.json version)"
80+ default : " "
8181 type : string
82+ dry-run :
83+ description : " Run in dry-run mode (the package will not be published)"
84+ default : false
85+ type : boolean
8286 secrets :
8387 npm-token :
84- description : ' NPM auth token'
85- required : true
88+ description : " NPM auth token (required unless `dry-run: true`) "
89+ required : false
8690
8791jobs :
8892 build :
9397 packages : write
9498 id-token : write
9599 steps :
100+ - name : Ensure npm-token
101+ if : ${{ !inputs.dry-run }}
102+ run : |
103+ if [ -n "${{ secrets.npm-token }}" ]; then
104+ echo "`npm-token` secret is set"
105+ else
106+ echo "Missing `npm-token` secret (required unless `dry-run: true`)"
107+ exit 1
108+ fi
109+
96110 - name : Download extra artifact
97111 if : ${{ inputs.artifact-name != '' }}
98112 uses : actions/download-artifact@v4
@@ -111,7 +125,7 @@ jobs:
111125 - name : Install dependencies
112126 working-directory : ${{ inputs.working-directory }}
113127 run : ${{ inputs.install-command }}
114-
128+
115129 - name : Override version
116130 if : ${{ inputs.version != '' }}
117131 working-directory : ${{ inputs.working-directory }}
@@ -149,8 +163,14 @@ jobs:
149163 TAG_OPT="--tag ${{ inputs.tag }}"
150164 fi
151165
166+ DRY_RUN_OPT=""
167+ if [ "${{ inputs.dry-run }}" = "true" ]; then
168+ DRY_RUN_OPT="--dry-run"
169+ fi
170+
171+ PROVENANCE_OPT=""
152172 if [ "${{ inputs.provenance }}" = "true" ]; then
153- npm publish --access ${{ inputs.access }} $TAG_OPT --provenance
154- else
155- npm publish --access ${{ inputs.access }} $TAG_OPT
173+ PROVENANCE_OPT="--provenance"
156174 fi
175+
176+ npm publish --access ${{ inputs.access }} $TAG_OPT $DRY_RUN_OPT $PROVENANCE_OPT
0 commit comments