forked from mobile-dev-inc/action-maestro-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
117 lines (104 loc) · 3.46 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
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
import * as core from '@actions/core'
import ApiClient, { UploadRequest } from './ApiClient'
import { validateAppFile } from './app_file';
import { zipFolder, zipIfFolder } from './archive_utils';
import { getParameters } from './params';
import { existsSync, readdirSync } from 'fs';
import StatusPoller from './StatusPoller';
import { info } from './log';
const knownAppTypes = ['ANDROID_APK', 'IOS_BUNDLE']
const listFilesInDirectory = () => {
const files = readdirSync('.', { withFileTypes: true })
console.log("Directory contents:")
for (const f of files) {
console.log(f.isDirectory() ? `${f.name}/` : f.name)
}
}
const createWorkspaceZip = async (workspaceFolder: string | null): Promise<string | null> => {
let resolvedWorkspaceFolder = workspaceFolder
if (resolvedWorkspaceFolder === null || workspaceFolder?.length === 0) {
if (existsSync('.maestro')) {
resolvedWorkspaceFolder = '.maestro'
info("Packaging .maestro folder")
} else if (existsSync('.mobiledev')) {
resolvedWorkspaceFolder = '.mobiledev'
info("Packaging .mobiledev folder")
} else {
listFilesInDirectory()
throw new Error("Default workspace directory does not exist: .maestro/")
}
} else if (!existsSync(resolvedWorkspaceFolder)) {
throw new Error(`Workspace directory does not exist: ${resolvedWorkspaceFolder}`)
}
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,
commitSha,
repoOwner,
repoName,
pullRequestId,
env,
async,
androidApiLevel,
iOSVersion,
includeTags,
excludeTags,
appBinaryId,
deviceLocale,
timeout,
} = await getParameters()
let appFile = null
if (appFilePath !== "") {
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 Maestro Cloud")
const request: UploadRequest = {
benchmarkName: name,
branch: branchName,
commitSha: commitSha,
repoOwner: repoOwner,
repoName: repoName,
pullRequestId: pullRequestId,
env: env,
agent: 'github',
androidApiLevel: androidApiLevel,
iOSVersion: iOSVersion,
includeTags: includeTags,
excludeTags: excludeTags,
appBinaryId: appBinaryId || undefined,
deviceLocale: deviceLocale || undefined,
}
const { uploadId, teamId, targetId: appId, appBinaryId: uploadedBinaryId } = await client.uploadRequest(
request,
appFile && 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`)
core.setOutput('MAESTRO_CLOUD_CONSOLE_URL', consoleUrl)
core.setOutput('MAESTRO_CLOUD_APP_BINARY_ID', uploadedBinaryId)
!async && new StatusPoller(client, uploadId, consoleUrl).startPolling(timeout)
}
run().catch(e => {
core.setFailed(`Error running Maestro Cloud Upload Action: ${e.message}`)
})