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