generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
55 lines (47 loc) · 1.46 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
import * as core from '@actions/core'
import { checkOrWait } from './wait.js'
import { 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()
if (
!_.includes(labels, 'auto deploy') &&
_.includes(labels, 'manual deploy')
) {
let lock = await getLock()
// No lock, we need to lock deployment
if (!lock) {
const { result } = await setLock(component)
console.log(result)
lock = result
}
// Manual deployment, so deployment is not permitted
core.setOutput('deployment_lock', lock.id)
}
}
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)
}
}
export async function getLock() {
// Manual deployment, check locks
const locks = (await getLocks(component)).data.data
return _.find(locks, {
component: component,
unlocked_by: null
})
}