-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (62 loc) · 1.73 KB
/
publish-to-npm.yml
File metadata and controls
75 lines (62 loc) · 1.73 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Publish to npm (OIDC)
on:
push:
branches:
- main
paths:
- 'src/**'
- 'package.json'
- 'pnpm-lock.yaml'
pull_request:
paths:
- 'src/**'
- 'package.json'
- 'pnpm-lock.yaml'
release:
types: [published]
workflow_dispatch:
permissions:
id-token: write
contents: read
env:
publish: false
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
always-auth: true
- name: Ensure latest npm
run: npm install -g npm@latest
- name: Install dependencies
run: |
npm i -g pnpm
pnpm install
- name: Check if package needs publishing
id: check_publish
run: |
current_version=$(node -p "require('./package.json').version")
npm_package_name=$(node -p "require('./package.json').name")
published_version=$(npm show $npm_package_name version) || echo "0.0.0"
echo "Current version: $current_version"
echo "Published version: $published_version"
if [ "$current_version" == "$published_version" ]; then
echo "No new version. Skipping publish."
echo "publish=false" >> $GITHUB_ENV
else
echo "New version available. Proceeding to publish."
echo "publish=true" >> $GITHUB_ENV
fi
- name: Build the project
run: |
pnpm run build
- name: Publish to npm using OIDC
if: env.publish == 'true'
run: |
npm publish --provenance