-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (95 loc) · 3.18 KB
/
cd-workflow.yml
File metadata and controls
101 lines (95 loc) · 3.18 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
92
93
94
95
96
97
98
99
100
101
name: cd-workflow
on:
pull_request:
types:
- opened
- synchronize
jobs:
ready-for-release:
runs-on: ubuntu-latest
environment: qa
steps:
- name: say "ready"
run: echo ready
# triggered by an external API call
pre-release-checks:
needs: ready-for-release
runs-on: ubuntu-latest
steps:
- name: say "checked"
run: echo checked
# check CI checks are passing
should-queue:
needs: pre-release-checks
runs-on: ubuntu-latest
steps:
- name: check existing runs
id: in-progress-runs
uses: actions/github-script@v5
with:
github-token: ${{ secrets.REPO_ACCESS_TOKEN }}
script: |
const { data: { workflow_runs }} = await github.rest.actions.listWorkflowRuns({
owner: 'ebk45',
repo: 'github-actions',
workflow_id: context.workflow + '.yml',
status: 'in_progress'
});
console.log("Existing workflows = ", workflow_runs.length)
return workflow_runs.length
result-encoding: string
- name: self approve workflow
if: ${{ steps.in-progress-runs.outputs.result == 0 }}
uses: actions/github-script@v5
with:
github-token: ${{ secrets.REPO_ACCESS_TOKEN }}
script: |
await github.rest.actions.reviewPendingDeploymentsForRun({
owner: 'ebk45',
repo: 'github-actions',
run_id: context.runId,
environment_ids: [394310963],
state: 'approved',
comment: 'approved to deploy to QA',
});
console.log("Workflow has been self approved")
# check if there's an another release currently running
# if yes - this job will pass and not do anything
# if no - this job will make an API call to approve the next job (deploy-to-qa)
# get the run id - github.run_id
# make a call to /repos/ebk45/github-actions/actions/runs/{run_id}/pending_deployments
deploy-to-qa:
needs: [pre-release-checks]
environment: qa
runs-on: ubuntu-latest
steps:
- name: say "ready"
run: echo ready
approve-next-workflow-run:
needs: deploy-to-qa
runs-on: ubuntu-latest
steps:
- name: say "approving"
run: echo approving
- name: approve next workflow run
uses: actions/github-script@v5
with:
github-token: ${{ secrets.REPO_ACCESS_TOKEN }}
script: |
const { data: { workflow_runs }} = await github.rest.actions.listWorkflowRuns({
owner: 'ebk45',
repo: 'github-actions',
workflow_id: context.workflow + '.yml',
status: 'waiting'
});
console.log(workflow_runs)
const nextRun = workflow_runs.pop()
await github.rest.actions.reviewPendingDeploymentsForRun({
owner: 'ebk45',
repo: 'github-actions',
run_id: nextRun.id,
environment_ids: [394310963],
state: 'approved',
comment: 'approved to deploy to QA',
});
console.log("approved next in line")