Skip to content

Commit cafad01

Browse files
feat: Add Release workflows for DEV, QA and STAGING (#117)
1 parent 2e5bceb commit cafad01

File tree

6 files changed

+209
-13
lines changed

6 files changed

+209
-13
lines changed

.github/workflows/generate-openapi.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ on:
1010
description: 'AWS S3 Bucket.'
1111
required: true
1212
type: string
13+
env:
14+
description: 'Environment to generate the OpenAPI Spec for.'
15+
required: true
16+
type: string
1317
secrets: # all secrets are passed explicitly in this workflow
1418
api_bot_pat:
1519
required: true
@@ -54,5 +58,5 @@ jobs:
5458
- name: Upload artifact
5559
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b
5660
with:
57-
name: openapi-foas
61+
name: openapi-foas-${{ inputs.env }}
5862
path: openapi-foas.*

.github/workflows/optional-spec-validations.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ on:
66
description: 'Version of Spectral to use'
77
type: string
88
required: true
9+
env:
10+
description: 'Environment to generate the OpenAPI Spec for.'
11+
required: true
12+
type: string
913
secrets: # all secrets are passed explicitly in this workflow
1014
api_bot_pat:
1115
required: true
1216

17+
1318
permissions:
1419
contents: write
1520
issues: write
@@ -23,7 +28,7 @@ jobs:
2328
- name: Download openapi-foas
2429
uses: actions/download-artifact@v4
2530
with:
26-
name: openapi-foas
31+
name: openapi-foas-${{ inputs.env }}
2732
github-token: ${{ secrets.api_bot_pat }}
2833
run-id: ${{ github.run_id }}
2934
- name: Validate the FOAS can be used to generate Postman collection
@@ -38,8 +43,10 @@ jobs:
3843
- name: Create Issue
3944
if: ${{ failure() }}
4045
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
46+
env:
47+
target_env: ${{ inputs.env }}
4148
with:
4249
labels: failed-release
43-
title: "(PROD) Optional Postman validation failed :scream_cat:"
50+
title: "(${{env.target_env}}) Optional Postman validation failed :scream_cat:"
4451
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
4552
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release-spec-prod.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ permissions:
99
issues: write
1010

1111
jobs:
12-
generata-spec:
12+
generate-spec:
1313
name: Generate the OpenAPI Spec
1414
uses: ./.github/workflows/generate-openapi.yml
1515
secrets:
@@ -19,26 +19,29 @@ jobs:
1919
with:
2020
aws_default_region: ${{ vars.AWS_DEFAULT_REGION}}
2121
aws_s3_bucket: ${{ vars.S3_BUCKET_PROD}}
22+
env: prod
2223

2324
# Required validations will stop the release if they fail
2425
run-required-validations:
2526
name: Run Required Validations
26-
needs: generata-spec
27+
needs: generate-spec
2728
uses: ./.github/workflows/required-spec-validations.yml
2829
secrets:
2930
api_bot_pat: ${{ secrets.API_BOT_PAT }}
3031
with:
3132
spectral_version: ${{ vars.SPECTRAL_VERSION }}
33+
env: prod
3234

3335
# Optional validations won't stop the release but only open a GH issue if they fail
3436
run-optional-validations:
3537
name: Run Optional Validations
36-
needs: generata-spec
38+
needs: generate-spec
3739
uses: ./.github/workflows/optional-spec-validations.yml
3840
secrets:
3941
api_bot_pat: ${{ secrets.API_BOT_PAT }}
4042
with:
4143
spectral_version: ${{ vars.SPECTRAL_VERSION }}
44+
env: prod
4245

4346
release:
4447
name: Release OpenAPI Spec
@@ -73,15 +76,15 @@ jobs:
7376
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
7477
with:
7578
labels: failed-release
76-
title: "(PROD) Release: `foascli split` command failed :scream_cat:"
79+
title: "(prod) Release: `foascli split` command failed :scream_cat:"
7780
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
7881
token: ${{ secrets.GITHUB_TOKEN }}
7982

8083
- name: Create Pull Request
8184
uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c
8285
with:
8386
token: ${{ secrets.GITHUB_TOKEN }}
84-
title: "release: (PROD) Release OpenAPI Spec :rocket:"
87+
title: "release: (prod) Release OpenAPI Spec :rocket:"
8588
commit-message: "release: (PROD) Release OpenAPI Spec :rocket:"
8689
delete-branch: true
8790
branch: api-bot-update
@@ -95,6 +98,6 @@ jobs:
9598
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
9699
with:
97100
labels: failed-release
98-
title: "(PROD) Release: `Create Pull Request` step failed :scream_cat:"
101+
title: "(prod) Release: `Create Pull Request` step failed :scream_cat:"
99102
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
100103
token: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: 'Release Runner: Start the Release Process for DEV, QA, and STAGING'
2+
on:
3+
workflow_dispatch: {}
4+
schedule:
5+
- cron: '0 * * * *' # Run every hour
6+
permissions:
7+
contents: write
8+
pull-requests: write
9+
issues: write
10+
11+
jobs:
12+
release-spec-dev:
13+
name: Release OpenAPI Spec for DEV
14+
uses: ./.github/workflows/release-spec.yml
15+
secrets:
16+
api_bot_pat: ${{ secrets.API_BOT_PAT }}
17+
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_DEV }}
18+
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }}
19+
with:
20+
aws_default_region: ${{ vars.AWS_DEFAULT_REGION}}
21+
aws_s3_bucket: ${{ vars.S3_BUCKET_DEV}}
22+
env: dev
23+
spectral_version: ${{ vars.SPECTRAL_VERSION }}
24+
release-spec-qa:
25+
name: Release OpenAPI Spec for QA
26+
uses: ./.github/workflows/release-spec.yml
27+
secrets:
28+
api_bot_pat: ${{ secrets.API_BOT_PAT }}
29+
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_QA }}
30+
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_QA }}
31+
with:
32+
aws_default_region: ${{ vars.AWS_DEFAULT_REGION}}
33+
aws_s3_bucket: ${{ vars.S3_BUCKET_QA}}
34+
env: qa
35+
spectral_version: ${{ vars.SPECTRAL_VERSION }}
36+
release-spec-staging:
37+
name: Release OpenAPI Spec for STAGING
38+
uses: ./.github/workflows/release-spec.yml
39+
secrets:
40+
api_bot_pat: ${{ secrets.API_BOT_PAT }}
41+
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_STAGING }}
42+
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_STAGING }}
43+
with:
44+
aws_default_region: ${{ vars.AWS_DEFAULT_REGION}}
45+
aws_s3_bucket: ${{ vars.S3_BUCKET_STAGING}}
46+
env: staging
47+
spectral_version: ${{ vars.SPECTRAL_VERSION }}

