-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
81 lines (68 loc) · 1.82 KB
/
index.js
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
import axios from 'axios'
import {
getInput,
getMultilineInput,
setFailed,
setOutput,
} from '@actions/core'
import { context } from '@actions/github'
const appId = getInput('app-id')
const workflowId = getInput('workflow-id')
const token = getInput('token')
const labels = getMultilineInput('labels')
let branch = getInput('branch')
let tag = getInput('tag')
if (!branch && !tag) {
const { ref } = context
branch = ref.split('refs/heads/')[1] || process.env.GITHUB_HEAD_REF
tag = ref.split('refs/tags/')[1]
}
const variables = Object.keys(process.env).reduce((variables, variable) => {
if (variable.startsWith('CM_')) {
variables[variable.substring(3)] = process.env[variable]
}
return variables
}, {})
const softwareVersions = [
'xcode',
'flutter',
'cocoapods',
'node',
'npm',
'ndk',
'java',
'ruby',
].reduce((softwareVersions, software) => {
const version = getInput(software)
if (version) {
softwareVersions[software] = version
}
return softwareVersions
}, {})
const url = 'https://api.codemagic.io/builds'
const payload = {
appId,
workflowId,
labels,
branch,
tag,
environment: { variables, softwareVersions },
}
const headers = {
'x-auth-token': token,
}
try {
const response = await axios.post(url, payload, { headers })
const { buildId } = await response.data
setOutput('build-id', buildId)
setOutput('build-api-url', `https://api.codemagic.io/builds/${buildId}`)
setOutput('build-url', `https://codemagic.io/app/${appId}/build/${buildId}`)
} catch (error) {
let details = null
if (error.response.status === 403) {
details = 'Either app ID or token is incorrect'
} else {
details = error.response.data.error
}
setFailed(`${error.message}: ${details}`)
}