-
Notifications
You must be signed in to change notification settings - Fork 0
173 lines (145 loc) · 5.6 KB
/
ci_cd.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: "CI/CD Pipeline"
on:
push:
paths:
- "terraform/**"
- ".github/workflows/**"
branches:
- main
pull_request:
jobs:
linting:
name: "Lambda Functions (Linting)"
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- name: "[Command Lambda Function] Install Dependencies & Run Linters"
working-directory: terraform/command_lambda_function
run: |
npm ci
npx eslint function.js
- name: "[Query Lambda Function] Install Dependencies & Run Linters"
working-directory: terraform/query_lambda_function
run: |
npm ci
npx eslint function.js
- name: "[Upsert Lambda Function] Install Dependencies & Run Linters"
working-directory: terraform/upsert_lambda_function
run: |
npm ci
npx eslint function.js
unit_tests:
name: "Lambda Functions (Unit Testing)"
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- name: "[Command Lambda Function] Install Dependencies & Run Tests"
working-directory: terraform/command_lambda_function
run: |
npm ci
npm run test tests/
- name: "[Query Lambda Function] Install Dependencies & Run Tests"
working-directory: terraform/query_lambda_function
run: |
npm ci
npm run test tests/
- name: "[Upsert Lambda Function] Install Dependencies & Run Tests"
working-directory: terraform/upsert_lambda_function
run: |
npm ci
npm run test tests/
deployment:
needs: [linting, unit_tests]
if: contains(github.event.head_commit.message, '[deploy]')
name: "Deploy (Terraform -> AWS)"
runs-on: ubuntu-latest
outputs:
api_base_url: ${{steps.options.outputs.api_base_url}}
bucket_name: ${{steps.options.outputs.bucket_name}}
steps:
- name: Check out Git repository
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
# terraform_version: 0.13.0:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
terraform_wrapper: false
- name: Terraform Format
working-directory: terraform
run: terraform fmt -check
- name: Terraform Init
working-directory: terraform
run: terraform init
- name: Terraform Validate
working-directory: terraform
run: terraform validate -no-color
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
working-directory: terraform
run: terraform apply -auto-approve -input=false
- name: Set Step's Output with `api_base_url_production` value from <terraform output>
id: api_base_url_step
working-directory: terraform
run: |
api_base_url=$(terraform output -raw api_base_url_production)
echo $api_base_url
echo "::set-output name=value::${api_base_url}"
- name: Set Job's Output with `api_base_url` value
uses: actions/github-script@v5
id: options
with:
script: |
console.log('*** api_base_url:', '${{steps.api_base_url_step.outputs.value}}');
core.setOutput('api_base_url', '${{steps.api_base_url_step.outputs.value}}');
integration_tests:
needs: deployment
name: "API Testing (Integration)"
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v3
- name: GET /urls Endpoint
working-directory: terraform/query_lambda_function/tests
run: |
api_base_url="${{ needs.deployment.outputs.api_base_url }}"
echo $api_base_url
bash integration.test.sh $api_base_url
- name: POST /urls Endpoint
working-directory: terraform/command_lambda_function/tests
run: |
api_base_url="${{ needs.deployment.outputs.api_base_url }}"
echo $api_base_url
bash integration.test.sh $api_base_url
load_tests:
needs: [deployment, integration_tests]
name: "API Testing (Load)"
runs-on: ubuntu-latest
container: artilleryio/artillery:latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Make reports directory
run: mkdir reports
- name: Execute load tests for GET /urls/{code} endpoint
env:
TARGET: "${{ needs.deployment.outputs.api_base_url }}"
run: /home/node/artillery/bin/run run --output reports/load_test_report_get_urls_endpoint.json terraform/query_lambda_function/tests/load_test.yaml
- name: Generate HTML report for GET /urls endpoint
run: /home/node/artillery/bin/run report --output reports/load_test_report_get_urls_endpoint.html reports/load_test_report_get_urls_endpoint.json
- name: Execute load tests for POST /urls endpoint
env:
TARGET: "${{ needs.deployment.outputs.api_base_url }}"
run: /home/node/artillery/bin/run run --output reports/load_test_report_post_urls_endpoint.json terraform/query_lambda_function/tests/load_test.yaml
- name: Generate HTML report for GET /urls endpoint
run: /home/node/artillery/bin/run report --output reports/load_test_report_post_urls_endpoint.html reports/load_test_report_post_urls_endpoint.json