-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (140 loc) · 6.14 KB
/
main.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
name: Application CI
on:
push:
branches:
concurrency:
group: application-ci-${{ github.ref }}
cancel-in-progress: true
jobs:
gradle:
name: 'Gradle Wrapper Validation'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v2
k6-report-ingress:
name: 'App: k6-report-ingress'
runs-on: ubuntu-latest
env:
SPRING_OUTPUT_ANSI_ENABLED: DETECT
SPRING_JPA_SHOW_SQL: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
- name: Build & Test
run: ./gradlew --no-daemon :apps:k6-report-ingress:build
- uses: actions/upload-artifact@v4
with:
name: k6-report-ingress
path: apps/k6-report-ingress/build/libs/*.jar
cli:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
- name: Generate Client
run: ./gradlew --no-daemon :cli:openApiGenerateClient
- name: Build
working-directory: cli
run: cargo build --verbose
- name: Test
working-directory: cli
run: cargo test --verbose
- uses: actions/upload-artifact@v4
with:
name: cli
path: cli/target/debug/cli
integration-test:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs:
- k6-report-ingress
- cli
env:
POSTGRES_PASSWORD: KrPPCHdYSXz6wMct5tUK
POSTGRES_USER: k6_dashboard
POSTGRES_DB: k6_dashboard
services:
timescaledb:
image: timescale/timescaledb:latest-pg16
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_DB: ${{ env.POSTGRES_DB }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: build/artifacts
- name: Create additional database
run: |
PGPASSWORD=${{ env.POSTGRES_PASSWORD }} psql -h localhost -U ${{ env.POSTGRES_USER }} -d ${{ env.POSTGRES_DB }} -c "CREATE DATABASE k6_output;"
- name: Run K6 Tests and Post Report
run: |
docker run --network host -e TIMESCALEDB_JDBC_URL=postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@localhost:5432/k6_output --name k6 -v ${{ github.workspace }}/src/test/k6:/scripts -v ${{ github.workspace }}/dev/k6:/mountpoint golang:alpine3.19 /mountpoint/entrypoint.sh
docker cp k6:/go/report.json ${{ github.workspace }}/src/test/k6/report.json
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- name: Migrate Database
run: ./gradlew :apps:k6-report-ingress:flywayMigrate
- name: Start Application and Upload JSON Report
timeout-minutes: 5
run: |
# Start the application in the background
java -jar "$(find build/artifacts -type f -name '*.jar' -not -name '*-plain.jar')" &
APP_PID=$!
# Wait for the application to be ready
echo "Waiting for application to start..."
while ! nc -z localhost 8080; do
sleep 1 # wait for 1 second before check again
done
echo "Application started. Uploading JSON Report..."
# Upload the JSON report
chmod 755 build/artifacts/cli/cli
build/artifacts/cli/cli upload -u http://localhost:8080 ${{ github.workspace }}/src/test/k6/report.json || exit 1
echo "Uploading done. Waiting for processing to finish..."
# Wait until processing finished
count=1
while [ $count -ne 0 ]; do
sleep 5
echo "Processing not done yet. Retrying..."
output=$(docker run --rm --network host -e PGPASSWORD=${{ env.POSTGRES_PASSWORD }} postgres:16.2-alpine psql -h localhost -U ${{ env.POSTGRES_USER }} -d ${{ env.POSTGRES_DB }} -c "select count(*) from report_processing where processing_status != 1;")
count=$(echo "$output" | grep -Eo '[0-9]+' | head -n 1)
done
echo "Done."
# Optionally, you might want to gracefully shut down your application
kill $APP_PID
env:
SPRING_DATASOURCE_URL: jdbc:postgresql://localhost:5432/${{ env.POSTGRES_DB }}
SPRING_DATASOURCE_USERNAME: ${{ env.POSTGRES_USER }}
SPRING_DATASOURCE_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE: 1GB
- name: Create Database Dumps
run: |
mkdir -p build/artifacts/database
docker run --rm --network host -e PGPASSWORD=${{ env.POSTGRES_PASSWORD }} postgres:16.2-alpine psql -h localhost -U ${{ env.POSTGRES_USER }} -d k6_output -c "COPY (SELECT date_trunc('milliseconds', ts), metric, tags, value FROM samples ORDER BY metric, ts) TO STDOUT WITH CSV HEADER;" > build/artifacts/database/k6_output.csv
cat build/artifacts/database/k6_output.csv | sort > build/artifacts/database/k6_output.csv
docker run --rm --network host -e PGPASSWORD=${{ env.POSTGRES_PASSWORD }} postgres:16.2-alpine psql -h localhost -U ${{ env.POSTGRES_USER }} -d ${{ env.POSTGRES_DB }} -c "COPY (SELECT date_trunc('milliseconds', ts), metric, tags, value FROM samples ORDER BY metric, ts) TO STDOUT WITH CSV HEADER;" > build/artifacts/database/${{ env.POSTGRES_DB }}.csv
cat build/artifacts/database/${{ env.POSTGRES_DB }}.csv | sort > build/artifacts/database/${{ env.POSTGRES_DB }}.csv
- uses: actions/upload-artifact@v4
with:
name: data
path: build/artifacts/database/*.csv
- name: Compare Tables
run: diff build/artifacts/database/k6_output.csv build/artifacts/database/${{ env.POSTGRES_DB }}.csv