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