Skip to content

Commit d10ecc4

Browse files
committed
ci: add npm publish workflow for main branch
Add GitHub Actions workflow to test, lint, build and publish npm packages on push to main branch. Includes version bump commit and notification steps.
1 parent 0849ba4 commit d10ecc4

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: πŸš€ Publish NPM Packages
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
# Job untuk testing dan linting (berjalan di semua push/PR)
11+
test:
12+
name: πŸ§ͺ Test & Lint
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: πŸ“₯ Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: 🟒 Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '22.16.0'
23+
registry-url: 'https://registry.npmjs.org'
24+
25+
- name: πŸ“¦ Setup Bun
26+
uses: oven-sh/setup-bun@v1
27+
with:
28+
bun-version: '1.2.17'
29+
30+
- name: πŸ“₯ Install dependencies
31+
run: bun install
32+
33+
- name: πŸ” Run linting
34+
run: bun run lint
35+
36+
- name: πŸ—οΈ Build all libraries
37+
run: bun run build:libs
38+
39+
# Job untuk publish (hanya berjalan di main branch)
40+
publish:
41+
name: πŸ“¦ Publish to NPM
42+
runs-on: ubuntu-latest
43+
needs: test
44+
# Hanya berjalan jika push ke main branch (bukan PR)
45+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
46+
47+
steps:
48+
- name: πŸ“₯ Checkout code
49+
uses: actions/checkout@v4
50+
with:
51+
# Fetch full history untuk git operations
52+
fetch-depth: 0
53+
54+
- name: 🟒 Setup Node.js
55+
uses: actions/setup-node@v4
56+
with:
57+
node-version: '22.16.0'
58+
registry-url: 'https://registry.npmjs.org'
59+
60+
- name: πŸ“¦ Setup Bun
61+
uses: oven-sh/setup-bun@v1
62+
with:
63+
bun-version: '1.2.17'
64+
65+
- name: πŸ“₯ Install dependencies
66+
run: bun install
67+
68+
- name: πŸ”§ Configure git
69+
run: |
70+
git config --global user.name "github-actions[bot]"
71+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
72+
73+
- name: πŸš€ Publish to NPM
74+
run: node tools/scripts/publish-all.js
75+
env:
76+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
77+
78+
- name: πŸ“ Commit version changes
79+
run: |
80+
git add .
81+
if git diff --staged --quiet; then
82+
echo "No changes to commit"
83+
else
84+
git commit -m "πŸ”– Auto-bump package versions [skip ci]"
85+
git push origin main
86+
fi
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
90+
# Job untuk notifikasi (opsional)
91+
notify:
92+
name: πŸ“¬ Notify
93+
runs-on: ubuntu-latest
94+
needs: [test, publish]
95+
if: always() && github.event_name == 'push' && github.ref == 'refs/heads/main'
96+
97+
steps:
98+
- name: πŸ“¬ Notify success
99+
if: needs.publish.result == 'success'
100+
run: |
101+
echo "βœ… NPM packages published successfully!"
102+
103+
- name: πŸ“¬ Notify failure
104+
if: needs.publish.result == 'failure'
105+
run: |
106+
echo "❌ NPM package publishing failed!"
107+
exit 1

0 commit comments

Comments
Β (0)