-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaction.yml
225 lines (202 loc) · 8.34 KB
/
action.yml
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
---
name: env-build-and-deploy
description: |
Uses kustomize to build and commit to an environment branch or opens a PR
inputs:
environment:
description: The environment to build and deploy or open/update a PR for
required: true
push-environment-regex:
description: Regex to match environments which will be pushed to directly
required: false
default: .*(development|integration).*
pr-environment-regex:
description: |
Regex to match environments which will push to a
deploy-pr/<environment> branch and open a PR for review
required: false
default: .*(staging|production).*
dry-run:
description: |
On a dry-run only the kustomize build will occur and the built branch will
not be pushed anywhere.
required: false
default: 'true'
working-directory:
description: The location where the deployment git repo is checked out
required: true
version:
description: Version of Kustomize to use
required: false
default: 5.3.0
sha256-checksum:
description: Checksum of Kustomize version
required: false
default: 3ab32f92360d752a2a53e56be073b649abc1e7351b912c0fb32b960d1def854c
git-commit-user:
description: Name to add to the Git Commit Message
required: false
default: Kustomize Everything
git-commit-email:
description: Email to add to the Git Commit Message
required: false
default: [email protected]
git-commit-message:
description: Commit message to use for deployment
required: false
token:
description: |
The token to use for pushing to the repo. This should be a bot account
with write access to the target repo, as well as PR access if it needs to
open a PR.
required: true
helm-version:
description: Helm Version to install
default: 3.9.4
runs:
using: composite
steps:
- run: echo "${{ github.action_path }}" >> $GITHUB_PATH
shell: bash
- name: Detect Push Environment
id: detect-push-environment
shell: bash
run: |-
MATCH=$(python ${{ github.action_path }}/regex-match.py "${{ inputs.push-environment-regex }}" "${{ inputs.environment }}")
echo "match=$MATCH" >> $GITHUB_OUTPUT
- name: Detect PR Environment
id: detect-pr-environment
shell: bash
run: |-
MATCH=$(python ${{ github.action_path }}/regex-match.py "${{ inputs.pr-environment-regex }}" "${{ inputs.environment }}")
echo "match=$MATCH" >> $GITHUB_OUTPUT
# These variables are re-used by the run steps.
- name: Shared ENV Setup
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
ENV: ${{ inputs.environment }}
PUSH_ENVIRONMENT_REGEX: ${{ steps.detect-push-environment.outputs.match }}
PR_ENVIRONMENT_REGEX: ${{ steps.detect-pr-environment.outputs.match }}
run: setup-shared-env.sh
# Kustomize setup (this should be abstracted into a separate action repo)
- name: Kustomize Setup
uses: kustomize-everything/[email protected]
with:
version: ${{ inputs.version }}
sha256-checksum: ${{ inputs.sha256-checksum }}
- uses: azure/setup-helm@v4
with:
version: ${{ inputs.helm-version }} # default is latest (stable)
id: install
- name: Set Git Author
shell: bash
run: |
git config --global user.name ${{ inputs.git-commit-user }}
git config --global user.email ${{ inputs.git-commit-email }}
# Kustomize Build
- name: Kustomize Build
shell: bash
working-directory: ${{ inputs.working-directory }}
run: kustomize-build.sh
- name: Branch and stage
shell: bash
working-directory: ${{ inputs.working-directory }}
run: branch-and-stage.sh
- name: Git diff against ${{ env.DIFF_BRANCH }}
shell: bash
id: diff
working-directory: ${{ inputs.working-directory }}
run: diff.sh
- name: Find Comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: github-actions[bot]
body-includes: Comparison of ${{env.DIFF_BRANCH}}
token: ${{ inputs.token }}
- name: Create or update comment with No Changes
if: ${{ github.event_name == 'pull_request' && steps.fc.outputs.comment-id != 0 && steps.diff.outputs.diff-bytes == 0 }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Comparison of ${{env.DIFF_BRANCH}} [${{env.DIFF_BRANCH_HEAD_SHORT_SHA}}](${{env.DIFF_BRANCH_HEAD_SHA_URL}}) to proposed changes to ${{env.ENV_DIR}} in this PR
No changes detected.
edit-mode: replace
token: ${{ inputs.token }}
- name: Create or update comment with Diff
if: ${{ github.event_name == 'pull_request' && steps.diff.outputs.diff-bytes > 0 && steps.diff.outputs.diff-bytes < 65000 }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Comparison of ${{env.DIFF_BRANCH}} [${{env.DIFF_BRANCH_HEAD_SHORT_SHA}}](${{env.DIFF_BRANCH_HEAD_SHA_URL}}) to proposed changes to ${{env.ENV_DIR}} in this PR
<details>
<summary>Diff output</summary>
```diff
${{ steps.diff.outputs.diff }}
```
</details>
edit-mode: replace
token: ${{ inputs.token }}
- name: Create or update comment with Too Big Diff
if: ${{ github.event_name == 'pull_request' && steps.diff.outputs.diff-bytes >= 65000 }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Comparison of ${{env.DIFF_BRANCH}} [${{env.DIFF_BRANCH_HEAD_SHORT_SHA}}](${{env.DIFF_BRANCH_HEAD_SHA_URL}}) to proposed changes to ${{env.ENV_DIR}} in this PR
Git Diff is too large to display in a comment.
Please [check the logs](${{env.RUN_URL}}).
edit-mode: replace
token: ${{ inputs.token }}
- name: Commit to ${{ env.PUSH_BRANCH }}
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
GIT_COMMIT_MESSAGE: ${{ inputs.git-commit-message }}
GIT_HEAD_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
if: ${{ inputs.dry-run == 'false' && env.DEPLOY_METHOD == 'push' }}
run: commit.sh
- name: Push to ${{ env.PUSH_BRANCH }}
shell: bash
working-directory: ${{ inputs.working-directory }}
if: ${{ inputs.dry-run == 'false' }}
run: |
if ! git diff --quiet "origin/${DIFF_BRANCH}" ; then
git push origin -f "${PUSH_BRANCH}"
fi
- name: Open Deployment PR to ${{ inputs.environment }}
id: open-pr
uses: peter-evans/create-pull-request@v6
if: ${{ inputs.dry-run == 'false' && env.DEPLOY_METHOD == 'pull-request' && steps.diff.outputs.diff-bytes > 0 }}
with:
title: Deployment to ${{ inputs.environment }}
body: ${{ steps.commit-message.outputs.commit-message }}
base: ${{ env.ENV_BRANCH }}
branch: ${{ env.PUSH_BRANCH }}
delete-branch: true
path: ${{ inputs.working-directory }}
token: ${{ inputs.token }}
- name: PR Opened or Updated
if: ${{ steps.open-pr.outputs.pull-request-number && (steps.open-pr.outputs.pull-request-operation == 'created' || steps.open-pr.outputs.pull-request-operation == 'updated') }}
shell: bash
run: |
echo "The deployment PR for ${{ inputs.environment }} is waiting for
deployment after PR review and merge."
echo "Please review the k8s manifests in this PR and merge if ready
to deploy to ${{ inputs.environment }}."
echo "${{ steps.cpr.outputs.pull-request-url }}"
- name: PR Closed
if: ${{ steps.open-pr.outputs.pull-request-number && steps.open-pr.outputs.pull-request-operation == 'closed' }}
shell: bash
run: |-
echo "The deployment PR for ${{ inputs.environment }} has been closed as
there are no changes detected."
echo "${{ steps.cpr.outputs.pull-request-url }}"