Skip to content

Commit 6ec9200

Browse files
authored
Krozamdev patch ci publish (#28)
* Create publish_npm.yml * ci: update logic deleting tag and publish
1 parent 2ec8c4c commit 6ec9200

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

.github/workflows/publish_npm.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Publish NPM
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: 18
20+
registry-url: "https://registry.npmjs.org/"
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Run tests
26+
run: npm test
27+
28+
- name: Build project
29+
run: npm run build
30+
31+
- name: Get current tag
32+
id: get-tag
33+
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
34+
35+
- name: Check if version already exists in npm
36+
id: check-version
37+
run: |
38+
PACKAGE_NAME=$(node -p "require('./package.json').name")
39+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
40+
EXISTS=$(npm view "$PACKAGE_NAME@$PACKAGE_VERSION" version || echo "not_found")
41+
42+
if [ "$EXISTS" != "not_found" ]; then
43+
echo "Version $PACKAGE_VERSION already exists on npm. Skipping publish."
44+
exit 1
45+
fi
46+
47+
- name: Publish package
48+
if: success()
49+
run: npm publish --access public
50+
env:
51+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
52+
53+
- name: Delete tag if publish fails
54+
if: failure()
55+
run: |
56+
echo "Deleting tag $TAG_NAME because publish failed..."
57+
git push --delete origin $TAG_NAME

0 commit comments

Comments
 (0)