Skip to content

Commit 78ac9e3

Browse files
SSHing to server to run k6 test on server due to network setup which means the website is not accessible from the Git workflow IPs
1 parent b20c4b8 commit 78ac9e3

File tree

2 files changed

+51
-23
lines changed

2 files changed

+51
-23
lines changed

.github/workflows/k6-performance.yml

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,55 @@ on:
1111
workflow_dispatch:
1212

1313
jobs:
14-
k6-test:
14+
load-test:
1515
runs-on: ubuntu-latest
16-
# Only run if the VM Deploy workflow succeeded
17-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1816

1917
steps:
20-
- name: Checkout code
21-
uses: actions/checkout@v4
18+
- name: Checkout code
19+
uses: actions/checkout@v4
2220

23-
- name: Setup k6
24-
uses: grafana/k6-action@v0.3.1
25-
with:
26-
filename: my-test.js
27-
28-
- name: Run k6 performance test
29-
run: |
30-
echo "Running k6 tests after successful VM deployment..."
31-
k6 run my-test.js --out json=k6-results.json
32-
33-
- name: Upload k6 results
34-
uses: actions/upload-artifact@v4
35-
if: always()
36-
with:
37-
name: k6-performance-results
38-
path: k6-results.json
21+
- name: Copy test file to server
22+
uses: appleboy/scp-action@v0.1.7
23+
with:
24+
host: ${{ secrets.SERVER_IP }}
25+
username: ${{ secrets.SERVER_ADMIN }}
26+
password: ${{ secrets.ADMIN_PASSWORD }}
27+
source: "my-test.js"
28+
target: "/tmp/"
29+
30+
- name: Run K6 test on server
31+
uses: appleboy/ssh-action@v1.2.1
32+
with:
33+
host: ${{ secrets.SERVER_IP }}
34+
username: ${{ secrets.SERVER_ADMIN }}
35+
password: ${{ secrets.ADMIN_PASSWORD }}
36+
script: |
37+
# Install k6 if not already installed
38+
if ! command -v k6 &> /dev/null; then
39+
sudo gpg -k
40+
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
41+
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
42+
sudo apt-get update
43+
sudo apt-get install -y k6
44+
fi
45+
46+
# Run test (use localhost since we're on the server)
47+
cd /tmp
48+
k6 run my-test.js --out json=results.json
49+
50+
- name: Download results
51+
uses: appleboy/scp-action@v0.1.7
52+
with:
53+
host: ${{ secrets.SERVER_IP }}
54+
username: ${{ secrets.SERVER_ADMIN }}
55+
password: ${{ secrets.ADMIN_PASSWORD }}
56+
source: "/tmp/results.json"
57+
target: "."
58+
download: true
59+
60+
- name: Upload results
61+
if: always()
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: k6-results
65+
path: results.json

my-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export const options = {
1111
};
1212

1313
export default function() {
14-
let res = http.get('https://crs-17313-nodegpt.qatar.cmu.edu/');
14+
// Use localhost since we're running ON the server
15+
let res = http.get('https://localhost/');
1516
expect.soft(res.status).toBe(200);
1617
sleep(1);
17-
}
18+
}

0 commit comments

Comments
 (0)