Skip to content

Commit 4200746

Browse files
committed
chore: Github action for dev
1 parent ab63d21 commit 4200746

6 files changed

Lines changed: 193 additions & 12 deletions

File tree

‎.eslintignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.github
12
/.git
23
/.vscode
34
/node_modules
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Build and Deploy
2+
on:
3+
workflow_call:
4+
inputs:
5+
env:
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+
15+
concurrency:
16+
cancel-in-progress: false
17+
group: build-deploy-${{ inputs.env }}
18+
19+
env:
20+
NODE_VERSION: 22.15.0
21+
VITE_BUILD_VERSION: ${{ inputs.version }}
22+
VITE_DD_VERSION: ${{ inputs.version }}
23+
24+
jobs:
25+
setup-vars:
26+
uses: ./.github/workflows/_setup.yaml
27+
with:
28+
env-name: ${{ inputs.env-name }}
29+
30+
build:
31+
runs-on: ubuntu-latest
32+
name: Node Build and Deploy
33+
needs: setup-vars
34+
permissions:
35+
contents: read
36+
id-token: write
37+
steps:
38+
- uses: actions/checkout@v4
39+
name: Checkout
40+
41+
- name: Configure aws credentials for secrets
42+
uses: aws-actions/configure-aws-credentials@v4
43+
with:
44+
role-to-assume: arn:aws:iam::917902836630:role/cmiml-devops-oidc-github-role
45+
role-session-name: OIDC-GHA-Build-Secrets
46+
aws-region: us-east-1
47+
48+
- name: Load build config
49+
uses: aws-actions/aws-secretsmanager-get-secrets@v2
50+
with:
51+
secret-ids: /CodeBuild/admin-panel/${{ inputs.env }}
52+
parse-json-secrets: true
53+
54+
- uses: actions/setup-node@v4
55+
name: Setup Node
56+
with:
57+
node-version: ${{ env.NODE_VERSION }}
58+
59+
- name: Install dependencies
60+
run: npm ci
61+
62+
- uses: wearerequired/lint-action@v2
63+
name: Lint
64+
with:
65+
eslint: true
66+
eslint_extensions: js,jsx,ts,tsx
67+
prettier: true
68+
prettier_extensions: js,jsx,ts,tsx
69+
continue_on_error: false
70+
71+
- name: Tests
72+
run: npm run test
73+
74+
- name: Build admin app
75+
run: npm run build
76+
77+
- name: Configure AWS credentials for deploy
78+
uses: aws-actions/configure-aws-credentials@v4
79+
with:
80+
role-to-assume: ${{ needs.setup-vars.outputs.role }}
81+
role-session-name: OIDC-GHA-session-deploy
82+
aws-region: ${{ needs.setup-vars.outputs.region }}
83+
84+
- name: Deploy
85+
run: |
86+
aws s3 sync ./build s3://cmiml-${{ inputs.env }}-admin-panel
87+
88+
- name: Invalidate Cloudfront caches
89+
run:
90+
for id in $(aws cloudfront list-distributions --output json | jq -r '.DistributionList.Items[] | select(.Comment | test("admin"; "i")) | .Id'); do
91+
aws cloudfront create-invalidation --distribution-id ${id} --paths "/*"
92+
done

‎.github/workflows/_setup.yaml‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Setup common variables
2+
on:
3+
workflow_call:
4+
outputs:
5+
role: ${{ jobs.setup-vars.outputs.role }}
6+
region: ${{ jobs.setup-vars.outputs.region }}
7+
cluster: ${{ jobs.setup-vars.outputs.cluster }}
8+
inputs:
9+
env-name:
10+
required: true
11+
type: string
12+
description: Environment name
13+
14+
15+
jobs:
16+
setup-vars:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Map env to AWS Role
21+
id: role
22+
run: |
23+
ENV_NAME="${{ inputs.env-name }}"
24+
case "$ENV_NAME" in
25+
"dev")
26+
echo 'role=arn:aws:iam::017925157769:role/cmiml-dev-oidc-github-role' >> "$GITHUB_OUTPUT"
27+
;;
28+
"test")
29+
echo 'role=arn:aws:iam::641513112151:role/cmiml-test-oidc-github-role' >> "$GITHUB_OUTPUT"
30+
;;
31+
"uat")
32+
echo 'role=arn:aws:iam::641513112151:role/cmiml-uat-oidc-github-role' >> "$GITHUB_OUTPUT"
33+
;;
34+
"stage")
35+
echo 'role=arn:aws:iam::641513112151:role/cmiml-stage-oidc-github-role' >> "$GITHUB_OUTPUT"
36+
;;
37+
"prod")
38+
echo 'role=arn:aws:iam::410431445687:role/cmiml-prod-oidc-github-role' >> "$GITHUB_OUTPUT"
39+
;;
40+
"prod-dr-us-west-2")
41+
echo 'role=arn:aws:iam::973422231492:role/cmiml-dr-oidc-github-role' >> "$GITHUB_OUTPUT"
42+
;;
43+
*)
44+
echo "Bad environment name"
45+
exit 1;
46+
esac
47+
48+
- name: Map env to AWS Region
49+
id: region
50+
run: |
51+
ENV_NAME="${{ inputs.env-name }}"
52+
case "$ENV_NAME" in
53+
"prod-dr-us-west-2")
54+
echo "region=us-west-2" >> "$GITHUB_OUTPUT"
55+
;;
56+
*)
57+
echo "region=us-east-1" >> "$GITHUB_OUTPUT"
58+
;;
59+
esac
60+
- name: Map env to ECS cluster
61+
id: cluster
62+
run: |
63+
ENV_NAME="${{ inputs.env-name }}"
64+
case "$ENV_NAME" in
65+
"prod-dr-us-west-2")
66+
echo "cluster=prod-dr-us-west-2" >> "$GITHUB_OUTPUT"
67+
;;
68+
*)
69+
echo "cluster=cmiml-${ENV_NAME}" >> "$GITHUB_OUTPUT"
70+
;;
71+
esac
72+
73+
outputs:
74+
role: ${{ steps.role.outputs.role }}
75+
region: ${{ steps.region.outputs.region }}
76+
cluster: ${{ steps.cluster.outputs.cluster }}

‎.github/workflows/ci.yml‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ jobs:
1414
- uses: actions/setup-node@v4
1515
with:
1616
node-version: ${{ env.NODE_VERSION }}
17+
cache: 'npm'
1718

1819
- uses: actions/cache@v4
20+
id: cache
1921
with:
2022
path: |
2123
~/node_modules
2224
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
2325

2426
- run: npm ci
27+
if: steps.cache.outputs.cache-hit != 'true'
2528

2629
- uses: wearerequired/lint-action@v2
2730
with:
@@ -30,47 +33,42 @@ jobs:
3033
prettier: true
3134
prettier_extensions: js,jsx,ts,tsx
3235
continue_on_error: false
36+
3337
tests:
38+
needs: lint
39+
name: Tests
3440
runs-on: ubuntu-latest
3541
steps:
3642
- uses: actions/checkout@v4
3743

3844
- uses: actions/setup-node@v4
3945
with:
4046
node-version: ${{ env.NODE_VERSION }}
47+
cache: 'npm'
4148

4249
- name: Install deps
4350
run: npm ci
4451

45-
- uses: actions/cache@v4
46-
with:
47-
path: |
48-
~/node_modules
49-
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
50-
5152
- name: Running tests
5253
env:
5354
REACT_APP_API_DOMAIN: http://localhost:8080
5455
REACT_APP_WEB_URI: http://localhost:5173
5556
run: npm run test:nowatch
5657
build:
58+
needs: tests
59+
name: Build
5760
runs-on: ubuntu-latest
5861
steps:
5962
- uses: actions/checkout@v4
6063

6164
- uses: actions/setup-node@v4
6265
with:
6366
node-version: ${{ env.NODE_VERSION }}
67+
cache: 'npm'
6468

6569
- name: Install deps
6670
run: npm ci
6771

68-
- uses: actions/cache@v4
69-
with:
70-
path: |
71-
~/node_modules
72-
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
73-
7472
- name: Build admin app
7573
env:
7674
CI: false
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Build and Deploy Dev
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
8+
jobs:
9+
build-deploy:
10+
name: Build and Deploy
11+
uses: ./.github/workflows/_build-deploy.yaml
12+
with:
13+
env: dev

‎.prettierignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.github

0 commit comments

Comments
 (0)