-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (90 loc) · 2.88 KB
/
deploy-dev.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Deploy Dev
on:
workflow_dispatch:
push:
branches: main
env:
app_zip_path: lambda-express-api.zip
aws_account_id: ${{ vars.AWS_ACCOUNT_ID }}
aws_region: ${{ vars.AWS_REGION }}
aws_role: ${{ vars.AWS_ROLE }}
jobs:
setup:
runs-on: ubuntu-latest
outputs:
sha_short: ${{ steps.set_sha.outputs.GITHUB_SHA_SHORT }}
steps:
- uses: actions/checkout@v4
- id: set_sha
run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_OUTPUT
build:
needs: setup
env:
app_folder: src/
app_zip_path: ${{ needs.setup.outputs.sha_short }}-lambda.zip
runs-on: ubuntu-latest
outputs:
app_zip_path: ${{ steps.set-zip-path.outputs.APP_ZIP_PATH }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build
run: |
cd ${{ env.app_folder }}
npm install
- name: Zip
run: |
zip -r ${{ env.app_zip_path }} ${{ env.app_folder }}
- name: Upload build artefact
uses: actions/upload-artifact@v3
with:
name: zipped-code
path: ${{ env.app_zip_path }}
- id: set-zip-path
run: echo "APP_ZIP_PATH=$(echo ${{ env.app_zip_path }})" >> $GITHUB_OUTPUT
dev:
runs-on: ubuntu-latest
needs: build
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: zipped-code
path: tf
- run: ls tf
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.aws_region }}
role-to-assume: arn:aws:iam::${{ env.aws_account_id }}:role/${{ env.aws_role }}
role-session-name: GitHubActions
- name: Init
shell: bash
run: |
cd tf
terraform init
- name: Select Workspace
shell: bash
run: |
cd tf
terraform workspace select -or-create dev
terraform init
- name: Action
shell: bash
id: action
run: |
cd tf
terraform apply -auto-approve -var function-stage=dev -var lambda-zip-path=${{ needs.build.outputs.app_zip_path }}
# get-url:
# needs: dev
# runs-on: ubuntu-latest
# steps:
# - run: echo random-number ${{ steps.action.outputs.api-url }}
# shell: bash