-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathindex.ts
More file actions
126 lines (116 loc) · 3.48 KB
/
index.ts
File metadata and controls
126 lines (116 loc) · 3.48 KB
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
118
119
120
121
122
123
124
125
126
import * as core from '@actions/core'
import ApiClient, {
UploadRequest,
UploadResponse,
} 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'
}
const run = async () => {
const {
apiKey,
apiUrl,
name,
appFilePath,
mappingFile,
workspaceFolder,
branchName,
commitSha,
repoOwner,
repoName,
pullRequestId,
env,
async,
androidApiLevel,
iOSVersion,
includeTags,
excludeTags,
appBinaryId,
deviceLocale,
deviceModel,
deviceOs,
timeout,
projectId,
} = await getParameters()
let appFile = null
if (appFilePath !== '' && deviceOs !== 'web') {
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, projectId)
info('Uploading to Maestro Cloud')
const request: UploadRequest = {
benchmarkName: name,
projectId: projectId,
repoOwner: repoOwner,
repoName: repoName,
agent: 'github',
branch: branchName,
commitSha: commitSha,
pullRequestId: pullRequestId,
env: env,
androidApiLevel: androidApiLevel,
iOSVersion: iOSVersion,
includeTags: includeTags,
excludeTags: excludeTags,
appBinaryId: appBinaryId || undefined,
deviceLocale: deviceLocale || undefined,
deviceModel: deviceModel || undefined,
deviceOs: deviceOs || undefined,
}
const {
uploadId,
appId,
appBinaryId: appBinaryIdResponse,
}: UploadResponse = await client.cloudUploadRequest(
request,
appFile && appFile.path,
workspaceZip,
mappingFile && (await zipIfFolder(mappingFile))
)
const consoleUrl = `https://app.maestro.dev/project/${projectId}/maestro-test/app/${appId}/upload/${uploadId}`
core.setOutput('MAESTRO_CLOUD_CONSOLE_URL', consoleUrl)
core.setOutput('MAESTRO_CLOUD_APP_BINARY_ID', appBinaryIdResponse)
!async &&
new StatusPoller(client, uploadId, consoleUrl).startPolling(timeout)
}
run().catch((e) => {
core.setFailed(`Error running Maestro Cloud Upload Action: ${e.message}`)
})