This repository has been archived by the owner on Nov 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
83 lines (70 loc) · 2.47 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
77
78
79
80
81
82
83
import * as core from '@actions/core'
import ApiClient, { BenchmarkStatus, UploadStatusError, UploadRequest } from './ApiClient'
import { validateAppFile } from './app_file';
import { zipFolder, zipIfFolder } from './archive_utils';
import { getParameters } from './params';
import { existsSync } from 'fs';
import StatusPoller from './StatusPoller';
import { err, info } from './log';
const knownAppTypes = ['ANDROID_APK', 'IOS_BUNDLE']
const createWorkspaceZip = async (workspaceFolder: string | null): Promise<string | null> => {
const resolvedWorkspaceFolder = workspaceFolder || '.mobiledev'
if (!existsSync(resolvedWorkspaceFolder)) {
err(`Workspace directory does not exist: ${resolvedWorkspaceFolder}`)
return null
}
info("Packaging .mobiledev folder")
await zipFolder(resolvedWorkspaceFolder, 'workspace.zip');
return 'workspace.zip'
}
export const getConsoleUrl = (uploadId: string, teamId: string, appId: string): string => {
return `https://console.mobile.dev/uploads/${uploadId}?teamId=${teamId}&appId=${appId}`
}
const run = async () => {
const {
apiKey,
apiUrl,
name,
appFilePath,
mappingFile,
workspaceFolder,
branchName,
repoOwner,
repoName,
pullRequestId,
env,
async
} = await getParameters()
info('⛔️ DEPRECATED ⛔️ -- please use mobile-dev-inc/action-maestro-cloud instead')
const appFile = await validateAppFile(
await zipIfFolder(appFilePath)
);
if (!knownAppTypes.includes(appFile.type)) {
throw new Error(`Unsupported app file type: ${appFile.type}`)
}
const workspaceZip = await createWorkspaceZip(workspaceFolder)
const client = new ApiClient(apiKey, apiUrl)
info("Uploading to mobile.dev")
const request: UploadRequest = {
benchmarkName: name,
branch: branchName,
repoOwner: repoOwner,
repoName: repoName,
pullRequestId: pullRequestId,
env: env,
agent: 'gh-action'
}
const { uploadId, teamId, targetId: appId } = await client.uploadRequest(
request,
appFile.path,
workspaceZip,
mappingFile && await zipIfFolder(mappingFile),
)
const consoleUrl = getConsoleUrl(uploadId, teamId, appId)
info(`Visit the web console for more details about the upload: ${consoleUrl}\n`)
!async && new StatusPoller(client, uploadId, consoleUrl).startPolling()
info('⛔️ DEPRECATED ⛔️ -- please use mobile-dev-inc/action-maestro-cloud instead')
}
run().catch(e => {
core.setFailed(`Error running mobile.dev Upload Action: ${e.message}`)
})