-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathpost.js
More file actions
91 lines (80 loc) · 3.1 KB
/
post.js
File metadata and controls
91 lines (80 loc) · 3.1 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
import * as core from '@actions/core'
import {retry} from '@octokit/plugin-retry'
import * as github from '@actions/github'
import {context} from '@actions/github'
import {stringToArray} from './string-to-array'
import {contextCheck} from './context-check'
import {checkInput} from './check-input'
import {postDeploy} from './post-deploy'
import {COLORS} from './colors'
import {VERSION} from '../version'
export async function post() {
try {
const token = core.getState('actionsToken')
const bypass = core.getState('bypass') === 'true'
const skip_completing = core.getBooleanInput('skip_completing')
const data = {
sha: core.getState('sha'),
ref: core.getState('ref'),
comment_id: core.getState('comment_id'),
reaction_id: core.getState('reaction_id'),
noop: core.getState('noop') === 'true',
deployment_id: core.getState('deployment_id'),
environment: core.getState('environment'),
environment_url: checkInput(core.getState('environment_url')),
approved_reviews_count: core.getState('approved_reviews_count'),
review_decision: core.getState('review_decision'),
status: core.getInput('status'),
fork: core.getState('fork') === 'true',
params: core.getState('params'),
parsed_params: core.getState('parsed_params'),
labels: {
successful_deploy: stringToArray(
core.getInput('successful_deploy_labels')
),
successful_noop: stringToArray(core.getInput('successful_noop_labels')),
failed_deploy: stringToArray(core.getInput('failed_deploy_labels')),
failed_noop: stringToArray(core.getInput('failed_noop_labels')),
skip_successful_noop_labels_if_approved: core.getBooleanInput(
'skip_successful_noop_labels_if_approved'
),
skip_successful_deploy_labels_if_approved: core.getBooleanInput(
'skip_successful_deploy_labels_if_approved'
)
},
commit_verified: core.getState('commit_verified') === 'true',
deployment_start_time: core.getState('deployment_start_time')
}
// If bypass is set, exit the workflow
if (bypass) {
core.warning(`⛔ ${COLORS.highlight}bypass${COLORS.reset} set, exiting`)
return
}
// Check the context of the event to ensure it is valid, return if it is not
if (!(await contextCheck(context))) {
return
}
// Skip the process of completing a deployment, return
if (skip_completing) {
core.info(
`⏩ ${COLORS.highlight}skip_completing${COLORS.reset} set, exiting`
)
return
}
// Create an octokit client with the retry plugin
const octokit = github.getOctokit(token, {
userAgent: `github/branch-deploy@${VERSION}`,
additionalPlugins: [retry]
})
core.info(`🧑🚀 commit SHA: ${COLORS.highlight}${data.sha}${COLORS.reset}`)
// Set the environment_url
if (data.environment_url === null) {
core.debug('environment_url not set, its value is null')
}
await postDeploy(context, octokit, data)
return
} catch (error) {
core.error(error.stack)
core.setFailed(error.message)
}
}