-
Notifications
You must be signed in to change notification settings - Fork 6
170 lines (138 loc) · 5.26 KB
/
k6-load-tests.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
name: Load Tests
on: [pull_request]
jobs:
test-base:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.base.sha }}
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Start containers
run: docker-compose -f "docker-compose.yml" up -d --build
- name: Start Node.js API
run: npm run start:devnet &
# TODO: export environment config variables when base config is implemented into the template
# env:
# SELF_URL: 'http://localhost:3000/assets-cdn'
# PUBLIC_API_PORT: 3000
# PUBLIC_API_PREFIX: 'assets-cdn'
# PRIVATE_API_PORT: 4000
- name: Install k6
run: |
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6
- name: Wait for API to be ready
run: |
until curl --output /dev/null --silent --fail http://localhost:4000/hello; do
echo 'Waiting for API...'
sleep 1
done
- name: Run k6 Load Test
run: k6 run ./k6/script.js
- name: Upload result file for base branch
uses: actions/upload-artifact@v2
with:
name: base-results
path: k6/output/summary.json
test-head:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Start containers
run: docker-compose -f "docker-compose.yml" up -d --build
- name: Build
run: npm run build
- name: Start Node.js API
run: npm run start:devnet &
# TODO: export environment config variables when base config is implemented into the template
# env:
# SELF_URL: 'http://localhost:3000/assets-cdn'
# PUBLIC_API_PORT: 3000
# PUBLIC_API_PREFIX: 'assets-cdn'
# PRIVATE_API_PORT: 4000
- name: Install k6
run: |
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6
- name: Wait for API to be ready
run: |
until curl --output /dev/null --silent --fail http://localhost:4000/hello; do
echo 'Waiting for API...'
sleep 1
done
- name: Run k6 Load Test
run: k6 run ./k6/script.js
- name: Upload result file for head branch
uses: actions/upload-artifact@v2
with:
name: head-results
path: k6/output/summary.json
compare-results:
runs-on: ubuntu-latest
needs: [test-base, test-head]
steps:
- uses: actions/checkout@v2
- name: Download all artifacts
uses: actions/download-artifact@v2
with:
path: artifacts
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Compare test results
run: |
node ./k6/compare-results.js ${{ github.event.pull_request.base.sha }} artifacts/base-results/summary.json ${{ github.event.pull_request.head.sha }} artifacts/head-results/summary.json report.md
- name: Render the report from the template
id: template
uses: chuhlomin/render-template@v1
if: github.event_name == 'pull_request'
with:
template: report.md
vars: |
base: ${{ github.event.pull_request.base.sha }}
head: ${{ github.event.pull_request.head.sha }}
- name: Upload the report markdown
uses: actions/upload-artifact@v3
if: github.event_name == 'pull_request'
with:
name: report-markdown
path: report.md
- name: Find the comment containing the report
id: fc
uses: peter-evans/find-comment@v2
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: 'k6 load testing comparison'
- name: Create or update the report comment
uses: peter-evans/create-or-update-comment@v2
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.template.outputs.result }}
edit-mode: replace