adjusting workflows #9
This file contains hidden or 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: k6 Performance Test | |
| on: | |
| push: | |
| branches: [ master ] | |
| pull_request: | |
| branches: [ master ] | |
| jobs: | |
| k6-perf: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Start PostgreSQL with Docker Compose | |
| run: docker compose up -d | |
| - name: Wait for PostgreSQL to be ready | |
| run: | | |
| for i in {1..30}; do | |
| if docker compose exec -T postgres pg_isready -U postgres > /dev/null 2>&1; then | |
| echo "PostgreSQL is ready"; | |
| exit 0; | |
| fi; | |
| echo "Waiting for PostgreSQL..."; | |
| sleep 2; | |
| done | |
| echo "PostgreSQL did not start in time" && exit 1 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: '21' | |
| cache: maven | |
| - name: Build and run tests | |
| run: ./mvnw -B verify | |
| - name: Package application | |
| run: ./mvnw -B -DskipTests package | |
| - name: Start Spring Boot (background) | |
| run: | | |
| nohup java -jar target/k6-performance-test-poc-0.0.1-SNAPSHOT.jar > app.log 2>&1 & echo $! > app.pid | |
| - name: Wait for application to be ready | |
| run: | | |
| for i in {1..30}; do | |
| if curl -s http://localhost:8080/api/products > /dev/null; then | |
| echo "Service is up"; | |
| exit 0; | |
| fi; | |
| echo "Waiting for service..."; | |
| sleep 2; | |
| done | |
| echo "Service did not start in time" && exit 1 | |
| - name: Set up k6 | |
| uses: grafana/setup-k6-action@v1 | |
| - name: Run k6 performance test | |
| run: k6 run src/test/java/com/k6performancetestpoc/k6/test.js | |
| - name: Upload app log on failure | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: app-log | |
| path: app.log | |
| - name: Stop Spring Boot | |
| if: always() | |
| run: | | |
| if [ -f app.pid ]; then | |
| kill $(cat app.pid) || true | |
| fi | |
| - name: Stop Docker Compose | |
| if: always() | |
| run: docker compose down -v |