1+ name : Build and Deploy
2+ on :
3+ workflow_call :
4+ inputs :
5+ env-name :
6+ required : true
7+ description : Environment name
8+ type : string
9+ version :
10+ required : false
11+ description : Version
12+ type : string
13+ default : latest
14+ secrets :
15+ slack-webhook :
16+ required : true
17+
18+ concurrency :
19+ cancel-in-progress : false
20+ group : build-deploy-${{ inputs.env-name }}
21+
22+ env :
23+ # NODE_VERSION: 22.15.0
24+ VITE_BUILD_VERSION : ${{ inputs.version }}
25+ VITE_DD_VERSION : ${{ inputs.version }}
26+
27+ jobs :
28+ setup-vars :
29+ uses : ./.github/workflows/_setup.yaml
30+ with :
31+ env-name : ${{ inputs.env-name }}
32+
33+ build-deploy :
34+ runs-on : ubuntu-latest
35+ name : Node Build and Deploy
36+ needs : setup-vars
37+ permissions :
38+ contents : read
39+ id-token : write
40+ steps :
41+ - uses : actions/checkout@v4
42+ name : Checkout
43+
44+ - name : Setup node version
45+ run : |
46+ echo "NODE_VERSION=$(cat .nvmrc)" >> $GITHUB_ENV
47+
48+ - name : Configure aws credentials for secrets
49+ uses : aws-actions/configure-aws-credentials@v4
50+ with :
51+ role-to-assume : arn:aws:iam::917902836630:role/cmiml-devops-oidc-github-role
52+ role-session-name : OIDC-GHA-Build-Secrets
53+ aws-region : us-east-1
54+
55+ - name : Load build config
56+ uses : aws-actions/aws-secretsmanager-get-secrets@v2
57+ with :
58+ secret-ids : |
59+ ,/CodeBuild/admin-panel/${{ inputs.env-name }}
60+ parse-json-secrets : true
61+
62+ - uses : actions/setup-node@v4
63+ name : Setup Node
64+ with :
65+ node-version : ${{ env.NODE_VERSION }}
66+
67+ - name : Install dependencies
68+ run : npm ci
69+
70+ - uses : wearerequired/lint-action@v2
71+ name : Lint
72+ with :
73+ eslint : true
74+ eslint_extensions : js,jsx,ts,tsx
75+ prettier : true
76+ prettier_extensions : js,jsx,ts,tsx
77+ continue_on_error : false
78+
79+ - name : Tests
80+ run : npm run test:nowatch
81+ env :
82+ REACT_APP_API_DOMAIN : http://localhost:8000
83+ REACT_APP_ENV : ' dev'
84+ REACT_APP_WEB_URI : http://localhost:5173
85+
86+ - name : Build admin app
87+ run : npm run build
88+ env :
89+ CI : false
90+
91+ - name : Configure AWS credentials for deploy
92+ uses : aws-actions/configure-aws-credentials@v4
93+ with :
94+ role-to-assume : ${{ needs.setup-vars.outputs.role }}
95+ role-session-name : OIDC-GHA-session-deploy
96+ aws-region : ${{ needs.setup-vars.outputs.region }}
97+
98+ - name : Deploy
99+ run : |
100+ aws s3 sync ./build s3://cmiml-${{ inputs.env-name }}-admin-panel
101+
102+ - name : Invalidate Cloudfront caches
103+ run : |
104+ for id in $(aws cloudfront list-distributions --output json | jq -r '.DistributionList.Items[] | select(.Comment | test("web"; "i")) | .Id'); do
105+ AWS_PAGER="" aws cloudfront create-invalidation --distribution-id ${id} --paths "/*" --output table
106+ done
107+
108+
109+ on-deploy-failure :
110+ runs-on : ubuntu-latest
111+ if : ${{ !cancelled() && (needs.build-deploy.result == 'failure' || needs.build-deploy.result == 'timed_out') }}
112+ needs :
113+ - build-deploy
114+ steps :
115+ - uses : actions/checkout@v4
116+ - name : " Send Slack message on failure"
117+ uses : rtCamp/action-slack-notify@v2
118+ env :
119+ SLACK_COLOR : failure
120+ SLACK_WEBHOOK : ${{ secrets.slack-webhook }}
121+ SLACKIFY_MARKDOWN : true
122+ MSG_MINIMAL : actions url
123+ SLACK_TITLE : Admin Deploy Failed to ${{ inputs.env-name }}
124+ SLACK_MESSAGE : ' 🚨 Error when executing deployment!'
125+
126+ on-deploy-success :
127+ runs-on : ubuntu-latest
128+ if : ${{ !cancelled() && (needs.build-deploy.result == 'success') }}
129+ needs :
130+ - build-deploy
131+ steps :
132+ - uses : actions/checkout@v4
133+ - name : " Send Slack message on success"
134+ uses : rtCamp/action-slack-notify@v2
135+ env :
136+ SLACK_COLOR : success
137+ SLACK_WEBHOOK : ${{ secrets.slack-webhook }}
138+ SLACKIFY_MARKDOWN : true
139+ MSG_MINIMAL : actions url
140+ SLACK_TITLE : Admin Deployed to ${{ inputs.env-name }}
141+ SLACK_MESSAGE : ' 🚀 Deployment was successful. Version: *${{ inputs.version }}*'
0 commit comments