.github/workflows/release-spec.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: 'Release OpenAPI Spec for a given environment'
2+
on:
3+
workflow_call:
4+
inputs:
5+
aws_default_region:
6+
description: 'AWS Default Region.'
7+
required: true
8+
type: string
9+
aws_s3_bucket:
10+
description: 'AWS S3 Bucket.'
11+
required: true
12+
type: string
13+
env:
14+
description: 'Environment to generate the OpenAPI Spec for.'
15+
required: true
16+
type: string
17+
spectral_version:
18+
description: 'Version of Spectral to use.'
19+
required: true
20+
type: string
21+
secrets: # all secrets are passed explicitly in this workflow
22+
api_bot_pat:
23+
required: true
24+
aws_access_key_id:
25+
required: true
26+
aws_secret_access_key:
27+
required: true
28+
29+
permissions:
30+
contents: write
31+
issues: write
32+
33+
jobs:
34+
generate-spec:
35+
name: Generate the OpenAPI Spec
36+
uses: ./.github/workflows/generate-openapi.yml
37+
secrets:
38+
api_bot_pat: ${{ secrets.api_bot_pat }}
39+
aws_access_key_id: ${{ secrets.aws_access_key_id }}
40+
aws_secret_access_key: ${{ secrets.aws_secret_access_key }}
41+
with:
42+
aws_default_region: ${{ inputs.aws_default_region}}
43+
aws_s3_bucket: ${{ inputs.aws_s3_bucket}}
44+
env: ${{ inputs.env }}
45+
46+
# Required validations will stop the release if they fail
47+
run-required-validations:
48+
name: Run Required Validations
49+
needs: generate-spec
50+
uses: ./.github/workflows/required-spec-validations.yml
51+
secrets:
52+
api_bot_pat: ${{ secrets.api_bot_pat }}
53+
with:
54+
spectral_version: ${{ inputs.spectral_version }}
55+
env: ${{ inputs.env }}
56+
57+
# Optional validations won't stop the release but only open a GH issue if they fail
58+
run-optional-validations:
59+
name: Run Optional Validations
60+
needs: generate-spec
61+
uses: ./.github/workflows/optional-spec-validations.yml
62+
secrets:
63+
api_bot_pat: ${{ secrets.api_bot_pat }}
64+
with:
65+
env: ${{ inputs.env }}
66+
spectral_version: ${{ vars.SPECTRAL_VERSION }}
67+
68+
release:
69+
name: Release OpenAPI Spec
70+
runs-on: ubuntu-latest
71+
needs: [run-required-validations]
72+
steps:
73+
- name: Checkout repository
74+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
75+
with:
76+
ref: ${{ inputs.env }}
77+
- name: Download openapi-foas
78+
uses: actions/download-artifact@v4
79+
with:
80+
name: openapi-foas-${{ inputs.env }}
81+
github-token: ${{ secrets.api_bot_pat }}
82+
run-id: ${{ github.run_id }}
83+
- name: Install FOASCLI
84+
run: |
85+
wget https://github.com/mongodb/openapi/releases/download/v0.0.8/mongodb-foas-cli_0.0.8_linux_x86_64.tar.gz -O foascli.tar.gz
86+
tar -xzvf foascli.tar.gz
87+
pushd mongodb-foas-cli_*
88+
echo "$(pwd)/bin" >> "${GITHUB_PATH}"
89+
popd
90+
- name: Run foascli split command
91+
env:
92+
target_env: ${{ inputs.env }}
93+
run: |
94+
foascli split -s openapi-foas.json --env "${target_env}" -o ./openapi/v2/openapi.json
95+
cp -rf "openapi-foas.json" "./openapi/v2.json"
96+
97+
foascli split -s openapi-foas.yaml --env "${target_env}" -o ./openapi/v2/openapi.yaml
98+
cp -rf "openapi-foas.yaml" "./openapi/v2.yaml"
99+
- name: Create Issue
100+
if: ${{ failure() }}
101+
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
102+
env:
103+
target_env: ${{ inputs.env }}
104+
with:
105+
labels: failed-release
106+
title: "(${{env.target_env}}) Release: `foascli split` command failed :scream_cat:"
107+
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
108+
token: ${{ secrets.GITHUB_TOKEN }}
109+
- name: Commit changes
110+
uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842
111+
env:
112+
target_env: ${{ inputs.env }}
113+
with:
114+
commit_message: "(${{env.target_env}}) Release OpenAPI Spec :rocket:"
115+
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
116+
branch: ${{env.target_env}}
117+
file_pattern: "openapi/*"
118+
- name: Create Issue
119+
if: ${{ failure() }}
120+
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
121+
env:
122+
target_env: ${{ inputs.env }}
123+
with:
124+
labels: failed-release
125+
title: "(${{env.target_env}}) Release: the Commit Changes step failed :scream_cat:"
126+
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
127+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/required-spec-validations.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
description: 'Version of Spectral to use'
77
type: string
88
required: true
9+
env:
10+
description: 'Environment to generate the OpenAPI Spec for.'
11+
required: true
12+
type: string
913
secrets: # all secrets are passed explicitly in this workflow
1014
api_bot_pat:
1115
required: true
@@ -23,7 +27,7 @@ jobs:
2327
- name: Download openapi-foas
2428
uses: actions/download-artifact@v4
2529
with:
26-
name: openapi-foas
30+
name: openapi-foas-${{ inputs.env }}
2731
github-token: ${{ secrets.api_bot_pat }}
2832
run-id: ${{ github.run_id }}
2933
- name: Run Spectral
@@ -33,9 +37,11 @@ jobs:
3337
- name: Create Issue
3438
if: ${{ failure() }}
3539
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
40+
env:
41+
target_env: ${{ inputs.env }}
3642
with:
3743
labels: failed-release
38-
title: "(PROD) Required Spectal validation failed :scream_cat:"
44+
title: "(${{env.target_env}}) Required Spectal validation failed :scream_cat:"
3945
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
4046
token: ${{ secrets.GITHUB_TOKEN }}
4147
- name: Install Go
@@ -52,7 +58,7 @@ jobs:
5258
- name: Download openapi-foas
5359
uses: actions/download-artifact@v4
5460
with:
55-
name: openapi-foas
61+
name: openapi-foas-${{ inputs.env }}
5662
github-token: ${{ secrets.api_bot_pat }}
5763
run-id: ${{ github.run_id }}
5864
- name: Validate the FOAS can be used with the Go SDK
@@ -64,8 +70,10 @@ jobs:
6470
- name: Create Issue
6571
if: ${{ failure() }}
6672
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
73+
env:
74+
target_env: ${{ inputs.env }}
6775
with:
6876
labels: failed-release
69-
title: "(PROD) Required GO SDK validation failed :scream_cat:"
77+
title: "(${{env.target_env}}) Required GO SDK validation failed :scream_cat:"
7078
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
7179
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)