Skip to content

Commit a5ea80b

Browse files
feat(publish-npm): add dry-run option
1 parent 29174e7 commit a5ea80b

File tree

2 files changed

+77
-56
lines changed

2 files changed

+77
-56
lines changed

.github/workflows/publish-npm.yml

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,85 +4,89 @@ on:
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

8791
jobs:
8892
build:
@@ -93,6 +97,16 @@ jobs:
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

publish-npm/README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ for the package scope, Node.js version, registry URL, and other options. The wor
2020
## Workflow Inputs 🛠️
2121

2222
| **Input** | **Description** | **Required** | **Default** |
23-
|--------------------------|---------------------------------------------------------------|--------------|-------------------------------------|
23+
| ------------------------ | ------------------------------------------------------------- | ------------ | ----------------------------------- |
2424
| **scope** | NPM package scope (e.g., `@iexec`). | No | `@iexec` |
2525
| **node-version** | Node.js version to use. | No | `20` |
2626
| **registry** | NPM registry URL. | No | `https://registry.npmjs.org` |
@@ -40,12 +40,13 @@ for the package scope, Node.js version, registry URL, and other options. The wor
4040
| **artifact-name** | Name of an artifact to download before the build. | No | `''` (empty string) |
4141
| **artifact-path** | Destination path for the downloaded artifact. | No | `''` (empty string) |
4242
| **version** | Version to publish (leave empty to use package.json version). | No | `''` (empty string) |
43+
| **dry-run** | Run in dry-run mode (the package will not be published). | No | `false` |
4344

4445
### Secrets 🔐
4546

46-
| **Secret** | **Description** | **Required** |
47-
|---------------|-----------------|--------------|
48-
| **npm-token** | NPM auth token. | Yes |
47+
| **Secret** | **Description** | **Required** |
48+
| ------------- | -------------------------------------------------- | ------------ |
49+
| **npm-token** | NPM auth token (required unless `dry-run: true`)". | No |
4950

5051
## Job and Steps ⚙️
5152

@@ -54,9 +55,9 @@ for the package scope, Node.js version, registry URL, and other options. The wor
5455
- **Runs On**: `ubuntu-latest`.
5556
- **Environment**: Uses the environment specified in `inputs.environment`.
5657
- **Permissions**:
57-
- `contents: read` – to access repository contents. 🔍
58-
- `packages: write` – to allow package publication. ✨
59-
- `id-token: write` – for authentication purposes. 🔑
58+
- `contents: read` – to access repository contents. 🔍
59+
- `packages: write` – to allow package publication. ✨
60+
- `id-token: write` – for authentication purposes. 🔑
6061

6162
## How to Use This Reusable Workflow 🔄
6263

@@ -76,14 +77,14 @@ for the package scope, Node.js version, registry URL, and other options. The wor
7677
publish:
7778
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/publish-npm.yml@main
7879
with:
79-
node-version: '22'
80-
build-command: 'npm run build:prod'
80+
node-version: "22"
81+
build-command: "npm run build:prod"
8182
run-tests: true
82-
test-command: 'npm run test:ci'
83-
lint-command: 'npm run lint'
84-
type-check-command: 'npm run check-types'
85-
format-check-command: 'npm run check-format'
86-
tag-prefix: 'v'
83+
test-command: "npm run test:ci"
84+
lint-command: "npm run lint"
85+
type-check-command: "npm run check-types"
86+
format-check-command: "npm run check-format"
87+
tag-prefix: "v"
8788
# Optional: Download an artifact before building
8889
# artifact-name: 'my-build-artifact'
8990
# artifact-path: './dist'

0 commit comments

Comments
 (0)