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 : ' '
61- type : string
62- tag-prefix :
63- description : ' Prefix for Git tag'
64- default : ' v'
59+ description : " npm publish tag (e.g., latest, nightly)"
60+ default : " "
6561 type : string
6662 working-directory :
67- description : ' Directory containing package.json'
68- default : ' '
63+ description : " Directory containing package.json"
64+ default : " "
6965 type : string
7066 artifact-name :
71- description : ' Name of an artifact to download before the build (leave empty to skip)'
72- default : ' '
67+ description : " Name of an artifact to download before the build (leave empty to skip)"
68+ default : " "
7369 type : string
7470 artifact-path :
75- description : ' Destination path for the downloaded artifact'
76- default : ' '
71+ description : " Destination path for the downloaded artifact"
72+ default : " "
7773 type : string
7874 version :
79- description : ' Version to publish (leave empty to use package.json version)'
80- default : ' '
75+ description : " Version to publish (leave empty to use package.json version)"
76+ default : " "
8177 type : string
78+ dry-run :
79+ description : " Run in dry-run mode (the package will not be published)"
80+ default : false
81+ type : boolean
8282 secrets :
8383 npm-token :
84- description : ' NPM auth token'
85- required : true
84+ description : " NPM auth token (required unless `dry-run: true`) "
85+ required : false
8686
8787jobs :
8888 build :
9393 packages : write
9494 id-token : write
9595 steps :
96+ - name : Ensure npm-token
97+ if : ${{ !inputs.dry-run }}
98+ run : |
99+ if [ -n "${{ secrets.npm-token }}" ]; then
100+ echo "`npm-token` secret is set"
101+ else
102+ echo "Missing `npm-token` secret (required unless `dry-run: true`)"
103+ exit 1
104+ fi
105+
96106 - name : Download extra artifact
97107 if : ${{ inputs.artifact-name != '' }}
98108 uses : actions/download-artifact@v4
@@ -111,7 +121,7 @@ jobs:
111121 - name : Install dependencies
112122 working-directory : ${{ inputs.working-directory }}
113123 run : ${{ inputs.install-command }}
114-
124+
115125 - name : Override version
116126 if : ${{ inputs.version != '' }}
117127 working-directory : ${{ inputs.working-directory }}
@@ -149,8 +159,14 @@ jobs:
149159 TAG_OPT="--tag ${{ inputs.tag }}"
150160 fi
151161
162+ DRY_RUN_OPT=""
163+ if [ "${{ inputs.dry-run }}" = "true" ]; then
164+ DRY_RUN_OPT="--dry-run"
165+ fi
166+
167+ PROVENANCE_OPT=""
152168 if [ "${{ inputs.provenance }}" = "true" ]; then
153- npm publish --access ${{ inputs.access }} $TAG_OPT --provenance
154- else
155- npm publish --access ${{ inputs.access }} $TAG_OPT
169+ PROVENANCE_OPT="--provenance"
156170 fi
171+
172+ npm publish --access ${{ inputs.access }} $TAG_OPT $DRY_RUN_OPT $PROVENANCE_OPT
0 commit comments