Skip to content

Commit fbf8f01

Browse files
committed
feat: npm publish를 위한 작업
1 parent b555820 commit fbf8f01

File tree

6 files changed

+703
-0
lines changed

6 files changed

+703
-0
lines changed

.github/workflows/release_jgf.yml

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
name: Release JGF
2+
3+
permissions: {}
4+
5+
on:
6+
workflow_dispatch:
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
- npm/jgf/package.json
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
check:
19+
name: Check version
20+
runs-on: ubuntu-latest
21+
outputs:
22+
version_changed: ${{ steps.version.outputs.changed }}
23+
version: ${{ steps.version.outputs.version }}
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- name: Check version changes
28+
uses: EndBug/version-check@v2
29+
id: version
30+
with:
31+
static-checking: localIsNew
32+
file-url: https://unpkg.com/jgf@latest/package.json
33+
file-name: npm/jgf/package.json
34+
35+
- name: Print version
36+
if: steps.version.outputs.changed == 'true'
37+
env:
38+
NEW_VERSION: ${{ steps.version.outputs.version }}
39+
run: |
40+
echo "Version change found! New version: ${NEW_VERSION}"
41+
42+
build:
43+
needs: check
44+
if: needs.check.outputs.version_changed == 'true'
45+
strategy:
46+
matrix:
47+
include:
48+
- os: windows-latest
49+
target: x86_64-pc-windows-msvc
50+
code-target: win32-x64
51+
52+
- os: windows-latest
53+
target: aarch64-pc-windows-msvc
54+
code-target: win32-arm64
55+
56+
- os: ubuntu-latest
57+
target: x86_64-unknown-linux-gnu
58+
code-target: linux-x64-gnu
59+
60+
- os: ubuntu-latest
61+
target: aarch64-unknown-linux-gnu
62+
code-target: linux-arm64-gnu
63+
64+
- os: ubuntu-latest
65+
target: x86_64-unknown-linux-musl
66+
code-target: linux-x64-musl
67+
68+
- os: ubuntu-latest
69+
target: aarch64-unknown-linux-musl
70+
code-target: linux-arm64-musl
71+
72+
- os: macos-latest
73+
target: x86_64-apple-darwin
74+
code-target: darwin-x64
75+
76+
- os: macos-latest
77+
target: aarch64-apple-darwin
78+
code-target: darwin-arm64
79+
80+
name: Package ${{ matrix.code-target }}
81+
runs-on: ${{ matrix.os }}
82+
defaults:
83+
run:
84+
shell: bash
85+
env:
86+
JGF_VERSION: ${{ needs.check.outputs.version }}
87+
steps:
88+
- uses: actions/checkout@v4
89+
90+
- name: Install cross
91+
uses: taiki-e/install-action@v2
92+
with:
93+
tool: cross
94+
95+
- name: Rust Cache
96+
uses: Swatinem/rust-cache@v2
97+
with:
98+
shared-key: release-${{ matrix.target }}
99+
100+
- name: Add Rust Target
101+
run: rustup target add ${{ matrix.target }}
102+
103+
- name: Build
104+
shell: bash
105+
run: |
106+
cross build --release --bin jgf --target=${{ matrix.target }}
107+
108+
# The binaries are zipped to fix permission loss https://github.com/actions/upload-artifact#permission-loss
109+
- name: Archive Binaries
110+
if: runner.os == 'Windows'
111+
run: |
112+
JGF_BIN_NAME=jgf-${{ matrix.code-target }}
113+
mv target/${{ matrix.target }}/release/jgf.exe $JGF_BIN_NAME.exe
114+
7z a $JGF_BIN_NAME.zip $JGF_BIN_NAME.exe
115+
116+
# The binaries are zipped to fix permission loss https://github.com/actions/upload-artifact#permission-loss
117+
- name: Archive Binaries
118+
if: runner.os != 'Windows'
119+
run: |
120+
JGF_BIN_NAME=jgf-${{ matrix.code-target }}
121+
mv target/${{ matrix.target }}/release/jgf $JGF_BIN_NAME
122+
tar czf $JGF_BIN_NAME.tar.gz $JGF_BIN_NAME
123+
124+
- name: Upload Binary
125+
uses: actions/upload-artifact@v4
126+
with:
127+
if-no-files-found: error
128+
name: binaries-${{ matrix.code-target }}
129+
path: |
130+
*.zip
131+
*.tar.gz
132+
133+
publish:
134+
name: Publish
135+
needs: [check, build]
136+
runs-on: ubuntu-latest
137+
permissions:
138+
contents: write # for creating GitHub release
139+
id-token: write # for npm provenance
140+
steps:
141+
- uses: actions/checkout@v4
142+
with:
143+
fetch-depth: 0 # for changelog
144+
145+
- uses: actions/download-artifact@v4
146+
with:
147+
merge-multiple: true
148+
149+
- name: Unzip
150+
run: |
151+
find . -name "*.zip" -exec unzip -qq {} \;
152+
153+
- name: Untar
154+
run: |
155+
find . -name "*.tar.gz" -exec tar xf {} \;
156+
157+
- uses: actions/setup-node@v4
158+
with:
159+
node-version: '20'
160+
registry-url: 'https://registry.npmjs.org'
161+
162+
- name: Generate npm packages
163+
run: |
164+
node npm/jgf/scripts/generate-packages.mjs
165+
cat npm/jgf/package.json
166+
for package in npm/jgf*; do cat $package/package.json ; echo ; done
167+
168+
- name: Publish npm packages as latest
169+
# NOTE: The trailing slash on $package/ changes it to publishing the directory
170+
run: |
171+
for package in npm/jgf*
172+
do
173+
npm publish $package/ --provenance --access public
174+
echo '----'
175+
done
176+
env:
177+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
178+
179+
- name: Create GitHub Release
180+
uses: softprops/action-gh-release@v2
181+
with:
182+
draft: false
183+
files: jgf-*
184+
name: jgf v${{ needs.check.outputs.version }}
185+
tag_name: v${{ needs.check.outputs.version }}
186+
fail_on_unmatched_files: true
187+
target_commitish: ${{ github.sha }}
188+
189+
- name: Wait 3 minutes for smoke test
190+
run: sleep 180s
191+
192+
smoke:
193+
needs: [check, publish]
194+
strategy:
195+
matrix:
196+
include:
197+
- os: windows-latest
198+
- os: ubuntu-latest
199+
- os: ubuntu-latest
200+
container: node:18-alpine # musl
201+
- os: macos-latest
202+
name: Smoke Test ${{ matrix.os }} ${{ matrix.container }}
203+
runs-on: ${{ matrix.os }}
204+
container: ${{ matrix.container }}
205+
steps:
206+
- name: Test
207+
env:
208+
JGF_VERSION: ${{ needs.check.outputs.version}}
209+
run: |
210+
npx jgf@${JGF_VERSION} --version

