Skip to content

Commit d8a0c33

Browse files
feat(publish-npm): add dry-run option (#71)
* feat(publish-npm): add dry-run option * chore(publish-npm): remove unused input
1 parent 29174e7 commit d8a0c33

File tree

2 files changed

+74
-59
lines changed

2 files changed

+74
-59
lines changed

.github/workflows/publish-npm.yml

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,85 +4,85 @@ 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: ''
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

8787
jobs:
8888
build:
@@ -93,6 +93,16 @@ jobs:
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

publish-npm/README.md

Lines changed: 14 additions & 15 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` |
@@ -35,17 +35,17 @@ for the package scope, Node.js version, registry URL, and other options. The wor
3535
| **format-check-command** | Run format-checking command. | No | `npm run check-format --if-present` |
3636
| **environment** | GitHub environment. | No | `production` |
3737
| **tag** | npm publish tag (e.g., latest, nightly). | No | `''` (empty string) |
38-
| **tag-prefix** | Prefix for Git tag. | No | `v` |
3938
| **working-directory** | Directory containing package.json. | No | `''` (empty string) |
4039
| **artifact-name** | Name of an artifact to download before the build. | No | `''` (empty string) |
4140
| **artifact-path** | Destination path for the downloaded artifact. | No | `''` (empty string) |
4241
| **version** | Version to publish (leave empty to use package.json version). | No | `''` (empty string) |
42+
| **dry-run** | Run in dry-run mode (the package will not be published). | No | `false` |
4343

4444
### Secrets 🔐
4545

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

5050
## Job and Steps ⚙️
5151

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

6161
## How to Use This Reusable Workflow 🔄
6262

@@ -76,14 +76,13 @@ for the package scope, Node.js version, registry URL, and other options. The wor
7676
publish:
7777
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/publish-npm.yml@main
7878
with:
79-
node-version: '22'
80-
build-command: 'npm run build:prod'
79+
node-version: "22"
80+
build-command: "npm run build:prod"
8181
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'
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"
8786
# Optional: Download an artifact before building
8887
# artifact-name: 'my-build-artifact'
8988
# artifact-path: './dist'

0 commit comments

Comments
 (0)