-
Notifications
You must be signed in to change notification settings - Fork 16
/
trigger-pipeline.ts
57 lines (50 loc) · 1.56 KB
/
trigger-pipeline.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
import { program } from 'commander'
import fetch from 'node-fetch'
import { MAIN_BRANCH } from './constants.js'
const CIRCLECI_URL = 'https://circleci.com/api/v2/project/github/digitalfabrik/integreat-app/pipeline'
const WORKFLOW_TYPES = [
'none',
'native_beta_delivery',
'native_production_delivery',
'native_promotion',
'web_beta_delivery',
'web_production_delivery',
'web_promotion',
'delivery',
'e2e_tests',
]
program
.command('trigger <workflow-type>')
.description(`trigger a workflow in the ci on the main branch`)
.requiredOption('--api-token <api-token>', 'circleci api token')
.option('--branch <branch>', 'the branch the workflow will be triggered on', MAIN_BRANCH)
.action(async (workflowType: string, options: { apiToken: string; branch: string }) => {
const { apiToken, branch } = options
try {
if (!WORKFLOW_TYPES.includes(workflowType)) {
throw new Error(`Only the following workflow types are supported: ${WORKFLOW_TYPES}`)
}
const postData = {
branch,
parameters: {
api_triggered: true,
workflow_type: workflowType,
},
}
const response = await fetch(CIRCLECI_URL, {
method: 'POST',
body: JSON.stringify(postData),
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
'Circle-Token': apiToken,
},
})
const json = await response.json()
console.log(json)
} catch (e) {
console.error(e)
process.exit(1)
}
})
program.parse(process.argv)