-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (144 loc) · 6.03 KB
/
deploy-start.yml
File metadata and controls
157 lines (144 loc) · 6.03 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Reusable workflow: prepare and start a deployment.
#
# Purpose:
#
# - Decide whether a deployment should start (comment trigger or other events).
# - Resolve the target environment; supports dynamic environment names when
# invoked from issue or pull-request events (e.g. `environment:issue_number`).
# - Create a GitHub deployment and set its initial state to `in_progress`.
#
# Trigger:
#
# - Can be triggered by a specific comment.
# - Any event that triggers the workflow that's not an "issue_comment".
#
# Environment:
#
# - Support dynamic env when comming from issue or pull-request event
name: Deploy - Start
on:
workflow_call:
inputs:
runs-on:
description: |
JSON array of runner(s) to use.
See https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job.
type: string
default: '["ubuntu-latest"]'
required: false
environment:
description: |
Environment where to deploy.
If trigger is from an issue event (or pull-request), environment will be set to `environment:issue_number`.
See https://docs.github.com/en/actions/deployment/deploying-to-your-cloud-provider/using-environments-for-deployment.
type: string
required: false
trigger-on-comment:
description: |
Comment trigger to start the workflow.
See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issue_comment.
type: string
default: "/deploy"
required: false
outputs:
trigger:
description: "Trigger event that started the workflow."
value: ${{ jobs.prepare-deploy.outputs.trigger }}
environment:
description: "Environment where to deploy."
value: ${{ jobs.prepare-deploy.outputs.environment }}
deployment-id:
description: "Deployment ID to use for the deployment."
value: ${{ jobs.start-deploy.outputs.deployment-id }}
permissions: {}
jobs:
prepare-deploy:
name: Check if should deploy
runs-on: ${{ fromJson(inputs.runs-on) }}
permissions:
contents: read
id-token: write # Needed for getting local workflow actions
issues: write
pull-requests: write
outputs:
trigger: ${{ steps.trigger.outputs.trigger }}
environment: ${{ steps.get-environment.outputs.environment }}
steps:
- id: not-created-issue-comment
if: github.event_name != 'issue_comment'
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: return true;
- uses: shanegenschaw/pull-request-comment-trigger@de309e4a2e83bb08877cada483e3e2b13b8d8e4b # v3.0.0
id: trigger-on-comment
if: ${{ !steps.not-created-issue-comment.outputs.result && inputs.trigger-on-comment }}
with:
trigger: ${{ inputs.trigger-on-comment }}
prefix_only: true
reaction: eyes
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN || github.token }}"
- id: trigger
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
if: ${{ steps.not-created-issue-comment.outputs.result || steps.trigger-on-comment.outputs.triggered == 'true' }}
env:
NOT_CREATED_ISSUE_COMMENT: ${{ steps.not-created-issue-comment.outputs.result }}
TRIGGER_ON_COMMENT: ${{ steps.trigger-on-comment.outputs.triggered }}
EVENT_NAME: ${{ github.event_name }}
with:
script: |
if (process.env.NOT_CREATED_ISSUE_COMMENT === 'true' || process.env.TRIGGER_ON_COMMENT === 'true') {
core.setOutput('trigger', process.env.EVENT_NAME);
}
- id: local-workflow-actions
uses: hoverkraft-tech/ci-github-common/actions/local-workflow-actions@4b53189212d5810f710bed89711002626977215b # 0.33.0
with:
actions-path: actions
- id: get-environment
if: ${{ steps.trigger.outputs.trigger }}
uses: ./self-workflow/actions/deploy/get-environment
with:
environment: ${{ inputs.environment }}
# jscpd:ignore-start
- uses: hoverkraft-tech/ci-github-common/actions/local-workflow-actions@4b53189212d5810f710bed89711002626977215b # 0.33.0
if: always() && steps.local-workflow-actions.outputs.repository
with:
actions-path: actions
repository: ${{ steps.local-workflow-actions.outputs.repository }}
ref: ${{ steps.local-workflow-actions.outputs.ref }}
# jscpd:ignore-end
start-deploy:
name: Start deploy
runs-on: ${{ fromJson(inputs.runs-on) }}
needs: prepare-deploy
if: needs.prepare-deploy.outputs.trigger
permissions:
actions: read
deployments: write
id-token: write # Needed for getting local workflow actions
pull-requests: read
environment: ${{ needs.prepare-deploy.outputs.environment }}
outputs:
deployment-id: ${{ steps.create-deployment.outputs.deployment-id }}
steps:
- id: local-workflow-actions
uses: hoverkraft-tech/ci-github-common/actions/local-workflow-actions@4b53189212d5810f710bed89711002626977215b # 0.33.0
with:
actions-path: actions
- id: create-deployment
uses: ./self-workflow/actions/deployment/create
with:
environment: ${{ needs.prepare-deploy.outputs.environment }}
- uses: ./self-workflow/actions/deployment/update
with:
deployment-id: ${{ steps.create-deployment.outputs.deployment-id }}
state: "in_progress"
description: "Starting deployment to ${{ needs.prepare-deploy.outputs.environment }}..."
# jscpd:ignore-start
- uses: hoverkraft-tech/ci-github-common/actions/local-workflow-actions@4b53189212d5810f710bed89711002626977215b # 0.33.0
if: always() && steps.local-workflow-actions.outputs.repository
with:
actions-path: actions
repository: ${{ steps.local-workflow-actions.outputs.repository }}
ref: ${{ steps.local-workflow-actions.outputs.ref }}
# jscpd:ignore-end