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