Skip to content

Commit 6d17659

Browse files
feat:add upload symbol files command (#1137)
* chore(android): bump sdk to v12.7.1 (#1134) * feat:add-upload-so-files-command * feat:add-upload-so-files-command * fix: add file path check * feat: add file validations * feat: add file validations * chore: format UploadSoFiles.ts * chore: add changes in changeLog --------- Co-authored-by: Ahmed Mahmoud <[email protected]>
1 parent 9b86a46 commit 6d17659

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Added
66

7+
- Adds symbol files upload script ([#1137](https://github.com/Instabug/Instabug-React-Native/pull/1137))
78
- Support enabling NDK crash capturing on Android ([#1132](https://github.com/Instabug/Instabug-React-Native/pull/1132)).
89

910
## [12.7.1](https://github.com/Instabug/Instabug-React-Native/compare/v12.7.0...v12.7.1) (February 15, 2024)

cli/UploadSoFiles.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import axios from 'axios';
2+
import { Command, Option } from 'commander';
3+
import FormData from 'form-data';
4+
import fs from 'fs';
5+
6+
interface UploadSoFilesOptions {
7+
arch: 'x86' | 'x86_64' | 'arm64-v8a' | 'armeabi-v7a';
8+
file: string;
9+
token: string;
10+
name: string;
11+
api_key: string;
12+
}
13+
/**
14+
* This script uploads .so files to the specified endpoint used in NDK crash reporting.
15+
* Usage: node upload-so-files.js --arch <arch> --file <path> --api_key <key> --token <token> --name <name>
16+
*/
17+
18+
export const UploadSoFilesCommand = new Command();
19+
20+
UploadSoFilesCommand.name('upload-so-files')
21+
.addOption(
22+
new Option('-arch, --arch <value>', 'arch')
23+
.choices(['x86', 'x86_64', 'arm64-v8a', 'armeabi-v7a'])
24+
.makeOptionMandatory(),
25+
)
26+
.addOption(
27+
new Option(
28+
'-f, --file <path>',
29+
'The path of the symbol files in Zip format',
30+
).makeOptionMandatory(),
31+
)
32+
.addOption(new Option('--api_key <value>', 'Your App key').makeOptionMandatory())
33+
.addOption(
34+
new Option('-t, --token <value>', 'Your App Token')
35+
.env('INSTABUG_APP_TOKEN')
36+
.makeOptionMandatory(),
37+
)
38+
.addOption(
39+
new Option('-n, --name <value>', 'The app version name')
40+
.env('INSTABUG_APP_VERSION_NAME')
41+
.makeOptionMandatory(),
42+
)
43+
.action(function (this: Command) {
44+
const options = this.opts<UploadSoFilesOptions>();
45+
UploadSoFiles(options);
46+
})
47+
.showHelpAfterError();
48+
49+
const UploadSoFiles = async (opts: UploadSoFilesOptions) => {
50+
const fileName = opts.file;
51+
if (fileName == null) {
52+
console.error('Failed to upload So Files: invalid file path');
53+
process.exit(1);
54+
}
55+
56+
if (fs.existsSync(fileName) === false) {
57+
console.error('Failed to upload So Files: File not found');
58+
process.exit(1);
59+
}
60+
var fileExt = fileName.split('.').pop();
61+
62+
if (fileExt !== 'zip') {
63+
console.error('Failed to upload So Files: You can only upload ZIP files');
64+
process.exit(1);
65+
}
66+
67+
const fileBlob = fs.readFileSync(opts.file);
68+
69+
const form = new FormData();
70+
form.append('app_version', opts.name);
71+
form.append('so_file', fileBlob, fileName);
72+
form.append('application_token', opts.token);
73+
form.append('api_key', opts.api_key);
74+
form.append('arch', opts.arch);
75+
76+
console.log('Uploading So files...');
77+
const uploadEndpoint = 'https://api.instabug.com/api/web/public/so_files';
78+
try {
79+
await axios.post(uploadEndpoint, form, {
80+
headers: form.getHeaders(),
81+
});
82+
83+
console.log(`Successfully uploaded So Files for version: ${opts.name} with arch ${opts.arch}`);
84+
} catch (err) {
85+
console.error('Failed to upload So Files:', axios.isAxiosError(err) ? err.response?.data : err);
86+
process.exit(1);
87+
}
88+
};

cli/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { Command } from 'commander';
33

44
import { uploadSourcemapsCommand } from './UploadSourcemaps';
5+
import { UploadSoFilesCommand } from './UploadSoFiles';
56

67
const program = new Command();
78

@@ -10,6 +11,7 @@ program
1011
.version('1.0.0-beta1')
1112
.description('A CLI for uploading source maps to Instabug dashboard.')
1213
.usage('[command]')
13-
.addCommand(uploadSourcemapsCommand);
14+
.addCommand(uploadSourcemapsCommand)
15+
.addCommand(UploadSoFilesCommand);
1416

1517
program.parse(process.argv);

0 commit comments

Comments
 (0)