-
Notifications
You must be signed in to change notification settings - Fork 0
245 lines (221 loc) · 7.46 KB
/
production_deploy.yml
File metadata and controls
245 lines (221 loc) · 7.46 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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: Release and Deploy Chat Function
on:
workflow_call:
inputs:
version-bump:
description: "Version bump type"
required: true
type: string
default: patch
chat_function_name:
type: string
description: "The name of the chat function to deploy."
required: true
template-repository-name:
type: string
description: "The name of the repository where the template is located"
required: true
region:
type: string
description: "The AWS region to deploy to"
required: false
build-file:
type: string
description: "The path to the Dockerfile to build"
required: false
default: "Dockerfile"
build-context:
type: string
description: "The context to use for the Docker build"
required: false
default: "."
build-target:
type: string
description: "The target stage of the image to build"
required: false
build-args:
type: string
description: "The build arguments to pass to the Docker build"
required: false
build-platforms:
type: string
description: "The platforms to build the image for"
default: "aws"
required: false
sha:
description: "The exact commit SHA to deploy (from staging)"
type: string
required: true
deployed-environment-variables:
type: string
description: "The environment variables to set for the lambda function on aws, set as mock values."
required: false
secrets:
aws-key-id:
description: "The AWS access key ID"
required: true
aws-secret-key:
description: "The AWS secret access key"
required: true
function-admin-api-key:
description: "The API key for the Lambda Feedback backend function admin API"
required: true
build-secrets:
description: "The Docker secrets to use for the build"
required: false
jobs:
checkout:
name: Checkout Code
runs-on: ubuntu-latest
outputs:
sha: ${{ steps.set-sha.outputs.sha }}
steps:
- name: Set SHA
id: set-sha
run: |
echo "sha=${{ inputs.sha }}" >> $GITHUB_OUTPUT
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.sha }}
fetch-depth: 0
version:
name: Determine Version
runs-on: ubuntu-latest
needs: checkout
outputs:
new-version: ${{ steps.determine-version.outputs.new-version }}
version-tag: ${{ steps.determine-version.outputs.version-tag }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.checkout.outputs.sha }}
fetch-depth: 0
- name: Get latest tag
id: get-latest-tag
run: |
latest_tag=$(git tag -l "v*.*.*" | sort -V | tail -n 1)
if [[ -z "$latest_tag" ]]; then
latest_tag="v0.0.0"
fi
echo "latest-tag=$latest_tag" >> $GITHUB_OUTPUT
echo "Latest tag: $latest_tag"
- name: Determine version bump
id: determine-version
run: |
latest_tag="${{ steps.get-latest-tag.outputs.latest-tag }}"
version="${latest_tag#v}"
IFS='.' read -r major minor patch <<< "$version"
bump_type="${{ inputs.version-bump }}"
case "$bump_type" in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
esac
commit_sha=$(git rev-parse --short HEAD)
new_version="${major}.${minor}.${patch}+${commit_sha}"
version_tag="v${major}.${minor}.${patch}"
echo "new-version=$new_version" >> $GITHUB_OUTPUT
echo "version-tag=$version_tag" >> $GITHUB_OUTPUT
echo "New version: $new_version"
echo "Version tag: $version_tag"
tag:
name: Create Git Tag
runs-on: ubuntu-latest
needs: [checkout, version]
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.checkout.outputs.sha }}
fetch-depth: 0
- name: Create and push tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
tag="${{ needs.version.outputs.version-tag }}"
if git rev-parse "$tag" >/dev/null 2>&1; then
echo "Tag $tag already exists"
exit 1
fi
git tag -a "$tag" -m "Release ${{ needs.version.outputs.new-version }}"
git push origin "$tag"
echo "Created and pushed tag: $tag"
release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [version, tag]
permissions:
contents: write
outputs:
release-id: ${{ steps.create-release.outputs.id }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create GitHub Release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.version.outputs.version-tag }}
release_name: Release ${{ needs.version.outputs.new-version }}
body: |
## Release ${{ needs.version.outputs.new-version }}
**Full version:** `${{ needs.version.outputs.new-version }}`
**Trigger:** Manual deployment
**SHA:** `${{ inputs.sha }}`
### Changes
This release includes all changes up to commit `${{ github.sha }}`.
See the [full changelog](https://github.com/${{ github.repository }}/compare/${{ needs.version.outputs.version-tag }}...HEAD) for details.
draft: false
prerelease: false
build-aws:
uses: ./.github/workflows/lambda_build.yml
if: inputs.build-platforms == 'aws'
needs: version
strategy:
fail-fast: false
with:
environment: prod
function-name: ${{ inputs.chat_function_name }}
region: ${{ inputs.region }}
build-file: ${{ inputs.build-file }}
build-context: ${{ inputs.build-context }}
build-target: ${{ inputs.build-target }}
build-args: ${{ inputs.build-args }}
build-platforms: ${{ inputs.build-platforms }}
build-push: true
secrets:
aws-key-id: ${{ secrets.aws-key-id }}
aws-secret-key: ${{ secrets.aws-secret-key }}
build-secrets: ${{ secrets.build-secrets }}
deploy-production-aws:
uses: ./.github/workflows/lambda_deploy.yml
if: inputs.build-platforms == 'aws' && github.repository != inputs.template-repository-name
needs: [build-aws, version]
with:
environment: prod
api-url: https://prod-api.lambdafeedback.com
image-name: ${{ needs.build-aws.outputs.registry }}/lambda-feedback-prod-chat:${{ inputs.chat_function_name }}
function-name: ${{ inputs.chat_function_name }}
region: ${{ inputs.region }}
deployed-environment-variables: ${{ inputs.deployed-environment-variables }}
secrets:
aws-key-id: ${{ secrets.aws-key-id }}
aws-secret-key: ${{ secrets.aws-secret-key }}
function-admin-api-key: ${{ secrets.function-admin-api-key }}