Skip to content

Commit 378e193

Browse files
committed
feat: npm publish canary version
1 parent 321ac8c commit 378e193

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

.github/workflows/ci-npm-publish-README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ To use this reusable workflow, create a project-specific workflow file in your `
4343
| `node-version` | Node.js version to use | No | `20` |
4444
| `package-manager` | Package manager to use (`npm`, `yarn`, `pnpm`) | No | `npm` |
4545
| `registry-url` | npm registry URL | No | `https://registry.npmjs.org` |
46-
| `app-dir` | Directory containing package.json | No | `.` |
4746
| `install-command` | Command to install dependencies | No | Auto-detected |
4847
| `test-command` | Command to run tests | No | Auto-detected |
4948
| `build-command` | Command to build the package | No | Auto-detected |
50-
| `publish-command` | Command to publish the package | No | Auto-detected |
51-
| `skip-tests` | Skip running tests | No | `false` |
5249
| `use-ci-build` | Use build artifacts from CI workflow | No | `false` |
50+
| `access` | Package access level | No | `public` |
51+
| `canary` | Create canary publish | No | `false` |
5352

5453
### 📄 Example usage (`<own project>/.github/workflows/npm-publish.yml`)
5554

.github/workflows/ci-npm-publish.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ on:
3737
required: false
3838
type: string
3939
default: 'public'
40+
canary:
41+
description: 'Make publish as a canary release'
42+
required: false
43+
type: boolean
44+
default: false
4045

4146
jobs:
4247
publish-npm-stable:
@@ -68,7 +73,15 @@ jobs:
6873
if: ${{ !inputs.use-ci-build }}
6974
run: ${{ inputs.build-command }}
7075
- name: Publish package
76+
if: ${{ !inputs.canary }}
7177
run: npm publish --ignore-scripts --access ${{ inputs.access }}
7278
env:
7379
NPM_CONFIG_PROVENANCE: true
74-
80+
- name: Publish canary package
81+
if: ${{ inputs.canary }}
82+
run: |
83+
short_sha=$(git rev-parse --short HEAD)
84+
sed -i '' -E "s/\"version\": \"([^\"]+)\"/\"version\": \"\1-canary-${short_sha}\"/" package.json
85+
npm publish --ignore-scripts --access ${{ inputs.access }} --tag canary
86+
env:
87+
NPM_CONFIG_PROVENANCE: true

0 commit comments

Comments
 (0)