-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (126 loc) · 5.05 KB
/
Copy pathdeploy-start.yml
File metadata and controls
137 lines (126 loc) · 5.05 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
# 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 coming 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
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@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: return true;
- uses: shanegenschaw/pull-request-comment-trigger@447b2d08faa9eda4f4e5064b84538cebd8b5ca29 # v3.0.1
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@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.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@7034f6ae5bae1ec46a0108e8efb60d102e88961d # 0.37.2
with:
actions-path: actions
- id: get-environment
if: ${{ steps.trigger.outputs.trigger }}
uses: ./../self-workflow/actions/deploy/get-environment
with:
environment: ${{ inputs.environment }}
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
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@7034f6ae5bae1ec46a0108e8efb60d102e88961d # 0.37.2
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 }}..."