-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
76 lines (70 loc) · 2 KB
/
index.ts
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
import ApiClient from './ApiClient'
import { getParameters } from './params';
import path from 'path';
import { exec } from 'child_process';
async function asyncExec(command: string) {
return new Promise<void>(function(resolve, reject) {
exec(command, (error, stdout, stderr) => {
if (error) {
reject(error);
return;
}
console.error(stderr)
console.log(stdout)
resolve();
});
});
}
async function zipDir(dir: string, output: string) {
const name = path.basename(dir)
const parent = path.join(dir, '..')
await asyncExec(`cd "${parent}" && zip -r "${output}" "${name}"`)
}
async function run() {
const {
apiKey,
apiUrl,
name,
appFile,
mappingFile,
branchName,
repoOwner,
repoName,
pullRequestId
} = await getParameters()
const client = new ApiClient(apiKey, apiUrl)
if (appFile.type === 'ANDROID_APK') {
const { id: appId } = await client.uploadApp(appFile.path, 'apk');
if (mappingFile) await client.uploadMapping(mappingFile, appId)
await client.createAnalysisRequest({
benchmarkName: name,
apkId: appId,
branch: branchName,
repoOwner: repoOwner,
repoName: repoName,
pullRequestId: pullRequestId
})
} else if (appFile.type === 'IOS_APP_ZIP' || appFile.type === 'IOS_APP_DIR') {
let appFilePath = appFile.path
if (appFile.type === 'IOS_APP_DIR') {
await zipDir(appFile.path, '/tmp/app.zip')
appFilePath = '/tmp/app.zip'
}
const { id: appId } = await client.uploadApp(appFilePath, 'iosAppBinary');
const response = await client.createAnalysisRequest({
benchmarkName: name,
iosAppBinaryId: appId,
branch: branchName,
repoOwner: repoOwner,
repoName: repoName,
pullRequestId: pullRequestId
})
console.log(response)
} else {
throw new Error(`Unsupported app file type: ${appFile.type}`)
}
}
run().catch(e => {
console.error(`Error running mobile.dev Upload Action: ${e.message}`)
process.exit(1)
})