forked from RGB-Tools/rgb-lib-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 2
275 lines (241 loc) · 9.14 KB
/
Copy pathrelease-branch.yml
File metadata and controls
275 lines (241 loc) · 9.14 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
name: Release from Branch
on:
workflow_dispatch:
inputs:
version:
description: 'Base version (e.g., 0.3.0-beta.9)'
required: true
type: string
suffix:
description: 'Branch suffix to append (e.g., branchname → v0.3.0-beta.9-branchname)'
required: true
type: string
rgb_lib_repo:
description: 'rgb-lib repo override (e.g., dcorral/rgb-lib). Leave empty for UTEXO-Protocol/rgb-lib'
required: false
type: string
rgb_lib_branch:
description: 'rgb-lib branch override (e.g., vss-backup). Leave empty for utexo-master'
required: false
type: string
jobs:
build:
name: Build (${{ matrix.platform }})
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-22.04
os: linux
cpu: x64
platform: linux-x64
target: x86_64-unknown-linux-gnu
lib_filename: librgblibcffi
lib_ext: so
- runner: ubuntu-22.04-arm
os: linux
cpu: arm64
platform: linux-arm64
target: aarch64-unknown-linux-gnu
lib_filename: librgblibcffi
lib_ext: so
- runner: macos-latest
os: darwin
cpu: arm64
platform: darwin-arm64
target: aarch64-apple-darwin
lib_filename: librgblibcffi
lib_ext: dylib
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Override rgb-lib submodule
if: inputs.rgb_lib_repo != '' || inputs.rgb_lib_branch != ''
run: |
REPO="${{ inputs.rgb_lib_repo || 'UTEXO-Protocol/rgb-lib' }}"
BRANCH="${{ inputs.rgb_lib_branch || 'utexo-master' }}"
cd rgb-lib
git remote set-url origin "https://github.com/${REPO}.git"
git fetch origin "$BRANCH"
git checkout FETCH_HEAD
cd ..
shell: bash
- name: Get full version
id: version
run: |
FULL_VERSION="${{ inputs.version }}.$(echo '${{ inputs.suffix }}' | tr '-' '.')"
echo "full_version=$FULL_VERSION" >> $GITHUB_OUTPUT
echo "Version: $FULL_VERSION"
shell: bash
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
- name: Install SWIG 4.2 (Linux)
if: matrix.os == 'linux'
run: |
sudo apt-get update
sudo apt-get install -y automake autoconf libtool bison byacc libpcre2-dev
git clone --depth 1 --branch v4.2.1 https://github.com/swig/swig.git /tmp/swig
cd /tmp/swig
./autogen.sh
./configure --prefix=/usr/local
make -j$(nproc)
sudo make install
swig -version
- name: Install SWIG (macOS)
if: matrix.os == 'darwin'
run: brew install swig
- name: Prepare platform package
id: prepare
run: |
PLATFORM="${{ matrix.platform }}"
PLATFORM_DIR="platforms/$PLATFORM"
TARGET="${{ matrix.target }}"
FILENAME="${{ matrix.lib_filename }}"
EXT="${{ matrix.lib_ext }}"
VERSION="${{ steps.version.outputs.full_version }}"
rm -rf "$PLATFORM_DIR"
mkdir -p platforms
cp -a template "$PLATFORM_DIR"
cp -a rgb-lib "$PLATFORM_DIR/"
sed -i.bak "s/%TARGET%/$TARGET/g" "$PLATFORM_DIR/binding.gyp"
sed -i.bak "s/%PLATFORM%/$PLATFORM/g" "$PLATFORM_DIR/package.json"
sed -i.bak "s/%OS%/${{ matrix.os }}/g" "$PLATFORM_DIR/package.json"
sed -i.bak "s/%CPU%/${{ matrix.cpu }}/g" "$PLATFORM_DIR/package.json"
sed -i.bak "s/%FILENAME%/$FILENAME/g" "$PLATFORM_DIR/package.json"
sed -i.bak "s/%EXTENSION%/$EXT/g" "$PLATFORM_DIR/package.json"
sed -i.bak "s/%TARGET%/$TARGET/g" "$PLATFORM_DIR/package.json"
sed -i.bak "s/%VERSION%/$VERSION/g" "$PLATFORM_DIR/package.json"
sed -i.bak "s/%OS%/${{ matrix.os }}/g" "$PLATFORM_DIR/README.md"
sed -i.bak "s/%CPU%/${{ matrix.cpu }}/g" "$PLATFORM_DIR/README.md"
find "$PLATFORM_DIR" -name "*.bak" -delete
echo "platform_dir=$PLATFORM_DIR" >> $GITHUB_OUTPUT
shell: bash
- name: Build Rust library (c-ffi)
working-directory: ${{ steps.prepare.outputs.platform_dir }}/rgb-lib/bindings/c-ffi
run: cargo build --release --target ${{ matrix.target }} --features camel_case,vss
- name: Generate SWIG wrapper
working-directory: ${{ steps.prepare.outputs.platform_dir }}
run: swig -c++ -javascript -node swig.i
- name: Build native Node.js module
working-directory: ${{ steps.prepare.outputs.platform_dir }}
run: |
npm install -g node-gyp
npm install --ignore-scripts
node-gyp configure
node-gyp build
- name: Publish platform package to npm
working-directory: ${{ steps.prepare.outputs.platform_dir }}
run: npm publish --access public --tag ${{ inputs.suffix }} || echo "Package version may already exist, continuing..."
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Package artifact
run: |
PLATFORM="${{ matrix.platform }}"
cd platforms
tar -czvf ../rgb-lib-nodejs-$PLATFORM.tar.gz $PLATFORM
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: rgb-lib-nodejs-${{ matrix.platform }}
path: rgb-lib-nodejs-${{ matrix.platform }}.tar.gz
retention-days: 5
publish-main-package:
name: Publish Main Package
needs: build
if: always() && !cancelled()
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
- name: Get full version
id: version
run: |
FULL_VERSION="${{ inputs.version }}.$(echo '${{ inputs.suffix }}' | tr '-' '.')"
echo "full_version=$FULL_VERSION" >> $GITHUB_OUTPUT
- name: Update package.json version
run: |
VERSION="${{ steps.version.outputs.full_version }}"
cat > package.json <<'PKGJSON'
{
"name": "@utexo/rgb-lib",
"version": "PLACEHOLDER_VERSION",
"description": "Node.js bindings for rgb-lib",
"main": "index.js",
"files": ["index.js"],
"scripts": {"test": "echo \"No tests\" && exit 1"},
"repository": {"type": "git", "url": "git+https://github.com/UTEXO-Protocol/rgb-lib-nodejs.git"},
"keywords": ["rgb", "bitcoin"],
"author": "UTEXO Protocol",
"license": "MIT",
"optionalDependencies": {
"@utexo/rgb-lib-linux-x64": "PLACEHOLDER_VERSION",
"@utexo/rgb-lib-linux-arm64": "PLACEHOLDER_VERSION",
"@utexo/rgb-lib-darwin-arm64": "PLACEHOLDER_VERSION"
}
}
PKGJSON
sed -i 's/^ *//' package.json
sed -i "s/PLACEHOLDER_VERSION/$VERSION/g" package.json
cat package.json
- name: Publish main package to npm
run: npm publish --access public --tag ${{ inputs.suffix }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
release:
name: Create GitHub Release
needs: [build, publish-main-package]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Get full version
id: version
run: echo "full_version=v${{ inputs.version }}.$(echo '${{ inputs.suffix }}' | tr '-' '.')" >> $GITHUB_OUTPUT
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Prepare release assets
run: |
mkdir -p release-assets
find artifacts -name "*.tar.gz" -exec cp {} release-assets/ \;
ls -la release-assets/
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.full_version }}
name: Release ${{ steps.version.outputs.full_version }}
body: |
## Node.js bindings for rgb-lib (branch build)
Version: `${{ steps.version.outputs.full_version }}`
Branch: `${{ github.ref_name }}`
### Installation
```bash
npm install @utexo/rgb-lib@${{ steps.version.outputs.full_version }}
```
### Platforms
- Linux x64
- Linux ARM64
- macOS ARM64 (Apple Silicon)
draft: false
prerelease: true
files: release-assets/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}