-
Notifications
You must be signed in to change notification settings - Fork 0
52 lines (42 loc) · 1.46 KB
/
Copy pathpublish.yml
File metadata and controls
52 lines (42 loc) · 1.46 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
name: Publish to NPM
on:
push:
branches:
- main
jobs:
publish:
name: Build and Publish
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Enable Corepack
run: corepack enable
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build package
run: yarn build
- name: Check version and publish
id: publish
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
CURRENT_VERSION=$(node -p "require('./package.json').version")
# Handle potential failure if package is new
PUBLISHED_VERSION=$(npm view $PACKAGE_NAME version 2>/dev/null || echo "0.0.0")
# Use node to compare semver versions
IS_NEWER=$(node -p "require('semver').gt('$CURRENT_VERSION', '$PUBLISHED_VERSION')")
if [ "$IS_NEWER" = "true" ]; then
echo "New version detected: $CURRENT_VERSION (Registry: $PUBLISHED_VERSION)"
echo "Publishing to NPM..."
npm publish --access public --provenance
else
echo "Version $CURRENT_VERSION is not newer than registry ($PUBLISHED_VERSION). Skipping."
fi