1- # name: Deploy Application
1+ name : deploy app
22
3- # on:
4- # push:
5- # branches: [main, develop]
6- # paths:
7- # - 'src/**'
8- # - '.github/workflows/deploy-app.yml'
9- # workflow_dispatch:
10- # inputs:
11- # environment:
12- # description: 'Environment to deploy to'
13- # required: true
14- # type: choice
15- # options:
16- # - dev
17- # - prod
3+ on :
4+ push :
5+ branches : main
6+ paths :
7+ - " ./src/handler"
188
199
20- # env:
21- # AWS_REGION: eu-west-2
10+ env :
11+ AWS_REGION : eu-west-2
2212
23- # jobs:
24- # deploy:
25- # runs-on: ubuntu-latest
26- # permissions:
27- # id-token: write
28- # contents: read
29-
30- # steps:
31- # - name: Checkout code
32- # uses: actions/checkout@v4
13+ jobs :
14+ deploy :
15+ runs-on : ubuntu-latest
16+ permissions :
17+ id-token : write
18+ contents : read
3319
34- # - name: Determine environment
35- # id: env
36- # run: |
37- # if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
38- # ENV="${{ github.event.inputs.environment }}"
39- # elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
40- # ENV="prod"
41- # else
42- # ENV="dev"
43- # fi
44- # echo "environment=${ENV}" >> $GITHUB_OUTPUT
45- # echo "Deploying to: ${ENV}"
46-
47-
48- # - name: Configure AWS credentials
49- # uses: aws-actions/configure-aws-credentials@v4
50- # with:
51- # role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
52- # aws-region: ${{ env.AWS_REGION }}
53-
54- # - name: Setup Node.js
55- # uses: actions/setup-node@v4
56- # with:
57- # node-version: '20'
58- # cache: 'npm'
59- # cache-dependency-path: 'src/package.json'
60-
61- # - name: Install dependencies
62- # working-directory: ./src
63- # run: npm ci --production
64-
65- # - name: Run tests
66- # working-directory: ./src
67- # run: npm test
68-
69- # - name: Package Lambda function
70- # run: |
71- # cd src
72- # zip -r ../deployment.zip . -x "*.git*" -x "node_modules/aws-sdk/*"
73- # cd ..
74- # ls -lh deployment.zip
75-
76- # - name: Get artifacts bucket name
77- # id: bucket
78- # run: |
79- # BUCKET=$(aws s3api list-buckets \
80- # --query "Buckets[?starts_with(Name, 'node-api-${{ steps.env.outputs.environment }}-lambda-artifacts')].Name" \
81- # --output text)
82- # echo "name=${BUCKET}" >> $GITHUB_OUTPUT
83- # echo "Using bucket: ${BUCKET}"
20+ steps :
21+ - name : Checkout code
22+ uses : actions/checkout@v4
23+
24+ - name : Configure AWS credentials
25+ uses : aws-actions/configure-aws-credentials@v4
26+ with :
27+ role-to-assume : ${{ secrets.AWS_ROLE_ARN }}
28+ aws-region : eu-west-2
29+
30+ - name : Setup Node.js
31+ uses : actions/setup-node@v4
32+ with :
33+ node-version : ' 20'
34+ cache : ' npm'
35+ cache-dependency-path : ' src/handler/package.json'
36+
37+ - name : Install dependencies
38+ working-directory : " ./src/handler"
39+ run : npm ci --production
40+
41+ - name : Run tests
42+ working-directory : ./src/handler
43+ run : npm test
44+
45+
46+ - name : Package Lambda function
47+ run : |
48+ cd src
49+ zip -r ../deployment.zip . -x "*.git*" -x "node_modules/aws-sdk/*"
50+ cd ..
51+ ls -lh deployment.zip
52+
53+
54+
55+ - name : Get artifacts bucket name
56+ id : bucket
57+ run : |
58+ BUCKET=$(aws s3api list-buckets \
59+ --query "Buckets[?starts_with(Name, 'node-api-${{ steps.env.outputs.environment }}-lambda-artifacts')].Name" \
60+ --output text)
61+ echo "name=${BUCKET}" >> $GITHUB_OUTPUT
62+ echo "Using bucket: ${BUCKET}"
8463
85- # - name: Upload to S3
86- # run: |
87- # aws s3 cp deployment.zip \
88- # s3://${{ steps.bucket.outputs.name }}/lambda/deployment.zip \
89- # --metadata "git-commit=${{ github.sha }},git-branch=${{ github.ref_name }},deployed-by=github-actions"
64+ - name : Upload to S3
65+ run : |
66+ aws s3 cp deployment.zip \
67+ s3://${{ steps.bucket.outputs.name }}/lambda/deployment.zip \
68+ --metadata "git-commit=${{ github.sha }},git-branch=${{ github.ref_name }},deployed-by=github-actions"
9069
91- # echo "Uploaded deployment package to S3"
70+ echo "Uploaded deployment package to S3"
9271
93- # - name: Update Lambda function code
94- # id: update-lambda
95- # run: |
96- # FUNCTION_NAME="node-api-${{ steps.env.outputs.environment }}-api"
72+ - name : Update Lambda function code
73+ id : update-lambda
74+ run : |
75+ FUNCTION_NAME="node-api-${{ steps.env.outputs.environment }}-api"
9776
98- # echo "Updating Lambda function: ${FUNCTION_NAME}"
77+ echo "Updating Lambda function: ${FUNCTION_NAME}"
9978
100- # aws lambda update-function-code \
101- # --function-name ${FUNCTION_NAME} \
102- # --s3-bucket ${{ steps.bucket.outputs.name }} \
103- # --s3-key handlers/deployment.zip \
104- # --publish
79+ aws lambda update-function-code \
80+ --function-name ${FUNCTION_NAME} \
81+ --s3-bucket ${{ steps.bucket.outputs.name }} \
82+ --s3-key handlers/deployment.zip \
83+ --publish
10584
106- # echo "Waiting for function update to complete..."
107- # aws lambda wait function-updated \
108- # --function-name ${FUNCTION_NAME}
85+ echo "Waiting for function update to complete..."
86+ aws lambda wait function-updated \
87+ --function-name ${FUNCTION_NAME}
10988
110- # VERSION=$(aws lambda get-function \
111- # --function-name ${FUNCTION_NAME} \
112- # --query 'Configuration.Version' \
113- # --output text)
89+ VERSION=$(aws lambda get-function \
90+ --function-name ${FUNCTION_NAME} \
91+ --query 'Configuration.Version' \
92+ --output text)
11493
115- # echo "version=${VERSION}" >> $GITHUB_OUTPUT
116- # echo "Lambda updated to version: ${VERSION}"
94+ echo "version=${VERSION}" >> $GITHUB_OUTPUT
95+ echo "Lambda updated to version: ${VERSION}"
11796
118- # - name: Get API endpoint
119- # id: api
120- # run: |
121- # API_ID=$(aws apigatewayv2 get-apis \
122- # --query "Items[?Name=='node-api-${{ steps.env.outputs.environment }}-api'].ApiId" \
123- # --output text)
97+ - name : Get API endpoint
98+ id : api
99+ run : |
100+ API_ID=$(aws apigatewayv2 get-apis \
101+ --query "Items[?Name=='node-api-${{ steps.env.outputs.environment }}-api'].ApiId" \
102+ --output text)
124103
125- # ENDPOINT=$(aws apigatewayv2 get-api \
126- # --api-id ${API_ID} \
127- # --query 'ApiEndpoint' \
128- # --output text)
104+ ENDPOINT=$(aws apigatewayv2 get-api \
105+ --api-id ${API_ID} \
106+ --query 'ApiEndpoint' \
107+ --output text)
129108
130- # echo "endpoint=${ENDPOINT}" >> $GITHUB_OUTPUT
131-
109+ echo "endpoint=${ENDPOINT}" >> $GITHUB_OUTPUT
110+
0 commit comments