Skip to content

Commit e8990a4

Browse files
HunnySajidlenkan
andauthored
feat: add npm publish github action workflow (#28)
* test: husky integration check * test: husky integration check * build: add ci-checks in github workflow * Apply suggestions from Daniel in code review Co-authored-by: Daniel Lenksjö <[email protected]> * fix: add single job for main.yml * feat: add prettierignore file * fix: format check instead of overwrite * feat: add npm publish github action workflow * format: publish-npm file --------- Co-authored-by: Daniel Lenksjö <[email protected]>
1 parent 448b5fe commit e8990a4

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

Diff for: .github/workflows/publish-npm.yml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Publish NPM
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
dry-run:
7+
type: boolean
8+
default: true
9+
description: Dry run publish
10+
dist-tag:
11+
type: choice
12+
options:
13+
- dev
14+
- latest
15+
default: dev
16+
description: Npm dist tag
17+
jobs:
18+
publish:
19+
name: Publish NPM
20+
permissions:
21+
contents: write
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout repo
25+
uses: actions/checkout@v4
26+
27+
- uses: actions/setup-node@v4
28+
with:
29+
node-version: "20"
30+
cache: "npm"
31+
registry-url: "https://registry.npmjs.org"
32+
33+
- name: Install dependencies
34+
run: npm ci --ignore-scripts
35+
36+
- name: Set package name from vars
37+
if: ${{ vars.NPM_PACKAGE_NAME }}
38+
run: |
39+
cat package.json | jq -r '.name = "${{ vars.NPM_PACKAGE_NAME }}"' > package.json.tmp
40+
mv package.json.tmp package.json
41+
42+
- name: Set version from commit
43+
if: ${{ inputs.dist-tag == 'dev' }}
44+
run: |
45+
npm version --no-git-tag-version $(cat package.json | jq .version -r)-dev.$(git rev-parse --short HEAD)
46+
47+
- name: Create git tag
48+
run: git tag $(cat package.json | jq .version -r)
49+
50+
- name: Publish dev package (Dry run)
51+
if: ${{ inputs.dry-run == true }}
52+
run: npm publish --tag "${{ inputs.dist-tag }}" --dry-run
53+
54+
- name: Publish dev package
55+
if: ${{ inputs.dry-run == false }}
56+
env:
57+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
58+
run: |
59+
npm publish --tag "${{ inputs.dist-tag }}"
60+
git tag v$(cat package.json | jq .version -r)
61+
git push origin v$(cat package.json | jq .version -r)

0 commit comments

Comments
 (0)