1+ name : NPM Release
2+
3+ on :
4+ release :
5+ types : [published]
6+ push :
7+ branches :
8+ - develop
9+ paths :
10+ - ' libCacheSim-node/**'
11+
12+ env :
13+ BUILD_TYPE : Release
14+
15+ jobs :
16+ create-release :
17+ if : github.event_name == 'release'
18+ runs-on : ubuntu-latest
19+ outputs :
20+ release_created : ${{ steps.release.outputs.release_created }}
21+ version : ${{ steps.package.outputs.version }}
22+
23+ steps :
24+ - name : Checkout code
25+ uses : actions/checkout@v4
26+
27+ - name : Synchronize Node.js binding version
28+ run : |
29+ echo "Synchronizing Node.js binding version with main project..."
30+ python3 scripts/sync_node_version.py
31+
32+ - name : Get package version
33+ id : package
34+ working-directory : libCacheSim-node
35+ run : |
36+ VERSION=$(node -p "require('./package.json').version")
37+ echo "version=$VERSION" >> $GITHUB_OUTPUT
38+ echo "Version: $VERSION"
39+
40+ - name : Check if release exists
41+ id : check_release
42+ run : |
43+ VERSION="${{ steps.package.outputs.version }}"
44+ if gh release view "v$VERSION" > /dev/null 2>&1; then
45+ echo "Release v$VERSION already exists"
46+ echo "exists=true" >> $GITHUB_OUTPUT
47+ else
48+ echo "Release v$VERSION does not exist"
49+ echo "exists=false" >> $GITHUB_OUTPUT
50+ fi
51+ env :
52+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
53+
54+ - name : Create GitHub Release
55+ id : release
56+ if : steps.check_release.outputs.exists == 'false'
57+ uses : actions/create-release@v1
58+ env :
59+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
60+ with :
61+ tag_name : v${{ steps.package.outputs.version }}
62+ release_name : Release v${{ steps.package.outputs.version }}
63+ body : |
64+ Release v${{ steps.package.outputs.version }}
65+
66+ ## Installation
67+ ```bash
68+ npm install libcachesim-node
69+ ```
70+
71+ ## Supported Platforms
72+ - Linux x64
73+
74+ Pre-compiled binaries are automatically downloaded during installation.
75+ draft : false
76+ prerelease : false
77+
78+ build-and-publish :
79+ if : github.event_name == 'release'
80+ needs : create-release
81+ runs-on : ubuntu-latest
82+
83+ steps :
84+ - name : Checkout code
85+ uses : actions/checkout@v4
86+ with :
87+ fetch-depth : 0
88+
89+ - name : Synchronize Node.js binding version
90+ run : |
91+ echo "Synchronizing Node.js binding version with main project..."
92+ python3 scripts/sync_node_version.py
93+
94+ - name : Setup Node.js
95+ uses : actions/setup-node@v4
96+ with :
97+ node-version : ' 18'
98+ registry-url : ' https://registry.npmjs.org'
99+
100+ - name : Install system dependencies
101+ run : |
102+ sudo apt-get update
103+ sudo apt-get install -y build-essential cmake libglib2.0-dev libzstd-dev
104+
105+ - name : Build libCacheSim
106+ run : |
107+ echo "Building libCacheSim for Linux x64..."
108+ mkdir -p _build
109+ cd _build
110+ cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} .. -DCMAKE_VERBOSE_MAKEFILE=ON
111+ echo "Starting build..."
112+ make -j$(nproc) VERBOSE=1
113+
114+ - name : Prepare vendored library
115+ run : |
116+ mkdir -p libCacheSim-node/vendor/include
117+ cp _build/liblibCacheSim.a libCacheSim-node/vendor/
118+ cp -r libCacheSim/include/* libCacheSim-node/vendor/include/
119+
120+ - name : Install Node.js dependencies
121+ working-directory : libCacheSim-node
122+ run : npm install
123+
124+ - name : Build and upload prebuilt binary
125+ working-directory : libCacheSim-node
126+ run : |
127+ echo "Building Node.js addon for Linux x64..."
128+ echo "Node.js version: $(node --version)"
129+ echo "NPM version: $(npm --version)"
130+ ls -la ../
131+ ls -la ../_build/
132+ CFLAGS=-fPIC CXXFLAGS=-fPIC npx prebuild --upload-all --verbose
133+ env :
134+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
135+
136+ - name : Test binary
137+ working-directory : libCacheSim-node
138+ run : |
139+ echo "Testing binary load for Linux x64..."
140+ ls -la
141+ ls -la prebuilds/ || echo "No prebuilds directory found"
142+ node -e "console.log('Testing binary load...'); try { require('./index.js'); console.log('Binary loaded successfully!'); } catch(e) { console.error('Failed to load binary:', e); process.exit(1); }"
143+
144+ publish-npm :
145+ if : github.event_name == 'release'
146+ needs : build-and-publish
147+ runs-on : ubuntu-latest
148+
149+ steps :
150+ - name : Checkout code
151+ uses : actions/checkout@v4
152+
153+ - name : Synchronize Node.js binding version
154+ run : |
155+ echo "Synchronizing Node.js binding version with main project..."
156+ python3 scripts/sync_node_version.py
157+
158+ - name : Setup Node.js
159+ uses : actions/setup-node@v4
160+ with :
161+ node-version : ' 18'
162+ registry-url : ' https://registry.npmjs.org'
163+
164+ - name : Install system dependencies
165+ run : |
166+ sudo apt-get update
167+ sudo apt-get install -y build-essential cmake libglib2.0-dev libzstd-dev
168+
169+ - name : Build libCacheSim
170+ run : |
171+ mkdir -p _build
172+ cd _build
173+ cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} ..
174+ make -j$(nproc)
175+
176+ - name : Prepare vendored library
177+ run : |
178+ mkdir -p libCacheSim-node/vendor/include
179+ cp _build/liblibCacheSim.a libCacheSim-node/vendor/
180+ cp -r libCacheSim/include/* libCacheSim-node/vendor/include/
181+
182+
183+ - name : Publish to NPM
184+ working-directory : libCacheSim-node
185+ run : npm publish --access public
186+ env :
187+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
0 commit comments