NPM_SETUP.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# NPM Publishing Setup Guide
2+
3+
## 1. NPM Token 생성
4+
5+
1. [npmjs.com](https://www.npmjs.com)에 로그인
6+
2. Profile → Access Tokens → Generate New Token
7+
3. **Automation** 타입으로 생성 (Classic Token 사용)
8+
4. 토큰 복사 (다시 볼 수 없음)
9+
10+
## 2. GitHub Secret 설정
11+
12+
1. GitHub Repository → Settings → Secrets and variables → Actions
13+
2. **New repository secret** 클릭
14+
3. Name: `NPM_TOKEN`
15+
4. Secret: 위에서 복사한 NPM token 붙여넣기
16+
17+
## 3. 배포 프로세스
18+
19+
1. **버전 업데이트**:
20+
```bash
21+
# npm/jgf/package.json의 version 수정
22+
# Cargo.toml의 version도 동일하게 맞춤
23+
```
24+
25+
2. **버전 커밋**:
26+
```bash
27+
git add npm/jgf/package.json Cargo.toml
28+
git commit -m "feat: version 0.1.3"
29+
git push origin main
30+
```
31+
32+
3. **자동 배포**: GitHub Actions가 자동으로
33+
- 8개 플랫폼용 바이너리 빌드
34+
- npm 패키지들 생성 및 배포
35+
- GitHub Release 생성
36+
37+
## 4. 배포 확인
38+
39+
- Actions 탭에서 워크플로 진행 상황 확인
40+
- [npm](https://www.npmjs.com/package/jgf)에서 패키지 확인
41+
- 스모크 테스트로 설치/실행 확인
42+
43+
## 5. 사용자 설치
44+
45+
```bash
46+
npm install -g jgf
47+
jgf --version # 0.1.3 출력되어야 함
48+
```

0 commit comments

Comments
 (0)