Skip to content

Commit c4e539f

Browse files
DPC-4472 dedupe workflows (#2391)
## 🎫 Ticket https://jira.cms.gov/browse/DPC-4472 ## πŸ›  Changes - logic for deploying api-waf-sync, opt-out-import, opt-out-export consolidated to deploy_go.yml - workflows differentiated by environment consolidated into single workflows with environment variable ## ℹ️ Context Rampant duplication of code consolidated for ease of maintenance and for running workflows. ## πŸ§ͺ Validation Deploy workflows ran automatically and passed tests (see checks).
1 parent d89589e commit c4e539f

16 files changed

+195
-307
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: api-waf-sync dev deploy
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
env:
7+
description: AWS environment to deploy to
8+
required: true
9+
type: string
10+
default: "dev"
11+
12+
workflow_dispatch:
13+
inputs:
14+
env:
15+
description: AWS environment to deploy to
16+
required: true
17+
type: string
18+
default: "dev"
19+
20+
push:
21+
branches:
22+
- main
23+
paths:
24+
- lambda/api-waf-sync/**
25+
- .github/workflows/api-waf-sync-deploy.yml
26+
- .github/workflows/deploy_go_lambda.yml
27+
28+
jobs:
29+
deploy:
30+
name: 'Deploy API WAF sync'
31+
uses: ./.github/workflows/deploy_go_lambda.yml
32+
with:
33+
env: dev # ${{ inputs.env || 'dev' }} currently only available on dev
34+
project: api-waf-sync
35+
go_files: "main.go db.go aws.go"
36+
secrets: inherit

β€Ž.github/workflows/api-waf-sync-dev-deploy.ymlβ€Ž

Lines changed: 0 additions & 40 deletions
This file was deleted.

β€Ž.github/workflows/api-waf-sync-prod-deploy.ymlβ€Ž

Lines changed: 0 additions & 24 deletions
This file was deleted.

β€Ž.github/workflows/api-waf-sync-test-deploy.ymlβ€Ž

Lines changed: 0 additions & 39 deletions
This file was deleted.

β€Ž.github/workflows/api-waf-sync-test-integration.ymlβ€Ž

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ on:
44
pull_request:
55
paths:
66
- .github/workflows/api-waf-sync-test-integration.yml
7-
- .github/workflows/api-waf-sync-test-deploy.yml
7+
- .github/workflows/api-waf-sync-deploy.yml
8+
- .github/workflows/deploy_go_lambda.yml
89
- lambda/api-waf-sync/**
910
workflow_dispatch:
1011

@@ -16,7 +17,9 @@ jobs:
1617
# Deploy first if triggered by pull_request
1718
deploy:
1819
if: ${{ github.event_name == 'pull_request' }}
19-
uses: ./.github/workflows/api-waf-sync-test-deploy.yml
20+
uses: ./.github/workflows/api-waf-sync-deploy.yml
21+
with:
22+
env: dev
2023
secrets: inherit
2124

2225
trigger:
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Deploy go lambda
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
env:
7+
description: AWS environment to deploy to
8+
required: true
9+
type: string
10+
project:
11+
description: Project name
12+
required: true
13+
type: string
14+
go_files:
15+
description: space-delimited go files
16+
required: true
17+
type: string
18+
19+
jobs:
20+
deploy:
21+
name: "Build and Deploy"
22+
if: ${{ inputs.env != 'prod' }}
23+
permissions:
24+
contents: read
25+
id-token: write
26+
runs-on: ubuntu-latest
27+
defaults:
28+
run:
29+
working-directory: ./lambda/${{ inputs.project }}
30+
environment: ${{ inputs.env }}
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: actions/setup-go@v5
34+
- name: Build ${{ inputs.project }} zip file
35+
env:
36+
CGO_ENABLED: 0
37+
run: |
38+
go build -o bootstrap ${{ inputs.go_files }}
39+
zip function.zip bootstrap
40+
- uses: aws-actions/configure-aws-credentials@v4
41+
with:
42+
aws-region: ${{ vars.AWS_REGION }}
43+
role-to-assume: arn:aws:iam::${{ secrets.ACCOUNT_ID }}:role/delegatedadmin/developer/dpc-${{ inputs.env }}-github-actions
44+
- name: Upload and reload
45+
env:
46+
LABEL: ${{ inputs.env }}-${{ inputs.project }}
47+
run: |
48+
aws s3 cp --no-progress function.zip \
49+
s3://dpc-$LABEL-function/function-${{ github.sha }}.zip
50+
aws lambda update-function-code --function-name dpc-$LABEL \
51+
--s3-bucket dpc-$LABEL-function --s3-key function-${{ github.sha }}.zip
52+
53+
promote:
54+
name: "Promote to prod"
55+
if: ${{ inputs.env == 'prod' }}
56+
permissions:
57+
contents: read
58+
id-token: write
59+
runs-on: ubuntu-latest
60+
environment: prod
61+
steps:
62+
- uses: aws-actions/configure-aws-credentials@v4
63+
with:
64+
aws-region: ${{ vars.AWS_REGION }}
65+
role-to-assume: arn:aws:iam::${{ secrets.ACCOUNT_ID }}:role/delegatedadmin/developer/dpc-prod-github-actions
66+
- name: Promote lambda code from test to prod
67+
run: |
68+
aws s3 cp --no-progress \
69+
s3://dpc-test-${{ inputs.project }}-function/function-${{ github.sha }}.zip \
70+
s3://dpc-prod-${{ inputs.project }}-function/function-${{ github.sha }}.zip
71+
aws lambda update-function-code --function-name dpc-prod-${{ inputs.project }} \
72+
--s3-bucket dpc-prod-${{ inputs.project }}-function --s3-key function-${{ github.sha }}.zip
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: opt-out-export deploy
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
env:
7+
description: AWS environment to deploy to
8+
required: true
9+
type: string
10+
default: "dev"
11+
12+
workflow_dispatch:
13+
inputs:
14+
env:
15+
description: AWS environment to deploy to
16+
required: true
17+
type: string
18+
default: "dev"
19+
20+
push:
21+
branches:
22+
- main
23+
paths:
24+
- lambda/opt-out-export/**
25+
- .github/workflows/opt-out-export-deploy.yml
26+
- .github/workflows/deploy_go_lambda.yml
27+
28+
jobs:
29+
deploy:
30+
name: 'Deploy Opt Out Export'
31+
uses: ./.github/workflows/deploy_go_lambda.yml
32+
with:
33+
env: ${{ inputs.env || 'dev' }}
34+
project: opt-out-export
35+
go_files: "main.go db.go"
36+
secrets: inherit

β€Ž.github/workflows/opt-out-export-dev-deploy.ymlβ€Ž

Lines changed: 0 additions & 40 deletions
This file was deleted.

β€Ž.github/workflows/opt-out-export-prod-deploy.ymlβ€Ž

Lines changed: 0 additions & 24 deletions
This file was deleted.

β€Ž.github/workflows/opt-out-export-test-deploy.ymlβ€Ž

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
Β (0)