From 1558107b270f7ba4054f9b9551ff20dfd7e3d7d7 Mon Sep 17 00:00:00 2001 From: Joshua Sajeev <99077093+joshua-sajeev@users.noreply.github.com> Date: Sun, 21 Sep 2025 15:04:03 +0530 Subject: [PATCH 1/3] Update ci.yml --- .github/workflows/ci.yml | 57 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60c092d..2c10b9e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,14 +1,30 @@ -name: Run Tests +name: Tests with Database on: - push: - pull_request: + pull_request: # Only test PRs, not direct pushes to main jobs: test: - name: Go Tests + name: Go Tests with MySQL runs-on: ubuntu-latest + # Start MySQL database + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: testdb + MYSQL_USER: testuser + MYSQL_PASSWORD: testpass + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping -h localhost" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + steps: - name: Checkout code uses: actions/checkout@v4 @@ -21,11 +37,42 @@ jobs: - name: Download dependencies run: go mod download + - name: Wait for MySQL to be ready + run: | + while ! mysqladmin ping -h"127.0.0.1" -P3306 -uroot -proot --silent; do + echo "Waiting for MySQL..." + sleep 2 + done + echo "MySQL is ready!" + - name: Run tests + env: + MYSQL_HOST: 127.0.0.1 + MYSQL_PORT: 3306 + MYSQL_USER: testuser + MYSQL_PASSWORD: testpass + MYSQL_DATABASE: testdb + JWT_SECRET: test-secret-key run: go test ./... -v - name: Run tests with coverage + env: + MYSQL_HOST: 127.0.0.1 + MYSQL_PORT: 3306 + MYSQL_USER: testuser + MYSQL_PASSWORD: testpass + MYSQL_DATABASE: testdb + JWT_SECRET: test-secret-key run: go test ./... -v -coverprofile=coverage.out - - name: Show coverage + - name: Show coverage summary run: go tool cover -func=coverage.out + + - name: Generate HTML coverage report + run: go tool cover -html=coverage.out -o coverage.html + + - name: Upload coverage report + uses: actions/upload-artifact@v3 + with: + name: coverage-report + path: coverage.html From 85a41f96f780380258cce712026392b6c63dd222 Mon Sep 17 00:00:00 2001 From: Joshua Sajeev <99077093+joshua-sajeev@users.noreply.github.com> Date: Sun, 21 Sep 2025 15:10:02 +0530 Subject: [PATCH 2/3] Update ci.yml From cecbd30c7b84520c6d61fcaeafd02ce55fbfd331 Mon Sep 17 00:00:00 2001 From: Joshua Sajeev <99077093+joshua-sajeev@users.noreply.github.com> Date: Sun, 21 Sep 2025 15:11:55 +0530 Subject: [PATCH 3/3] Update ci.yml --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c10b9e..cbd9b63 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,3 +1,6 @@ +# .github/workflows/test-with-mysql.yml +# Full workflow with MySQL database for integration tests + name: Tests with Database on: @@ -72,7 +75,7 @@ jobs: run: go tool cover -html=coverage.out -o coverage.html - name: Upload coverage report - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: coverage-report path: coverage.html