Skip to content

Commit 6ff96aa

Browse files
committed
Refactor deployment workflow to use reusable GitHub Actions
1 parent 1bdf8b5 commit 6ff96aa

2 files changed

Lines changed: 102 additions & 74 deletions

File tree

.github/workflows/deploy-dev.yml

Lines changed: 7 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -9,77 +9,10 @@ concurrency:
99

1010
jobs:
1111
deploy:
12-
name: Deploy
13-
runs-on: ubuntu-latest
14-
timeout-minutes: 15
15-
16-
permissions:
17-
contents: read
18-
id-token: write
19-
20-
steps:
21-
- name: Checkout repository
22-
uses: actions/checkout@v6
23-
24-
- name: Setup Node.js
25-
uses: actions/setup-node@v6
26-
with:
27-
node-version-file: .nvmrc
28-
cache: 'npm'
29-
30-
- name: Configure AWS credentials
31-
uses: aws-actions/configure-aws-credentials@v6
32-
with:
33-
role-to-assume: ${{ vars.AWS_ROLE_ARN_DEV }}
34-
aws-region: ${{ vars.AWS_REGION }}
35-
role-session-name: deploy-dev-lambda-starter
36-
37-
- name: Install dependencies
38-
run: npm ci
39-
40-
- name: Build application
41-
run: npm run build
42-
43-
- name: Run tests
44-
run: npm run test
45-
46-
- name: Install infrastructure dependencies
47-
working-directory: ./infrastructure
48-
run: npm ci
49-
50-
- name: Create infrastructure .env file
51-
working-directory: ./infrastructure
52-
run: echo "${{ vars.CDK_ENV_DEV }}" > .env
53-
54-
- name: Build infrastructure
55-
working-directory: ./infrastructure
56-
run: npm run build
57-
58-
- name: Bootstrap CDK (if needed)
59-
working-directory: ./infrastructure
60-
run: |
61-
# Check if bootstrap is needed
62-
if ! aws cloudformation describe-stacks --stack-name CDKToolkit --region ${{ vars.AWS_REGION }} >/dev/null 2>&1; then
63-
echo "Bootstrapping CDK..."
64-
npm run bootstrap
65-
else
66-
echo "CDK already bootstrapped"
67-
fi
68-
69-
- name: Synthesize CDK stacks
70-
working-directory: ./infrastructure
71-
run: npm run synth
72-
73-
- name: Deploy CDK stacks
74-
working-directory: ./infrastructure
75-
run: npm run deploy:all -- --require-approval never --progress events
76-
77-
# Final Step: Clean up sensitive infrastructure files
78-
- name: Clean up sensitive files
79-
if: always()
80-
working-directory: ./infrastructure
81-
run: |
82-
echo "🧹 Cleaning up sensitive files..."
83-
rm -f .env
84-
rm -rf cdk.out
85-
echo "✅ Sensitive files cleaned up"
12+
name: Deploy to DEV
13+
uses: ./.github/workflows/deploy-reusable.yml
14+
with:
15+
aws_role_arn: ${{ vars.AWS_ROLE_ARN_DEV }}
16+
aws_region: ${{ vars.AWS_REGION }}
17+
cdk_env: ${{ vars.CDK_ENV_DEV }}
18+
secrets: inherit
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Deploy (Reusable)
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
aws_role_arn:
7+
description: 'AWS Role ARN for credential assumption'
8+
required: true
9+
type: string
10+
aws_region:
11+
description: 'AWS region'
12+
required: false
13+
type: string
14+
default: 'us-east-1'
15+
cdk_env:
16+
description: 'CDK environment variables'
17+
required: true
18+
type: string
19+
20+
jobs:
21+
deploy:
22+
name: Deploy
23+
runs-on: ubuntu-latest
24+
timeout-minutes: 15
25+
26+
permissions:
27+
contents: read
28+
id-token: write
29+
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v6
33+
34+
- name: Setup Node.js
35+
uses: actions/setup-node@v6
36+
with:
37+
node-version-file: .nvmrc
38+
cache: 'npm'
39+
40+
- name: Configure AWS credentials
41+
uses: aws-actions/configure-aws-credentials@v6
42+
with:
43+
role-to-assume: ${{ inputs.aws_role_arn }}
44+
aws-region: ${{ inputs.aws_region }}
45+
role-session-name: deploy-lambda-starter
46+
47+
- name: Install dependencies
48+
run: npm ci
49+
50+
- name: Build application
51+
run: npm run build
52+
53+
- name: Run tests
54+
run: npm run test
55+
56+
- name: Install infrastructure dependencies
57+
working-directory: ./infrastructure
58+
run: npm ci
59+
60+
- name: Create infrastructure .env file
61+
working-directory: ./infrastructure
62+
run: echo "${{ inputs.cdk_env }}" > .env
63+
64+
- name: Build infrastructure
65+
working-directory: ./infrastructure
66+
run: npm run build
67+
68+
- name: Bootstrap CDK (if needed)
69+
working-directory: ./infrastructure
70+
run: |
71+
# Check if bootstrap is needed
72+
if ! aws cloudformation describe-stacks --stack-name CDKToolkit --region ${{ inputs.aws_region }} >/dev/null 2>&1; then
73+
echo "Bootstrapping CDK..."
74+
npm run bootstrap
75+
else
76+
echo "CDK already bootstrapped"
77+
fi
78+
79+
- name: Synthesize CDK stacks
80+
working-directory: ./infrastructure
81+
run: npm run synth
82+
83+
- name: Deploy CDK stacks
84+
working-directory: ./infrastructure
85+
run: npm run deploy:all -- --require-approval never --progress events
86+
87+
# Final Step: Clean up sensitive infrastructure files
88+
- name: Clean up sensitive files
89+
if: always()
90+
working-directory: ./infrastructure
91+
run: |
92+
echo "🧹 Cleaning up sensitive files..."
93+
rm -f .env
94+
rm -rf cdk.out
95+
echo "✅ Sensitive files cleaned up"

0 commit comments

Comments
 (0)