Skip to content

Commit 89631a8

Browse files
authored
feat: attach binaries to github release (#33)
* feat: attach binaries to github release * fix: formatting issue * fix: exit gracefully if binaries do not exist
1 parent 0cf0e59 commit 89631a8

6 files changed

Lines changed: 191 additions & 6 deletions

File tree

.eslintrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"env": {
3-
"es6": true
3+
"es6": true,
4+
"node": true
45
},
56
"parserOptions": {
6-
"sourceType": "module",
7+
"ecmaVersion": 2018,
8+
"sourceType": "module"
79
},
810
"plugins": ["prettier"]
911
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,4 @@ rust_modules/
8383
# React Native Codegen
8484
ios/generated
8585
android/generated
86+
binaries.tar.gz

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
"ios",
2525
"cpp",
2626
"*.podspec",
27-
"build",
2827
"react-native.config.js",
2928
"swift",
29+
"scripts",
3030
"!ios/build",
3131
"!android/build",
3232
"!android/gradle",
@@ -59,7 +59,7 @@
5959
"clean": "del-cli -v android/build example/android/build example/android/app/build example/ios/build lib **/.cxx",
6060
"prepare": "bob build",
6161
"release": "release-it",
62-
"postinstall": "patch-package"
62+
"postinstall": "patch-package && node scripts/download-binaries.js"
6363
},
6464
"keywords": [
6565
"react-native",
@@ -100,6 +100,7 @@
100100
"react-native": "0.76.9",
101101
"react-native-builder-bob": "^0.31.0",
102102
"release-it": "^15.0.0",
103+
"tar": "^7.4.3",
103104
"turbo": "^1.10.7",
104105
"typescript": "^5.2.2",
105106
"uniffi-bindgen-react-native": "0.29.3-1"
@@ -136,7 +137,13 @@
136137
"publish": true
137138
},
138139
"github": {
139-
"release": true
140+
"release": true,
141+
"assets": [
142+
"binaries.tar.gz"
143+
]
144+
},
145+
"hooks": {
146+
"before:release": "node scripts/package-binaries.js"
140147
},
141148
"plugins": {
142149
"@release-it/conventional-changelog": {

scripts/download-binaries.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const https = require('https');
6+
const { execSync } = require('child_process');
7+
const tar = require('tar');
8+
9+
const PACKAGE_JSON = require('../package.json');
10+
const VERSION = PACKAGE_JSON.version;
11+
const REPO = 'unomed-dev/react-native-matrix-sdk';
12+
13+
async function downloadFile(url, dest) {
14+
return new Promise((resolve, reject) => {
15+
const file = fs.createWriteStream(dest);
16+
https.get(url, (response) => {
17+
if (response.statusCode === 302 || response.statusCode === 301) {
18+
// Follow redirect
19+
https.get(response.headers.location, (redirectResponse) => {
20+
redirectResponse.pipe(file);
21+
file.on('finish', () => {
22+
file.close(resolve);
23+
});
24+
}).on('error', reject);
25+
} else if (response.statusCode === 200) {
26+
response.pipe(file);
27+
file.on('finish', () => {
28+
file.close(resolve);
29+
});
30+
} else {
31+
reject(new Error(`HTTP ${response.statusCode}`));
32+
}
33+
}).on('error', reject);
34+
});
35+
}
36+
37+
async function downloadBinaries() {
38+
const buildDir = path.join(__dirname, '..', 'build');
39+
40+
// Check if binaries already exist
41+
if (fs.existsSync(path.join(buildDir, 'RnMatrixRustSdk.xcframework'))) {
42+
console.log('Binaries already exist, skipping download.');
43+
return;
44+
}
45+
46+
console.log(`Downloading binaries for v${VERSION}...`);
47+
48+
// Create build directory
49+
if (!fs.existsSync(buildDir)) {
50+
fs.mkdirSync(buildDir, { recursive: true });
51+
}
52+
53+
const releaseUrl = `https://github.com/${REPO}/releases/download/v${VERSION}/binaries.tar.gz`;
54+
const tempFile = path.join(buildDir, 'binaries.tar.gz');
55+
56+
try {
57+
// Download the binary archive
58+
console.log(`Downloading from ${releaseUrl}...`);
59+
await downloadFile(releaseUrl, tempFile);
60+
61+
// Extract the archive
62+
console.log('Extracting binaries...');
63+
await tar.x({
64+
file: tempFile,
65+
cwd: buildDir,
66+
});
67+
68+
// Clean up
69+
fs.unlinkSync(tempFile);
70+
71+
console.log('Binaries downloaded successfully!');
72+
} catch (error) {
73+
console.error('Failed to download binaries:', error.message);
74+
console.error('You may need to build the binaries locally using:');
75+
console.error(' yarn generate:release');
76+
// Exit gracefully if binaries do not exist
77+
process.exit(0);
78+
}
79+
}
80+
81+
if (require.main === module) {
82+
downloadBinaries().catch(console.error);
83+
}
84+
85+
module.exports = { downloadBinaries };

scripts/package-binaries.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const tar = require('tar');
6+
7+
async function packageBinaries() {
8+
const buildDir = path.join(__dirname, '..', 'build');
9+
const outputFile = path.join(__dirname, '..', 'binaries.tar.gz');
10+
11+
if (!fs.existsSync(path.join(buildDir, 'RnMatrixRustSdk.xcframework'))) {
12+
console.error('No binaries found in build directory. Run yarn generate:release first.');
13+
process.exit(1);
14+
}
15+
16+
console.log('Packaging binaries...');
17+
18+
await tar.c({
19+
gzip: true,
20+
file: outputFile,
21+
cwd: buildDir,
22+
}, ['.']);
23+
24+
const stats = fs.statSync(outputFile);
25+
const sizeMB = (stats.size / 1024 / 1024).toFixed(2);
26+
27+
console.log(`Binaries packaged successfully: ${outputFile} (${sizeMB} MB)`);
28+
}
29+
30+
if (require.main === module) {
31+
packageBinaries().catch(console.error);
32+
}
33+
34+
module.exports = { packageBinaries };

yarn.lock

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3030,6 +3030,15 @@ __metadata:
30303030
languageName: node
30313031
linkType: hard
30323032

3033+
"@isaacs/fs-minipass@npm:^4.0.0":
3034+
version: 4.0.1
3035+
resolution: "@isaacs/fs-minipass@npm:4.0.1"
3036+
dependencies:
3037+
minipass: ^7.0.4
3038+
checksum: 5d36d289960e886484362d9eb6a51d1ea28baed5f5d0140bbe62b99bac52eaf06cc01c2bc0d3575977962f84f6b2c4387b043ee632216643d4787b0999465bf2
3039+
languageName: node
3040+
linkType: hard
3041+
30333042
"@isaacs/ttlcache@npm:^1.4.1":
30343043
version: 1.4.1
30353044
resolution: "@isaacs/ttlcache@npm:1.4.1"
@@ -4564,6 +4573,7 @@ __metadata:
45644573
react-native: 0.76.9
45654574
react-native-builder-bob: ^0.31.0
45664575
release-it: ^15.0.0
4576+
tar: ^7.4.3
45674577
turbo: ^1.10.7
45684578
typescript: ^5.2.2
45694579
uniffi-bindgen-react-native: 0.29.3-1
@@ -5599,6 +5609,13 @@ __metadata:
55995609
languageName: node
56005610
linkType: hard
56015611

5612+
"chownr@npm:^3.0.0":
5613+
version: 3.0.0
5614+
resolution: "chownr@npm:3.0.0"
5615+
checksum: fd73a4bab48b79e66903fe1cafbdc208956f41ea4f856df883d0c7277b7ab29fd33ee65f93b2ec9192fc0169238f2f8307b7735d27c155821d886b84aa97aa8d
5616+
languageName: node
5617+
linkType: hard
5618+
56025619
"chrome-launcher@npm:^0.15.2":
56035620
version: 0.15.2
56045621
resolution: "chrome-launcher@npm:0.15.2"
@@ -11223,7 +11240,7 @@ __metadata:
1122311240
languageName: node
1122411241
linkType: hard
1122511242

11226-
"minipass@npm:^5.0.0 || ^6.0.2 || ^7.0.0, minipass@npm:^7.0.2, minipass@npm:^7.0.3, minipass@npm:^7.1.2":
11243+
"minipass@npm:^5.0.0 || ^6.0.2 || ^7.0.0, minipass@npm:^7.0.2, minipass@npm:^7.0.3, minipass@npm:^7.0.4, minipass@npm:^7.1.2":
1122711244
version: 7.1.2
1122811245
resolution: "minipass@npm:7.1.2"
1122911246
checksum: 2bfd325b95c555f2b4d2814d49325691c7bee937d753814861b0b49d5edcda55cbbf22b6b6a60bb91eddac8668771f03c5ff647dcd9d0f798e9548b9cdc46ee3
@@ -11240,6 +11257,15 @@ __metadata:
1124011257
languageName: node
1124111258
linkType: hard
1124211259

11260+
"minizlib@npm:^3.0.1":
11261+
version: 3.0.2
11262+
resolution: "minizlib@npm:3.0.2"
11263+
dependencies:
11264+
minipass: ^7.1.2
11265+
checksum: 493bed14dcb6118da7f8af356a8947cf1473289c09658e5aabd69a737800a8c3b1736fb7d7931b722268a9c9bc038a6d53c049b6a6af24b34a121823bb709996
11266+
languageName: node
11267+
linkType: hard
11268+
1124311269
"mkdirp@npm:^0.5.1":
1124411270
version: 0.5.6
1124511271
resolution: "mkdirp@npm:0.5.6"
@@ -11260,6 +11286,15 @@ __metadata:
1126011286
languageName: node
1126111287
linkType: hard
1126211288

11289+
"mkdirp@npm:^3.0.1":
11290+
version: 3.0.1
11291+
resolution: "mkdirp@npm:3.0.1"
11292+
bin:
11293+
mkdirp: dist/cjs/src/bin.js
11294+
checksum: 972deb188e8fb55547f1e58d66bd6b4a3623bf0c7137802582602d73e6480c1c2268dcbafbfb1be466e00cc7e56ac514d7fd9334b7cf33e3e2ab547c16f83a8d
11295+
languageName: node
11296+
linkType: hard
11297+
1126311298
"modify-values@npm:^1.0.0":
1126411299
version: 1.0.1
1126511300
resolution: "modify-values@npm:1.0.1"
@@ -13861,6 +13896,20 @@ __metadata:
1386113896
languageName: node
1386213897
linkType: hard
1386313898

13899+
"tar@npm:^7.4.3":
13900+
version: 7.4.3
13901+
resolution: "tar@npm:7.4.3"
13902+
dependencies:
13903+
"@isaacs/fs-minipass": ^4.0.0
13904+
chownr: ^3.0.0
13905+
minipass: ^7.1.2
13906+
minizlib: ^3.0.1
13907+
mkdirp: ^3.0.1
13908+
yallist: ^5.0.0
13909+
checksum: 8485350c0688331c94493031f417df069b778aadb25598abdad51862e007c39d1dd5310702c7be4a6784731a174799d8885d2fde0484269aea205b724d7b2ffa
13910+
languageName: node
13911+
linkType: hard
13912+
1386413913
"temp@npm:^0.8.4":
1386513914
version: 0.8.4
1386613915
resolution: "temp@npm:0.8.4"
@@ -14893,6 +14942,13 @@ __metadata:
1489314942
languageName: node
1489414943
linkType: hard
1489514944

14945+
"yallist@npm:^5.0.0":
14946+
version: 5.0.0
14947+
resolution: "yallist@npm:5.0.0"
14948+
checksum: eba51182400b9f35b017daa7f419f434424410691bbc5de4f4240cc830fdef906b504424992700dc047f16b4d99100a6f8b8b11175c193f38008e9c96322b6a5
14949+
languageName: node
14950+
linkType: hard
14951+
1489614952
"yaml@npm:^2.2.1":
1489714953
version: 2.6.0
1489814954
resolution: "yaml@npm:2.6.0"

0 commit comments

Comments
 (0)