forked from digitalfabrik/integreat-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrigger-pipeline.ts
52 lines (45 loc) · 1.35 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
import { program } from 'commander'
import fetch from 'node-fetch'
import { MAIN_BRANCH } from './constants'
const CIRCLECI_URL = 'https://circleci.com/api/v2/project/github/digitalfabrik/integreat-app/pipeline'
const WORKFLOW_TYPES = [
'none',
'native_development_delivery',
'native_production_delivery',
'native_promotion',
'web_production_delivery',
'delivery'
]
program.requiredOption('--api-token <api-token>', 'circleci api token')
program
.command('trigger <workflow-type>')
.description(`trigger a workflow in the ci on the main branch`)
.action(async (workflowType: string) => {
try {
if (!WORKFLOW_TYPES.includes(workflowType)) {
throw new Error(`Only the following workflow types are supported: ${WORKFLOW_TYPES}`)
}
const postData = {
branch: MAIN_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': program.apiToken
}
})
const json = await response.json()
console.log(json)
} catch (e) {
console.error(e)
process.exit(1)
}
})
program.parse(process.argv)