generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
64 lines (57 loc) · 1.86 KB
/
main.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
import * as core from '@actions/core'
import { check, checkOrWait } from './wait.js'
import { getLock, getLocks, setLock } from './semaphore.js'
import { GitHub } from './github.js'
import * as _ from 'lodash'
const https = require('https')
const octoAuth = require('@octokit/auth-action')
const Request = require('@octokit/request')
const component = core.getInput('component')
/**
* The main function for the action.
* @returns {Promise<void>} Resolves when the action is complete.
*/
export async function run(): Promise<void> {
try {
if (core.getInput('pull_request') != '') {
const github = new GitHub()
await github.performAuth()
const labels = await github.getLabels()
const url = await github.getPRUrl()
if (
!_.includes(labels, 'auto deploy') &&
_.includes(labels, 'manual deploy')
) {
let lock = await getLock(component + '_deploy')
// No lock, we need to lock deployment
if (!lock) {
try {
const { data } = await setLock(component + '_deploy', url)
lock = data.data
core.setOutput(
'lock_msg',
'Manual deployment enabled! Automatic deployment disabled!'
)
core.setOutput('github_pr', url)
} catch (error) {
console.log(error)
}
} else {
core.setOutput(
'lock_msg',
'Deployment already locked! Please check PR!'
)
core.setOutput('github_pr', lock.purpose)
}
// Manual deployment, so deployment is not permitted
core.setOutput('deployment_lock', lock.id)
core.setOutput('github_pr', url)
}
} else {
await checkOrWait()
}
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)
}
}