-
Notifications
You must be signed in to change notification settings - Fork 16
259 lines (246 loc) · 9.25 KB
/
release-spec.yml
File metadata and controls
259 lines (246 loc) · 9.25 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
name: 'Release OpenAPI Spec for a given environment'
on:
workflow_call:
inputs:
aws_default_region:
description: 'AWS Default Region.'
required: true
type: string
aws_s3_bucket:
description: 'AWS S3 Bucket.'
required: true
type: string
env:
description: 'Environment to generate the OpenAPI Spec for.'
required: true
type: string
branch:
description: 'Branch to release the OpenAPI Spec to.'
required: true
type: string
spectral_version:
description: 'Version of Spectral to use.'
required: true
type: string
foascli_version:
description: 'Version of FOASCLI to use.'
required: true
type: string
atlas_prod_base_url:
description: 'Base URL of Atlas.'
required: false
type: string
aws_s3_role_to_assume:
description: 'AWS S3 Role to Assume.'
required: true
type: string
atlas_admin_v1_doc_id:
description: 'Bump Doc ID for the v1 spec'
required: false
type: string
atlas_admin_v2_doc_id:
description: 'Bump Doc ID for the v2 specs'
required: true
type: string
secrets: # all secrets are passed explicitly in this workflow
api_bot_pat:
required: true
postman_api_key:
required: false
workspace_id:
required: false
jira_api_token:
required: true
ipa_aws_access_key:
required: false
ipa_aws_secret_key:
required: false
ipa_aws_s3_bucket_prefix:
required: false
bump_token:
required: true
permissions:
contents: write
issues: write
id-token: write
jobs:
generate-spec:
name: Generate the OpenAPI Spec
uses: ./.github/workflows/generate-openapi.yml
secrets:
api_bot_pat: ${{ secrets.api_bot_pat }}
with:
aws_default_region: ${{ inputs.aws_default_region}}
aws_s3_bucket: ${{ inputs.aws_s3_bucket}}
aws_s3_role_to_assume: ${{ inputs.aws_s3_role_to_assume }}
env: ${{ inputs.env }}
foascli_version: ${{ inputs.foascli_version }}
# Required validations will stop the release if they fail
run-required-validations:
name: Run Required Validations
needs: generate-spec
uses: ./.github/workflows/required-spec-validations.yml
secrets:
api_bot_pat: ${{ secrets.api_bot_pat }}
with:
spectral_version: ${{ inputs.spectral_version }}
env: ${{ inputs.env }}
# Optional validations won't stop the release but only open a GH issue if they fail
run-optional-validations:
name: Run Optional Validations
needs: generate-spec
uses: ./.github/workflows/optional-spec-validations.yml
secrets:
api_bot_pat: ${{ secrets.api_bot_pat }}
jira_api_token: ${{ secrets.jira_api_token }}
with:
env: ${{ inputs.env }}
spectral_version: ${{ vars.SPECTRAL_VERSION }}
release:
name: Release OpenAPI Spec for V2 APIs
runs-on: ubuntu-latest
needs: [run-required-validations]
outputs:
changes_detected: ${{ steps.commit.outputs.changes_detected }}
bump_release: ${{ steps.bump_changes.outputs.bump_release }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
ref: ${{ inputs.branch }}
token: ${{secrets.api_bot_pat}}
- name: Upload current Specs and Changelog files
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: base-${{ inputs.env }}
retention-days: 1
path: |
openapi/v2/openapi*.json
changelog/changelog.json
changelog/internal/changelog-all.json
changelog/internal/metadata.json
- name: Download openapi-foas
uses: actions/download-artifact@v8
with:
name: openapi-foas-${{ inputs.env }}
github-token: ${{ secrets.api_bot_pat }}
run-id: ${{ github.run_id }}
- name: Download release scripts
uses: actions/download-artifact@v8
with:
name: release-scripts
github-token: ${{ secrets.api_bot_pat }}
run-id: ${{ github.run_id }}
path: release-scripts
- name: Add permissions to execute scripts
run: chmod +x release-scripts/*.sh
- name: Install FOASCLI
env:
foascli_version: ${{ inputs.foascli_version }}
run: |
wget https://github.com/mongodb/openapi/releases/download/v"${foascli_version}"/mongodb-foas-cli_"${foascli_version}"_linux_x86_64.tar.gz -O foascli.tar.gz
tar -xzvf foascli.tar.gz
pushd mongodb-foas-cli_*
echo "$(pwd)/bin" >> "${GITHUB_PATH}"
popd
- name: Run foascli split command
id: split
env:
target_env: ${{ inputs.env }}
run: ./release-scripts/split_spec.sh
- name: Create branded_preview.html
working-directory: openapi
env:
target_env: ${{ inputs.env }}
run: ../release-scripts/branded_preview.sh
- name: Check if changes should be deployed to bump.sh
id: bump_changes
run: |
# We often only update the x-xgen-sha property in OAS since we need
# this piece of information during the changelog release. However, this small changes
# should not trigger a bump.sh release since the rendered spec is still the same.
# This logic makes sure that the v2.json file changes are more than 1 lines
# which suggests that we are not only updating the x-xgen-sha property.
export bump_release='false'
changed_lines=$(git diff --numstat openapi/v2.json | awk '{print $1}')
# Default to 0 if empty
changed_lines=${changed_lines:-0}
if [ "${changed_lines}" -gt 1 ]; then
export bump_release='true'
fi
echo "bump_release=${bump_release}" >> "${GITHUB_OUTPUT:?}"
- name: Commit changes
id: commit
uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9
env:
target_env: ${{ inputs.env }}
target_branch: ${{ inputs.branch }}
run_id: ${{ github.run_id }}
with:
commit_message: "ci(${{env.target_env}}): Release OpenAPI Spec :rocket:. See https://github.com/mongodb/openapi/actions/runs/${{env.run_id}}."
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
branch: ${{env.target_branch}}
file_pattern: "openapi/*"
release-postman:
name: Release Postman
needs: [release]
if: ${{ inputs.env == 'prod' && needs.release.outputs.changes_detected == 'true' }}
uses: ./.github/workflows/release-postman.yml
secrets:
postman_api_key: ${{ secrets.postman_api_key }}
workspace_id: ${{ secrets.workspace_id }}
with:
atlas_prod_base_url: ${{ inputs.atlas_prod_base_url}}
release-changelog:
name: Release API Changelog
needs: release
uses: ./.github/workflows/release-changelog.yml
secrets:
api_bot_pat: ${{ secrets.api_bot_pat }}
with:
aws_default_region: ${{ inputs.aws_default_region}}
aws_s3_role_to_assume: ${{ inputs.aws_s3_role_to_assume }}
aws_s3_bucket: ${{ inputs.aws_s3_bucket}}
env: ${{ inputs.env }}
branch: ${{ inputs.branch }}
foascli_version: ${{ inputs.foascli_version }}
release-bump-sh:
name: Release API Specification to Bump.sh for ${{ inputs.branch }}
needs: release
if: ${{needs.release.outputs.bump_release == 'true'}}
uses: ./.github/workflows/generate-bump-pages.yml
secrets:
api_bot_pat: ${{ secrets.api_bot_pat }}
bump_token: ${{ secrets.bump_token }}
with:
branch: ${{ inputs.branch }}
atlas_admin_v1_doc_id: ${{ inputs.atlas_admin_v1_doc_id }}
atlas_admin_v2_doc_id: ${{ inputs.atlas_admin_v2_doc_id }}
release-cleanup:
needs: [ release, release-changelog]
uses: ./.github/workflows/release-cleanup.yml
with:
env: ${{ inputs.env }}
branch: ${{ inputs.branch }}
secrets:
api_bot_pat: ${{ secrets.api_bot_pat }}
retry-handler:
needs: [ release, release-postman, release-changelog, release-bump-sh]
if: ${{ always() && contains(needs.*.result, 'failure') && fromJSON(github.run_attempt) < 3}}
runs-on: ubuntu-latest
steps:
- env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.api_bot_pat }}
run: gh workflow run retry-handler.yml -F run_id=${{ github.run_id }}
failure-handler:
name: Failure Handler
needs: [retry-handler, release, release-postman, release-changelog]
if: ${{ always() && contains(needs.*.result, 'failure') && needs.retry-handler.result == 'skipped' }}
uses: ./.github/workflows/failure-handler.yml
with:
env: ${{ inputs.env }}
release_name: "OpenAPI Spec"
team_id: ${{ vars.JIRA_TEAM_ID_APIX_PLATFORM }}
secrets:
jira_api_token: ${{ secrets.JIRA_API_TOKEN }}