added k6 load testing into the template #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |