From 9fab87b8e0d9ab47a9c691a067f905772a96a6f2 Mon Sep 17 00:00:00 2001 From: HarK Date: Fri, 17 Oct 2025 19:13:13 +0000 Subject: [PATCH 01/32] Updated workflow to show error on failing test --- .github/workflows/go.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 53550f4233..5d460c0004 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -97,17 +97,16 @@ jobs: id: test uses: nick-fields/retry@v3 with: - timeout_minutes: 5 # Maximum time for the tests to run - max_attempts: 2 # Retry up to 2 times if tests fail + timeout_minutes: 5 + max_attempts: 2 + retry_on: error + shell: bash command: | + set -e export APP_ENV=test - # Run tests for the examples directory with coverage go test ./examples/... -v -short -covermode=atomic -coverprofile packageWithpbgo.cov -coverpkg=./examples/... - # Filter out auto-generated files by protobuf and gofr framework from coverage report grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov - # Display coverage statistics go tool cover -func profile.cov - # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} From f9667c3fe51f36ed0928cfd415cfdb7aaa9c59de Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Mon, 27 Oct 2025 19:41:22 +0530 Subject: [PATCH 02/32] reworked failing tests --- .github/workflows/go.yml | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 53550f4233..7a3a5c3a54 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -41,14 +41,14 @@ jobs: kafka: image: bitnamilegacy/kafka:3.4.1 ports: - - "9092:9092" + - "1092:9092" env: KAFKA_ENABLE_KRAFT: yes KAFKA_CFG_PROCESS_ROLES: broker,controller KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER KAFKA_CFG_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093 KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT - KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:9092 + KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:1092 KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: true KAFKA_BROKER_ID: 1 KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@127.0.0.1:9093 @@ -59,14 +59,14 @@ jobs: redis: image: redis:7.0.5 ports: - - "2002:6379" + - "2001:6379" options: "--entrypoint redis-server" # MySQL service mysql: image: mysql:8.2.0 ports: - - "2001:3306" + - "2002:3306" env: MYSQL_ROOT_PASSWORD: "password" MYSQL_DATABASE: "test" @@ -93,21 +93,23 @@ jobs: run: docker run -d -p 2005:9411 openzipkin/zipkin:latest # Run tests with automatic retry on failures - - name: Test with Retry Logic - id: test - uses: nick-fields/retry@v3 - with: - timeout_minutes: 5 # Maximum time for the tests to run - max_attempts: 2 # Retry up to 2 times if tests fail - command: | - export APP_ENV=test - # Run tests for the examples directory with coverage - go test ./examples/... -v -short -covermode=atomic -coverprofile packageWithpbgo.cov -coverpkg=./examples/... - # Filter out auto-generated files by protobuf and gofr framework from coverage report - grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov - # Display coverage statistics - go tool cover -func profile.cov - + + - name: Wait for services to be ready + run: | + set -e + echo "Waiting for Redis (localhost:2001), Kafka (localhost:1092) and MySQL (localhost:2002)..." + attempts=0 + max=60 + while : ; do + nc -z 127.0.0.1 2001 >/dev/null 2>&1 && nc -z 127.0.0.1 1092 >/dev/null 2>&1 && nc -z 127.0.0.1 2002 >/dev/null 2>&1 && break + attempts=$((attempts+1)) + if [ $attempts -ge $max ]; then + echo "Timeout waiting for services" + exit 1 + fi + sleep 1 + done + echo "Services ready." # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} From 69a9fc2f4dc1880a3cf8612e880c930b2c6e3cbf Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Mon, 27 Oct 2025 19:49:27 +0530 Subject: [PATCH 03/32] Added retries --- .github/workflows/go.yml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 73b7f4fbab..937b17f2c8 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -93,23 +93,6 @@ jobs: run: docker run -d -p 2005:9411 openzipkin/zipkin:latest # Run tests with automatic retry on failures - - - name: Wait for services to be ready - run: | - set -e - echo "Waiting for Redis (localhost:2001), Kafka (localhost:1092) and MySQL (localhost:2002)..." - attempts=0 - max=60 - while : ; do - nc -z 127.0.0.1 2001 >/dev/null 2>&1 && nc -z 127.0.0.1 1092 >/dev/null 2>&1 && nc -z 127.0.0.1 2002 >/dev/null 2>&1 && break - attempts=$((attempts+1)) - if [ $attempts -ge $max ]; then - echo "Timeout waiting for services" - exit 1 - fi - sleep 1 - done - echo "Services ready." - name: Test with Retry Logic id: test uses: nick-fields/retry@v3 From 8a2f6ba6d36da15b208cf13aed98699bcb72182b Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Mon, 27 Oct 2025 20:03:31 +0530 Subject: [PATCH 04/32] Changes --- .github/workflows/go.yml | 52 +++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 937b17f2c8..ef53f59333 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -37,7 +37,7 @@ jobs: # Define service containers that tests depend on services: - # Kafka service + # Kafka service — expose host port 1092 so tests using localhost:1092 connect to Kafka kafka: image: bitnamilegacy/kafka:3.4.1 ports: @@ -48,6 +48,7 @@ jobs: KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER KAFKA_CFG_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093 KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT + # advertise the host port that tests use KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:1092 KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: true KAFKA_BROKER_ID: 1 @@ -55,14 +56,14 @@ jobs: ALLOW_PLAINTEXT_LISTENER: yes KAFKA_CFG_NODE_ID: 1 - # Redis service + # Redis service — tests expect Redis at localhost:2001, so expose 2001 redis: image: redis:7.0.5 ports: - "2001:6379" options: "--entrypoint redis-server" - # MySQL service + # MySQL service — move MySQL to a different host port to avoid conflict with Redis mysql: image: mysql:8.2.0 ports: @@ -88,24 +89,41 @@ jobs: - name: Get dependencies run: | go mod download - - name: Start Zipkin run: docker run -d -p 2005:9411 openzipkin/zipkin:latest + # Wait for service ports to be ready before running tests (prevents race conditions) + - name: Wait for services to be ready + run: | + set -e + echo "Waiting for Redis (localhost:2001), Kafka (localhost:1092) and MySQL (localhost:2002)..." + attempts=0 + max=60 + while : ; do + nc -z 127.0.0.1 2001 >/dev/null 2>&1 && nc -z 127.0.0.1 1092 >/dev/null 2>&1 && nc -z 127.0.0.1 2002 >/dev/null 2>&1 && break + attempts=$((attempts+1)) + if [ $attempts -ge $max ]; then + echo "Timeout waiting for services" + exit 1 + fi + sleep 1 + done + echo "Services ready." + # Run tests with automatic retry on failures - name: Test with Retry Logic id: test uses: nick-fields/retry@v3 with: - timeout_minutes: 5 - max_attempts: 2 - retry_on: error - shell: bash + timeout_minutes: 5 # Maximum time for the tests to run + max_attempts: 2 # Retry up to 2 times if tests fail command: | - set -e export APP_ENV=test + # Run tests for the examples directory with coverage go test ./examples/... -v -short -covermode=atomic -coverprofile packageWithpbgo.cov -coverpkg=./examples/... + # Filter out auto-generated files by protobuf and gofr framework from coverage report grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov + # Display coverage statistics go tool cover -func profile.cov # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage @@ -139,7 +157,6 @@ jobs: - name: Get dependencies run: | go mod download - # Run pkg tests with automatic retry logic - name: Test with Retry Logic id: test @@ -150,7 +167,6 @@ jobs: retry_on: error command: | export APP_ENV=test - # Run tests for root gofr package go test -v -short -covermode=atomic \ -coverpkg=./pkg/gofr -coverprofile=gofr_only.cov ./pkg/gofr @@ -162,7 +178,6 @@ jobs: echo "::error::Root gofr package tests failed" exit $exit_code fi - # Run tests for sub-packages go test -v -covermode=atomic \ -coverpkg=./pkg/gofr -coverprofile=submodules.cov ./pkg/gofr/... @@ -174,14 +189,11 @@ jobs: echo "::error::Gofr sub-packages tests failed" exit $exit_code fi - # Combine coverage profiles echo "mode: atomic" > profile.cov grep -h -v "mode:" gofr_only.cov submodules.cov | grep -v '/mock_' >> profile.cov - # Show coverage summary go tool cover -func profile.cov - # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} @@ -212,7 +224,6 @@ jobs: run: | echo "mode: atomic" > merged_profile.cov grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov - # Calculate and output the total code coverage percentage - name: Parse code-coverage value working-directory: artifacts @@ -221,7 +232,6 @@ jobs: codeCoverage=${codeCoverage%?} echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV echo "✅ Total Code Coverage: $codeCoverage%" - # - name: Check if code-coverage is greater than threshold # run: | # codeCoverage=${{ env.CODE_COVERAGE }} @@ -256,7 +266,6 @@ jobs: # Find all directories containing a go.mod file within 'pkg' SUBMODULES=$(find pkg -name "go.mod" -exec dirname {} \; | jq -R -s -c 'split("\n") | map(select(length > 0))') echo "submodules=$SUBMODULES" >> $GITHUB_OUTPUT - # Test all submodules in parallel with retry logic - name: Test Submodules with Retry and Parallelism id: test_submodules @@ -293,7 +302,6 @@ jobs: cd - ' - # Upload submodule coverage reports as an artifact - name: Upload Coverage Reports uses: actions/upload-artifact@v4 @@ -321,7 +329,6 @@ jobs: run: | curl https://qlty.sh | sh echo "$HOME/.qlty/bin" >> $GITHUB_PATH - # Download coverage artifacts - name: Download Coverage Report uses: actions/download-artifact@v5 @@ -334,7 +341,6 @@ jobs: run: | echo "mode: atomic" > merged_profile.cov grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov - # Generate and print total coverage percentage echo "Total Coverage:" go tool cover -func=merged_profile.cov | tail -n 1 @@ -365,16 +371,13 @@ jobs: - name: Install golangci-lint run: | go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0 - - name: Get dependencies run: | go mod tidy - # Run linter on the root module - name: Lint Root Module run: | golangci-lint run --output.text.print-issued-lines --output.text.colors=true --show-stats=false --timeout=5m - # Run linter on each submodule - name: Lint Submodules run: | @@ -393,7 +396,6 @@ jobs: echo "Linting failed for $total_errors submodule(s)." exit 1 # Fail the job if there are linting errors in submodules fi - # Job for checking filename conventions linting_party: name: Linting Party🥳 From 5f564cfe983e08b26b1896df16713690188c2ee9 Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Mon, 27 Oct 2025 20:11:58 +0530 Subject: [PATCH 05/32] Added wait for services --- .github/workflows/go.yml | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ef53f59333..eaab36f3d5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -95,20 +95,15 @@ jobs: # Wait for service ports to be ready before running tests (prevents race conditions) - name: Wait for services to be ready run: | - set -e - echo "Waiting for Redis (localhost:2001), Kafka (localhost:1092) and MySQL (localhost:2002)..." - attempts=0 - max=60 - while : ; do - nc -z 127.0.0.1 2001 >/dev/null 2>&1 && nc -z 127.0.0.1 1092 >/dev/null 2>&1 && nc -z 127.0.0.1 2002 >/dev/null 2>&1 && break - attempts=$((attempts+1)) - if [ $attempts -ge $max ]; then - echo "Timeout waiting for services" - exit 1 - fi - sleep 1 - done - echo "Services ready." + echo "Waiting for MySQL..." + until mysqladmin ping -h mysql -ppassword --silent; do sleep 2; done + + echo "Waiting for Redis..." + until redis-cli -h redis ping; do sleep 2; done + + echo "Waiting for Kafka..." + until nc -z kafka 9092; do sleep 2; done + # Run tests with automatic retry on failures - name: Test with Retry Logic From 2db12418e1b02221b3435cf0f379ea742e6c3d21 Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Mon, 27 Oct 2025 20:23:18 +0530 Subject: [PATCH 06/32] Added ignore password error --- .github/workflows/go.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index eaab36f3d5..c790cd72f1 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -96,15 +96,16 @@ jobs: - name: Wait for services to be ready run: | echo "Waiting for MySQL..." - until mysqladmin ping -h mysql -ppassword --silent; do sleep 2; done + until mysqladmin ping -h mysql -ppassword --silent 2>/dev/null; do sleep 2; done echo "Waiting for Redis..." - until redis-cli -h redis ping; do sleep 2; done + until redis-cli -h redis ping &>/dev/null; do sleep 2; done echo "Waiting for Kafka..." until nc -z kafka 9092; do sleep 2; done + # Run tests with automatic retry on failures - name: Test with Retry Logic id: test From f0c5e5e86b7eadb94c91112f63fdd97d1041e195 Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Mon, 27 Oct 2025 20:30:05 +0530 Subject: [PATCH 07/32] Added alternative to get services reade --- .github/workflows/go.yml | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c790cd72f1..baf7a82e6e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -93,17 +93,45 @@ jobs: run: docker run -d -p 2005:9411 openzipkin/zipkin:latest # Wait for service ports to be ready before running tests (prevents race conditions) + - name: Wait for services to be ready run: | - echo "Waiting for MySQL..." - until mysqladmin ping -h mysql -ppassword --silent 2>/dev/null; do sleep 2; done + set +e # Don't exit on individual command failures + + echo "Waiting for MySQL on 127.0.0.1:2002..." + for i in {1..60}; do + if timeout 2 bash -c 'echo > /dev/tcp/127.0.0.1/2002' 2>/dev/null; then + echo "✓ MySQL port is open" + sleep 2 # Give MySQL time to fully initialize + break + fi + echo " Attempt $i/60..." + sleep 1 + done - echo "Waiting for Redis..." - until redis-cli -h redis ping &>/dev/null; do sleep 2; done + echo "Waiting for Redis on 127.0.0.1:2001..." + for i in {1..60}; do + if timeout 2 bash -c 'echo > /dev/tcp/127.0.0.1/2001' 2>/dev/null; then + echo "✓ Redis port is open" + break + fi + echo " Attempt $i/60..." + sleep 1 + done - echo "Waiting for Kafka..." - until nc -z kafka 9092; do sleep 2; done + echo "Waiting for Kafka on 127.0.0.1:1092..." + for i in {1..60}; do + if timeout 2 bash -c 'echo > /dev/tcp/127.0.0.1/1092' 2>/dev/null; then + echo "✓ Kafka port is open" + break + fi + echo " Attempt $i/60..." + sleep 1 + done + echo "All services should be ready!" + sleep 3 # Final buffer + shell: bash # Run tests with automatic retry on failures From b52759dd334de61349dd855f1fb017b8bafa0a25 Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 13:53:39 +0530 Subject: [PATCH 08/32] Resolved issues --- .github/workflows/go.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 9f91e424fe..d40a13e962 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -133,7 +133,6 @@ jobs: sleep 3 # Final buffer shell: bash - # Run tests with automatic retry on failures - name: Test with Retry Logic id: test @@ -149,6 +148,7 @@ jobs: grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov # Display coverage statistics go tool cover -func profile.cov + # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} @@ -181,6 +181,7 @@ jobs: - name: Get dependencies run: | go mod download + # Run pkg tests with automatic retry logic - name: Test with Retry Logic id: test From b49c060ac7a0a17e09e2a0385c8eb91bd238b74f Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 16:18:58 +0530 Subject: [PATCH 09/32] Reverted whitespaces and added healthchecks --- .github/workflows/go.yml | 74 +++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d40a13e962..ee9a7b8da4 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -55,13 +55,24 @@ jobs: KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@127.0.0.1:9093 ALLOW_PLAINTEXT_LISTENER: yes KAFKA_CFG_NODE_ID: 1 - + options: >- + --health-cmd='kafka-broker-api-versions.sh --bootstrap-server 127.0.0.1:9092' + --health-interval=5s + --health-timeout=10s + --health-retries=5 + --health-start-period=10s # Redis service — tests expect Redis at localhost:2001, so expose 2001 redis: image: redis:7.0.5 ports: - "2001:6379" - options: "--entrypoint redis-server" + options: >- + --entrypoint redis-server + --health-cmd='redis-cli ping' + --health-interval=5s + --health-timeout=5s + --health-retries=5 + --health-start-period=5s # MySQL service — move MySQL to a different host port to avoid conflict with Redis mysql: @@ -71,6 +82,12 @@ jobs: env: MYSQL_ROOT_PASSWORD: "password" MYSQL_DATABASE: "test" + options: >- + --health-cmd='mysqladmin ping -h localhost -ppassword --silent' + --health-interval=5s + --health-timeout=5s + --health-retries=10 + --health-start-period=5s # Steps to execute for this job steps: @@ -92,47 +109,6 @@ jobs: - name: Start Zipkin run: docker run -d -p 2005:9411 openzipkin/zipkin:latest - # Wait for service ports to be ready before running tests (prevents race conditions) - - - name: Wait for services to be ready - run: | - set +e # Don't exit on individual command failures - - echo "Waiting for MySQL on 127.0.0.1:2002..." - for i in {1..60}; do - if timeout 2 bash -c 'echo > /dev/tcp/127.0.0.1/2002' 2>/dev/null; then - echo "✓ MySQL port is open" - sleep 2 # Give MySQL time to fully initialize - break - fi - echo " Attempt $i/60..." - sleep 1 - done - - echo "Waiting for Redis on 127.0.0.1:2001..." - for i in {1..60}; do - if timeout 2 bash -c 'echo > /dev/tcp/127.0.0.1/2001' 2>/dev/null; then - echo "✓ Redis port is open" - break - fi - echo " Attempt $i/60..." - sleep 1 - done - - echo "Waiting for Kafka on 127.0.0.1:1092..." - for i in {1..60}; do - if timeout 2 bash -c 'echo > /dev/tcp/127.0.0.1/1092' 2>/dev/null; then - echo "✓ Kafka port is open" - break - fi - echo " Attempt $i/60..." - sleep 1 - done - - echo "All services should be ready!" - sleep 3 # Final buffer - shell: bash - # Run tests with automatic retry on failures - name: Test with Retry Logic id: test @@ -192,6 +168,7 @@ jobs: retry_on: error command: | export APP_ENV=test + # Run tests for root gofr package go test -v -short -covermode=atomic \ -coverpkg=./pkg/gofr -coverprofile=gofr_only.cov ./pkg/gofr @@ -203,6 +180,7 @@ jobs: echo "::error::Root gofr package tests failed" exit $exit_code fi + # Run tests for sub-packages go test -v -covermode=atomic \ -coverpkg=./pkg/gofr -coverprofile=submodules.cov ./pkg/gofr/... @@ -214,11 +192,14 @@ jobs: echo "::error::Gofr sub-packages tests failed" exit $exit_code fi + # Combine coverage profiles echo "mode: atomic" > profile.cov grep -h -v "mode:" gofr_only.cov submodules.cov | grep -v '/mock_' >> profile.cov + # Show coverage summary go tool cover -func profile.cov + # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} @@ -249,6 +230,7 @@ jobs: run: | echo "mode: atomic" > merged_profile.cov grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov + # Calculate and output the total code coverage percentage - name: Parse code-coverage value working-directory: artifacts @@ -291,6 +273,7 @@ jobs: # Find all directories containing a go.mod file within 'pkg' SUBMODULES=$(find pkg -name "go.mod" -exec dirname {} \; | jq -R -s -c 'split("\n") | map(select(length > 0))') echo "submodules=$SUBMODULES" >> $GITHUB_OUTPUT + # Test all submodules in parallel with retry logic - name: Test Submodules with Retry and Parallelism id: test_submodules @@ -354,6 +337,7 @@ jobs: run: | curl https://qlty.sh | sh echo "$HOME/.qlty/bin" >> $GITHUB_PATH + # Download coverage artifacts - name: Download Coverage Report uses: actions/download-artifact@v6 @@ -396,13 +380,16 @@ jobs: - name: Install golangci-lint run: | go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0 + - name: Get dependencies run: | go mod tidy + # Run linter on the root module - name: Lint Root Module run: | golangci-lint run --output.text.print-issued-lines --output.text.colors=true --show-stats=false --timeout=5m + # Run linter on each submodule - name: Lint Submodules run: | @@ -421,6 +408,7 @@ jobs: echo "Linting failed for $total_errors submodule(s)." exit 1 # Fail the job if there are linting errors in submodules fi + # Job for checking filename conventions linting_party: name: Linting Party🥳 From b9b7c10438799ae3415850edaf7418e06a14ff84 Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 16:25:26 +0530 Subject: [PATCH 10/32] Resolved remaining whitespace issues --- .github/workflows/go.yml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ee9a7b8da4..1ac8b9be69 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -106,6 +106,7 @@ jobs: - name: Get dependencies run: | go mod download + - name: Start Zipkin run: docker run -d -p 2005:9411 openzipkin/zipkin:latest @@ -124,7 +125,7 @@ jobs: grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov # Display coverage statistics go tool cover -func profile.cov - + # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} @@ -168,7 +169,7 @@ jobs: retry_on: error command: | export APP_ENV=test - + # Run tests for root gofr package go test -v -short -covermode=atomic \ -coverpkg=./pkg/gofr -coverprofile=gofr_only.cov ./pkg/gofr @@ -196,10 +197,10 @@ jobs: # Combine coverage profiles echo "mode: atomic" > profile.cov grep -h -v "mode:" gofr_only.cov submodules.cov | grep -v '/mock_' >> profile.cov - + # Show coverage summary go tool cover -func profile.cov - + # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} @@ -230,7 +231,7 @@ jobs: run: | echo "mode: atomic" > merged_profile.cov grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov - + # Calculate and output the total code coverage percentage - name: Parse code-coverage value working-directory: artifacts @@ -239,6 +240,7 @@ jobs: codeCoverage=${codeCoverage%?} echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV echo "✅ Total Code Coverage: $codeCoverage%" + # - name: Check if code-coverage is greater than threshold # run: | # codeCoverage=${{ env.CODE_COVERAGE }} @@ -310,6 +312,7 @@ jobs: cd - ' + # Upload submodule coverage reports as an artifact - name: Upload Coverage Reports uses: actions/upload-artifact@v5 @@ -337,7 +340,7 @@ jobs: run: | curl https://qlty.sh | sh echo "$HOME/.qlty/bin" >> $GITHUB_PATH - + # Download coverage artifacts - name: Download Coverage Report uses: actions/download-artifact@v6 @@ -350,6 +353,7 @@ jobs: run: | echo "mode: atomic" > merged_profile.cov grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov + # Generate and print total coverage percentage echo "Total Coverage:" go tool cover -func=merged_profile.cov | tail -n 1 @@ -380,16 +384,16 @@ jobs: - name: Install golangci-lint run: | go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0 - + - name: Get dependencies run: | go mod tidy - + # Run linter on the root module - name: Lint Root Module run: | golangci-lint run --output.text.print-issued-lines --output.text.colors=true --show-stats=false --timeout=5m - + # Run linter on each submodule - name: Lint Submodules run: | @@ -408,7 +412,7 @@ jobs: echo "Linting failed for $total_errors submodule(s)." exit 1 # Fail the job if there are linting errors in submodules fi - + # Job for checking filename conventions linting_party: name: Linting Party🥳 From 0772f3b9078c46e4050cb9a641610b272aec9a14 Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 16:27:50 +0530 Subject: [PATCH 11/32] Pruning whitespaces --- .github/workflows/go.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 1ac8b9be69..cd762d4ab0 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -158,7 +158,7 @@ jobs: - name: Get dependencies run: | go mod download - + # Run pkg tests with automatic retry logic - name: Test with Retry Logic id: test @@ -169,7 +169,7 @@ jobs: retry_on: error command: | export APP_ENV=test - + # Run tests for root gofr package go test -v -short -covermode=atomic \ -coverpkg=./pkg/gofr -coverprofile=gofr_only.cov ./pkg/gofr @@ -275,7 +275,7 @@ jobs: # Find all directories containing a go.mod file within 'pkg' SUBMODULES=$(find pkg -name "go.mod" -exec dirname {} \; | jq -R -s -c 'split("\n") | map(select(length > 0))') echo "submodules=$SUBMODULES" >> $GITHUB_OUTPUT - + # Test all submodules in parallel with retry logic - name: Test Submodules with Retry and Parallelism id: test_submodules From 8c4bb12d60ec88062cda99c627ac5214d4169ddc Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 16:32:49 +0530 Subject: [PATCH 12/32] Resolved health checkup --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index cd762d4ab0..82f538c5a4 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -56,7 +56,7 @@ jobs: ALLOW_PLAINTEXT_LISTENER: yes KAFKA_CFG_NODE_ID: 1 options: >- - --health-cmd='kafka-broker-api-versions.sh --bootstrap-server 127.0.0.1:9092' + --health-cmd='kafka-broker-api-versions.sh --broker-list 127.0.0.1:9092' --health-interval=5s --health-timeout=10s --health-retries=5 From cf691bfa457a2a313dcf487e8c90f472fa14b644 Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 16:39:12 +0530 Subject: [PATCH 13/32] Changed to ping --- .github/workflows/go.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 82f538c5a4..9a3e2c7528 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -56,11 +56,11 @@ jobs: ALLOW_PLAINTEXT_LISTENER: yes KAFKA_CFG_NODE_ID: 1 options: >- - --health-cmd='kafka-broker-api-versions.sh --broker-list 127.0.0.1:9092' + --health-cmd='bash -c "echo > /dev/tcp/127.0.0.1/9092"' --health-interval=5s - --health-timeout=10s - --health-retries=5 - --health-start-period=10s + --health-timeout=5s + --health-retries=10 + --health-start-period=15s # Redis service — tests expect Redis at localhost:2001, so expose 2001 redis: image: redis:7.0.5 From b5b886a003a83bd9eb98062544a3a496fd70e934 Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 17:05:46 +0530 Subject: [PATCH 14/32] Added kafka checks --- .github/workflows/go.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 9a3e2c7528..4ddce534f2 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -56,11 +56,12 @@ jobs: ALLOW_PLAINTEXT_LISTENER: yes KAFKA_CFG_NODE_ID: 1 options: >- - --health-cmd='bash -c "echo > /dev/tcp/127.0.0.1/9092"' - --health-interval=5s + --health-cmd="kafka-topics.sh --list --bootstrap-server localhost:9092 || exit 1" + --health-interval=10s --health-timeout=5s --health-retries=10 - --health-start-period=15s + --health-start-period=25s + # Redis service — tests expect Redis at localhost:2001, so expose 2001 redis: image: redis:7.0.5 From b77170e6a82cd2e9ee22ee45ef1ecca4f45405ca Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 17:07:52 +0530 Subject: [PATCH 15/32] Changes --- .github/workflows/go.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 4ddce534f2..835eb00d78 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -69,7 +69,7 @@ jobs: - "2001:6379" options: >- --entrypoint redis-server - --health-cmd='redis-cli ping' + --health-cmd="redis-cli ping" --health-interval=5s --health-timeout=5s --health-retries=5 @@ -84,7 +84,7 @@ jobs: MYSQL_ROOT_PASSWORD: "password" MYSQL_DATABASE: "test" options: >- - --health-cmd='mysqladmin ping -h localhost -ppassword --silent' + --health-cmd="mysqladmin ping -h localhost -ppassword --silent" --health-interval=5s --health-timeout=5s --health-retries=10 From 043b7c8fb29545a46955155ef858ca69c33a165f Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 17:28:09 +0530 Subject: [PATCH 16/32] Removed health check for kafka --- .github/workflows/go.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 835eb00d78..847f90f8b2 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -55,12 +55,6 @@ jobs: KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@127.0.0.1:9093 ALLOW_PLAINTEXT_LISTENER: yes KAFKA_CFG_NODE_ID: 1 - options: >- - --health-cmd="kafka-topics.sh --list --bootstrap-server localhost:9092 || exit 1" - --health-interval=10s - --health-timeout=5s - --health-retries=10 - --health-start-period=25s # Redis service — tests expect Redis at localhost:2001, so expose 2001 redis: From 6199300e47703d4981eed0c4c109596479f6ff84 Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 19:52:48 +0530 Subject: [PATCH 17/32] Changed continue on error --- .github/workflows/go.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 847f90f8b2..440a3f409a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -112,7 +112,9 @@ jobs: with: timeout_minutes: 5 # Maximum time for the tests to run max_attempts: 2 # Retry up to 2 times if tests fail + continue-on-error: false command: | + set -e export APP_ENV=test # Run tests for the examples directory with coverage go test ./examples/... -v -short -covermode=atomic -coverprofile packageWithpbgo.cov -coverpkg=./examples/... From 85b50f609f7ba9f4604ec4abf27f86fcc44bb15e Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 19:58:31 +0530 Subject: [PATCH 18/32] repair --- .github/workflows/go.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 440a3f409a..89c8c0176f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -109,17 +109,17 @@ jobs: - name: Test with Retry Logic id: test uses: nick-fields/retry@v3 + continue-on-error: false with: timeout_minutes: 5 # Maximum time for the tests to run max_attempts: 2 # Retry up to 2 times if tests fail - continue-on-error: false command: | set -e export APP_ENV=test # Run tests for the examples directory with coverage go test ./examples/... -v -short -covermode=atomic -coverprofile packageWithpbgo.cov -coverpkg=./examples/... # Filter out auto-generated files by protobuf and gofr framework from coverage report - grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov + grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov || true # Display coverage statistics go tool cover -func profile.cov From 4ffabaaf774d089a72d62822d0081f0b17c3fe87 Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 22:14:27 +0530 Subject: [PATCH 19/32] Added continue_on_error false --- .github/workflows/go.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 89c8c0176f..f79ac1debe 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -113,6 +113,7 @@ jobs: with: timeout_minutes: 5 # Maximum time for the tests to run max_attempts: 2 # Retry up to 2 times if tests fail + continue_on_error: false command: | set -e export APP_ENV=test From 6944eaab428ab54570df135779002d6530a27430 Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 22:21:36 +0530 Subject: [PATCH 20/32] Made default ports --- .github/workflows/go.yml | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f79ac1debe..dea35c287e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -41,15 +41,14 @@ jobs: kafka: image: bitnamilegacy/kafka:3.4.1 ports: - - "1092:9092" + - "9092:9092" env: KAFKA_ENABLE_KRAFT: yes KAFKA_CFG_PROCESS_ROLES: broker,controller KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER KAFKA_CFG_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093 KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT - # advertise the host port that tests use - KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:1092 + KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:9092 KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: true KAFKA_BROKER_ID: 1 KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@127.0.0.1:9093 @@ -60,20 +59,14 @@ jobs: redis: image: redis:7.0.5 ports: - - "2001:6379" - options: >- - --entrypoint redis-server - --health-cmd="redis-cli ping" - --health-interval=5s - --health-timeout=5s - --health-retries=5 - --health-start-period=5s + - "2002:6379" + options: "--entrypoint redis-server" # MySQL service — move MySQL to a different host port to avoid conflict with Redis mysql: image: mysql:8.2.0 ports: - - "2002:3306" + - "2001:3306" env: MYSQL_ROOT_PASSWORD: "password" MYSQL_DATABASE: "test" From 2b9be016d74541c640cbe5fd3abb509ce38b396b Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 22:43:40 +0530 Subject: [PATCH 21/32] Final touches --- .github/workflows/go.yml | 82 ++++++++++------------------------------ 1 file changed, 21 insertions(+), 61 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index dea35c287e..8952dcc7f8 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -9,6 +9,7 @@ on: push: branches: - main + - test3 - development paths-ignore: - 'docs/**' # Ignore changes to docs folder @@ -37,45 +38,39 @@ jobs: # Define service containers that tests depend on services: - # Kafka service — expose host port 1092 so tests using localhost:1092 connect to Kafka + # Kafka service kafka: image: bitnamilegacy/kafka:3.4.1 ports: - - "9092:9092" + - "1092:9092" env: KAFKA_ENABLE_KRAFT: yes KAFKA_CFG_PROCESS_ROLES: broker,controller KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER KAFKA_CFG_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093 KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT - KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:9092 + KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:1092 KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: true KAFKA_BROKER_ID: 1 KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@127.0.0.1:9093 ALLOW_PLAINTEXT_LISTENER: yes KAFKA_CFG_NODE_ID: 1 - # Redis service — tests expect Redis at localhost:2001, so expose 2001 + # Redis service redis: image: redis:7.0.5 ports: - - "2002:6379" + - "2001:6379" options: "--entrypoint redis-server" - # MySQL service — move MySQL to a different host port to avoid conflict with Redis + # MySQL service mysql: image: mysql:8.2.0 ports: - - "2001:3306" + - "2009:3306" env: MYSQL_ROOT_PASSWORD: "password" MYSQL_DATABASE: "test" - options: >- - --health-cmd="mysqladmin ping -h localhost -ppassword --silent" - --health-interval=5s - --health-timeout=5s - --health-retries=10 - --health-start-period=5s # Steps to execute for this job steps: @@ -94,7 +89,6 @@ jobs: - name: Get dependencies run: | go mod download - - name: Start Zipkin run: docker run -d -p 2005:9411 openzipkin/zipkin:latest @@ -102,21 +96,22 @@ jobs: - name: Test with Retry Logic id: test uses: nick-fields/retry@v3 - continue-on-error: false with: timeout_minutes: 5 # Maximum time for the tests to run - max_attempts: 2 # Retry up to 2 times if tests fail + max_attempts: 2 # Retry up to 2 times if tests fail continue_on_error: false + retry_on: error command: | set -e export APP_ENV=test # Run tests for the examples directory with coverage go test ./examples/... -v -short -covermode=atomic -coverprofile packageWithpbgo.cov -coverpkg=./examples/... # Filter out auto-generated files by protobuf and gofr framework from coverage report - grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov || true + grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov # Display coverage statistics go tool cover -func profile.cov - + + # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} @@ -125,7 +120,7 @@ jobs: name: Example-Test-Report path: profile.cov - # Job for testing the pkg directory + # Job for testing the pkg directorypk PKG-Unit-Testing: name: PKG Unit Testing (v${{ matrix.go-version }})🛠 runs-on: ubuntu-latest @@ -149,7 +144,6 @@ jobs: - name: Get dependencies run: | go mod download - # Run pkg tests with automatic retry logic - name: Test with Retry Logic id: test @@ -157,41 +151,17 @@ jobs: with: timeout_minutes: 5 max_attempts: 2 + continue_on_error: false retry_on: error command: | + set -e export APP_ENV=test - - # Run tests for root gofr package - go test -v -short -covermode=atomic \ - -coverpkg=./pkg/gofr -coverprofile=gofr_only.cov ./pkg/gofr - exit_code=$? - if [ $exit_code -eq 2 ]; then - echo "::error::Panic detected in root gofr package tests" - exit 2 - elif [ $exit_code -ne 0 ]; then - echo "::error::Root gofr package tests failed" - exit $exit_code - fi - - # Run tests for sub-packages - go test -v -covermode=atomic \ - -coverpkg=./pkg/gofr -coverprofile=submodules.cov ./pkg/gofr/... - exit_code=$? - if [ $exit_code -eq 2 ]; then - echo "::error::Panic detected in gofr sub-packages tests" - exit 2 - elif [ $exit_code -ne 0 ]; then - echo "::error::Gofr sub-packages tests failed" - exit $exit_code - fi - - # Combine coverage profiles - echo "mode: atomic" > profile.cov - grep -h -v "mode:" gofr_only.cov submodules.cov | grep -v '/mock_' >> profile.cov - - # Show coverage summary + # Run tests for the examples directory with coverage + go test ./examples/... -v -short -covermode=atomic -coverprofile packageWithpbgo.cov -coverpkg=./examples/... + # Filter out auto-generated files by protobuf and gofr framework from coverage report + grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov + # Display coverage statistics go tool cover -func profile.cov - # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} @@ -222,7 +192,6 @@ jobs: run: | echo "mode: atomic" > merged_profile.cov grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov - # Calculate and output the total code coverage percentage - name: Parse code-coverage value working-directory: artifacts @@ -231,7 +200,6 @@ jobs: codeCoverage=${codeCoverage%?} echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV echo "✅ Total Code Coverage: $codeCoverage%" - # - name: Check if code-coverage is greater than threshold # run: | # codeCoverage=${{ env.CODE_COVERAGE }} @@ -266,7 +234,6 @@ jobs: # Find all directories containing a go.mod file within 'pkg' SUBMODULES=$(find pkg -name "go.mod" -exec dirname {} \; | jq -R -s -c 'split("\n") | map(select(length > 0))') echo "submodules=$SUBMODULES" >> $GITHUB_OUTPUT - # Test all submodules in parallel with retry logic - name: Test Submodules with Retry and Parallelism id: test_submodules @@ -303,7 +270,6 @@ jobs: cd - ' - # Upload submodule coverage reports as an artifact - name: Upload Coverage Reports uses: actions/upload-artifact@v5 @@ -331,7 +297,6 @@ jobs: run: | curl https://qlty.sh | sh echo "$HOME/.qlty/bin" >> $GITHUB_PATH - # Download coverage artifacts - name: Download Coverage Report uses: actions/download-artifact@v6 @@ -344,7 +309,6 @@ jobs: run: | echo "mode: atomic" > merged_profile.cov grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov - # Generate and print total coverage percentage echo "Total Coverage:" go tool cover -func=merged_profile.cov | tail -n 1 @@ -375,16 +339,13 @@ jobs: - name: Install golangci-lint run: | go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0 - - name: Get dependencies run: | go mod tidy - # Run linter on the root module - name: Lint Root Module run: | golangci-lint run --output.text.print-issued-lines --output.text.colors=true --show-stats=false --timeout=5m - # Run linter on each submodule - name: Lint Submodules run: | @@ -403,7 +364,6 @@ jobs: echo "Linting failed for $total_errors submodule(s)." exit 1 # Fail the job if there are linting errors in submodules fi - # Job for checking filename conventions linting_party: name: Linting Party🥳 From a598a7ee5d6819fd2e6bd54f191d30bca84428c9 Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 23:02:27 +0530 Subject: [PATCH 22/32] More changes --- .github/workflows/go.yml | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 8952dcc7f8..14d016537c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -89,6 +89,7 @@ jobs: - name: Get dependencies run: | go mod download + - name: Start Zipkin run: docker run -d -p 2005:9411 openzipkin/zipkin:latest @@ -102,16 +103,28 @@ jobs: continue_on_error: false retry_on: error command: | - set -e - export APP_ENV=test + # Run tests for sub-packages + go test -v -covermode=atomic \ + -coverpkg=./pkg/gofr -coverprofile=submodules.cov ./pkg/gofr/... + exit_code=$? + if [ $exit_code -eq 2 ]; then + echo "::error::Panic detected in gofr sub-packages tests" + exit 2 + elif [ $exit_code -ne 0 ]; then + echo "::error::Gofr sub-packages tests failed" + exit $exit_code + fi + # Combine coverage profiles + echo "mode: atomic" > profile.cov + grep -h -v "mode:" gofr_only.cov submodules.cov | grep -v '/mock_' >> profile.cov + # Show coverage summary # Run tests for the examples directory with coverage go test ./examples/... -v -short -covermode=atomic -coverprofile packageWithpbgo.cov -coverpkg=./examples/... # Filter out auto-generated files by protobuf and gofr framework from coverage report grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov # Display coverage statistics go tool cover -func profile.cov - - + # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} @@ -120,7 +133,7 @@ jobs: name: Example-Test-Report path: profile.cov - # Job for testing the pkg directorypk + # Job for testing the pkg directory PKG-Unit-Testing: name: PKG Unit Testing (v${{ matrix.go-version }})🛠 runs-on: ubuntu-latest @@ -192,6 +205,7 @@ jobs: run: | echo "mode: atomic" > merged_profile.cov grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov + # Calculate and output the total code coverage percentage - name: Parse code-coverage value working-directory: artifacts @@ -200,6 +214,7 @@ jobs: codeCoverage=${codeCoverage%?} echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV echo "✅ Total Code Coverage: $codeCoverage%" + # - name: Check if code-coverage is greater than threshold # run: | # codeCoverage=${{ env.CODE_COVERAGE }} @@ -234,6 +249,7 @@ jobs: # Find all directories containing a go.mod file within 'pkg' SUBMODULES=$(find pkg -name "go.mod" -exec dirname {} \; | jq -R -s -c 'split("\n") | map(select(length > 0))') echo "submodules=$SUBMODULES" >> $GITHUB_OUTPUT + # Test all submodules in parallel with retry logic - name: Test Submodules with Retry and Parallelism id: test_submodules @@ -270,6 +286,7 @@ jobs: cd - ' + # Upload submodule coverage reports as an artifact - name: Upload Coverage Reports uses: actions/upload-artifact@v5 @@ -309,6 +326,8 @@ jobs: run: | echo "mode: atomic" > merged_profile.cov grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov + ' + # Generate and print total coverage percentage echo "Total Coverage:" go tool cover -func=merged_profile.cov | tail -n 1 @@ -339,13 +358,16 @@ jobs: - name: Install golangci-lint run: | go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0 + - name: Get dependencies run: | go mod tidy + # Run linter on the root module - name: Lint Root Module run: | golangci-lint run --output.text.print-issued-lines --output.text.colors=true --show-stats=false --timeout=5m + # Run linter on each submodule - name: Lint Submodules run: | @@ -364,6 +386,7 @@ jobs: echo "Linting failed for $total_errors submodule(s)." exit 1 # Fail the job if there are linting errors in submodules fi + # Job for checking filename conventions linting_party: name: Linting Party🥳 From 4d2439af7c3da288598bdc11a4b1e99909df2615 Mon Sep 17 00:00:00 2001 From: HarK Date: Wed, 29 Oct 2025 23:06:57 +0530 Subject: [PATCH 23/32] Refactor Go CI workflow to simplify test execution Removed old test execution and coverage profile handling for sub-packages in the Go CI workflow. --- .github/workflows/go.yml | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 14d016537c..3b7808af57 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -103,21 +103,8 @@ jobs: continue_on_error: false retry_on: error command: | - # Run tests for sub-packages - go test -v -covermode=atomic \ - -coverpkg=./pkg/gofr -coverprofile=submodules.cov ./pkg/gofr/... - exit_code=$? - if [ $exit_code -eq 2 ]; then - echo "::error::Panic detected in gofr sub-packages tests" - exit 2 - elif [ $exit_code -ne 0 ]; then - echo "::error::Gofr sub-packages tests failed" - exit $exit_code - fi - # Combine coverage profiles - echo "mode: atomic" > profile.cov - grep -h -v "mode:" gofr_only.cov submodules.cov | grep -v '/mock_' >> profile.cov - # Show coverage summary + set -e + export APP_ENV=test # Run tests for the examples directory with coverage go test ./examples/... -v -short -covermode=atomic -coverprofile packageWithpbgo.cov -coverpkg=./examples/... # Filter out auto-generated files by protobuf and gofr framework from coverage report @@ -404,4 +391,4 @@ jobs: - name: Check for file names errors uses: ls-lint/action@v2.3.1 with: - config: .ls-lint.yml \ No newline at end of file + config: .ls-lint.yml From 6a3d48e65223659d226b3e203bf5a36eabdc5afc Mon Sep 17 00:00:00 2001 From: Harshit Kandpal Date: Wed, 29 Oct 2025 23:49:24 +0530 Subject: [PATCH 24/32] chnges --- .github/workflows/go.yml | 53 +++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 14d016537c..b3bf6046c5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -89,7 +89,6 @@ jobs: - name: Get dependencies run: | go mod download - - name: Start Zipkin run: docker run -d -p 2005:9411 openzipkin/zipkin:latest @@ -103,21 +102,8 @@ jobs: continue_on_error: false retry_on: error command: | - # Run tests for sub-packages - go test -v -covermode=atomic \ - -coverpkg=./pkg/gofr -coverprofile=submodules.cov ./pkg/gofr/... - exit_code=$? - if [ $exit_code -eq 2 ]; then - echo "::error::Panic detected in gofr sub-packages tests" - exit 2 - elif [ $exit_code -ne 0 ]; then - echo "::error::Gofr sub-packages tests failed" - exit $exit_code - fi - # Combine coverage profiles - echo "mode: atomic" > profile.cov - grep -h -v "mode:" gofr_only.cov submodules.cov | grep -v '/mock_' >> profile.cov - # Show coverage summary + set -e + export APP_ENV=test # Run tests for the examples directory with coverage go test ./examples/... -v -short -covermode=atomic -coverprofile packageWithpbgo.cov -coverpkg=./examples/... # Filter out auto-generated files by protobuf and gofr framework from coverage report @@ -133,7 +119,7 @@ jobs: name: Example-Test-Report path: profile.cov - # Job for testing the pkg directory + # Job for testing the pkg directorypk PKG-Unit-Testing: name: PKG Unit Testing (v${{ matrix.go-version }})🛠 runs-on: ubuntu-latest @@ -169,12 +155,33 @@ jobs: command: | set -e export APP_ENV=test - # Run tests for the examples directory with coverage - go test ./examples/... -v -short -covermode=atomic -coverprofile packageWithpbgo.cov -coverpkg=./examples/... - # Filter out auto-generated files by protobuf and gofr framework from coverage report - grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov - # Display coverage statistics - go tool cover -func profile.cov + # Run tests for root gofr package + go test -v -short -covermode=atomic \ + -coverpkg=./pkg/gofr -coverprofile=gofr_only.cov ./pkg/gofr + exit_code=$? + if [ $exit_code -eq 2 ]; then + echo "::error::Panic detected in root gofr package tests" + exit 2 + elif [ $exit_code -ne 0 ]; then + echo "::error::Root gofr package tests failed" + exit $exit_code + fi + # Run tests for sub-packages + go test -v -covermode=atomic \ + -coverpkg=./pkg/gofr -coverprofile=submodules.cov ./pkg/gofr/... + exit_code=$? + if [ $exit_code -eq 2 ]; then + echo "::error::Panic detected in gofr sub-packages tests" + exit 2 + elif [ $exit_code -ne 0 ]; then + echo "::error::Gofr sub-packages tests failed" + exit $exit_code + fi + # Combine coverage profiles + echo "mode: atomic" > profile.cov + grep -h -v "mode:" gofr_only.cov submodules.cov | grep -v '/mock_' >> profile.cov + # Show coverage summary + # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} From 84cf83b2c749748a6cab4f5755ce3c3a52dad707 Mon Sep 17 00:00:00 2001 From: HarK Date: Thu, 30 Oct 2025 18:27:10 +0530 Subject: [PATCH 25/32] Update go.yml --- .github/workflows/go.yml | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 6322dbfa27..0a2070d56f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -9,7 +9,6 @@ on: push: branches: - main - - test3 - development paths-ignore: - 'docs/**' # Ignore changes to docs folder @@ -42,14 +41,14 @@ jobs: kafka: image: bitnamilegacy/kafka:3.4.1 ports: - - "1092:9092" + - "9092:9092" env: KAFKA_ENABLE_KRAFT: yes KAFKA_CFG_PROCESS_ROLES: broker,controller KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER KAFKA_CFG_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093 KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT - KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:1092 + KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:9092 KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: true KAFKA_BROKER_ID: 1 KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@127.0.0.1:9093 @@ -60,14 +59,14 @@ jobs: redis: image: redis:7.0.5 ports: - - "2001:6379" + - "2002:6379" options: "--entrypoint redis-server" # MySQL service mysql: image: mysql:8.2.0 ports: - - "2009:3306" + - "2001:3306" env: MYSQL_ROOT_PASSWORD: "password" MYSQL_DATABASE: "test" @@ -96,21 +95,24 @@ jobs: - name: Test with Retry Logic id: test uses: nick-fields/retry@v3 + continue-on-error: false with: timeout_minutes: 5 # Maximum time for the tests to run - max_attempts: 2 # Retry up to 2 times if tests fail - continue_on_error: false - retry_on: error + max_attempts: 2 # Retry up to 2 times if tests fail command: | set -e export APP_ENV=test # Run tests for the examples directory with coverage go test ./examples/... -v -short -covermode=atomic -coverprofile packageWithpbgo.cov -coverpkg=./examples/... + # Treat exit code 0 as success; exit code 1 may be harmless if output exists + if [ "${exit_code:-0}" -ne 0 ]; then + echo "⚠️ go test exited with $exit_code" + fi # Filter out auto-generated files by protobuf and gofr framework from coverage report + grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov # Display coverage statistics go tool cover -func profile.cov - # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} @@ -119,7 +121,7 @@ jobs: name: Example-Test-Report path: profile.cov - # Job for testing the pkg directorypk + # Job for testing the pkg directory PKG-Unit-Testing: name: PKG Unit Testing (v${{ matrix.go-version }})🛠 runs-on: ubuntu-latest @@ -150,7 +152,7 @@ jobs: with: timeout_minutes: 5 max_attempts: 2 - continue_on_error: false + continue-on-error: false retry_on: error command: | set -e @@ -181,7 +183,7 @@ jobs: echo "mode: atomic" > profile.cov grep -h -v "mode:" gofr_only.cov submodules.cov | grep -v '/mock_' >> profile.cov # Show coverage summary - + go tool cover -func profile.cov # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} @@ -212,7 +214,6 @@ jobs: run: | echo "mode: atomic" > merged_profile.cov grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov - # Calculate and output the total code coverage percentage - name: Parse code-coverage value working-directory: artifacts @@ -221,7 +222,6 @@ jobs: codeCoverage=${codeCoverage%?} echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV echo "✅ Total Code Coverage: $codeCoverage%" - # - name: Check if code-coverage is greater than threshold # run: | # codeCoverage=${{ env.CODE_COVERAGE }} @@ -256,7 +256,6 @@ jobs: # Find all directories containing a go.mod file within 'pkg' SUBMODULES=$(find pkg -name "go.mod" -exec dirname {} \; | jq -R -s -c 'split("\n") | map(select(length > 0))') echo "submodules=$SUBMODULES" >> $GITHUB_OUTPUT - # Test all submodules in parallel with retry logic - name: Test Submodules with Retry and Parallelism id: test_submodules @@ -293,7 +292,6 @@ jobs: cd - ' - # Upload submodule coverage reports as an artifact - name: Upload Coverage Reports uses: actions/upload-artifact@v5 @@ -333,8 +331,6 @@ jobs: run: | echo "mode: atomic" > merged_profile.cov grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov - ' - # Generate and print total coverage percentage echo "Total Coverage:" go tool cover -func=merged_profile.cov | tail -n 1 @@ -365,16 +361,13 @@ jobs: - name: Install golangci-lint run: | go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0 - - name: Get dependencies run: | go mod tidy - # Run linter on the root module - name: Lint Root Module run: | golangci-lint run --output.text.print-issued-lines --output.text.colors=true --show-stats=false --timeout=5m - # Run linter on each submodule - name: Lint Submodules run: | @@ -393,7 +386,6 @@ jobs: echo "Linting failed for $total_errors submodule(s)." exit 1 # Fail the job if there are linting errors in submodules fi - # Job for checking filename conventions linting_party: name: Linting Party🥳 From de4cf381939a9dd0287dcb4448c17ace6a81bf54 Mon Sep 17 00:00:00 2001 From: HarK Date: Thu, 30 Oct 2025 18:28:40 +0530 Subject: [PATCH 26/32] Update go.yml --- .github/workflows/go.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0a2070d56f..b746e69003 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -88,6 +88,7 @@ jobs: - name: Get dependencies run: | go mod download + - name: Start Zipkin run: docker run -d -p 2005:9411 openzipkin/zipkin:latest @@ -113,6 +114,7 @@ jobs: grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov # Display coverage statistics go tool cover -func profile.cov + # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} @@ -145,6 +147,7 @@ jobs: - name: Get dependencies run: | go mod download + # Run pkg tests with automatic retry logic - name: Test with Retry Logic id: test @@ -184,6 +187,7 @@ jobs: grep -h -v "mode:" gofr_only.cov submodules.cov | grep -v '/mock_' >> profile.cov # Show coverage summary go tool cover -func profile.cov + # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} From de7b5fcb5c965e9aa9e86762dbdaa68fdce9df1f Mon Sep 17 00:00:00 2001 From: HarK Date: Thu, 30 Oct 2025 18:33:38 +0530 Subject: [PATCH 27/32] Update go.yml --- .github/workflows/go.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b746e69003..15890a240b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -88,7 +88,7 @@ jobs: - name: Get dependencies run: | go mod download - + - name: Start Zipkin run: docker run -d -p 2005:9411 openzipkin/zipkin:latest @@ -147,7 +147,7 @@ jobs: - name: Get dependencies run: | go mod download - + # Run pkg tests with automatic retry logic - name: Test with Retry Logic id: test @@ -160,6 +160,7 @@ jobs: command: | set -e export APP_ENV=test + # Run tests for root gofr package go test -v -short -covermode=atomic \ -coverpkg=./pkg/gofr -coverprofile=gofr_only.cov ./pkg/gofr @@ -171,6 +172,7 @@ jobs: echo "::error::Root gofr package tests failed" exit $exit_code fi + # Run tests for sub-packages go test -v -covermode=atomic \ -coverpkg=./pkg/gofr -coverprofile=submodules.cov ./pkg/gofr/... @@ -187,7 +189,7 @@ jobs: grep -h -v "mode:" gofr_only.cov submodules.cov | grep -v '/mock_' >> profile.cov # Show coverage summary go tool cover -func profile.cov - + # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage if: ${{ matrix.go-version == '1.24'}} @@ -226,6 +228,7 @@ jobs: codeCoverage=${codeCoverage%?} echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV echo "✅ Total Code Coverage: $codeCoverage%" + # - name: Check if code-coverage is greater than threshold # run: | # codeCoverage=${{ env.CODE_COVERAGE }} @@ -260,6 +263,7 @@ jobs: # Find all directories containing a go.mod file within 'pkg' SUBMODULES=$(find pkg -name "go.mod" -exec dirname {} \; | jq -R -s -c 'split("\n") | map(select(length > 0))') echo "submodules=$SUBMODULES" >> $GITHUB_OUTPUT + # Test all submodules in parallel with retry logic - name: Test Submodules with Retry and Parallelism id: test_submodules @@ -290,7 +294,7 @@ jobs: # Run tests with a focus on failed tests first go test ./... -v -short -coverprofile=${module_name}.cov -coverpkg=./... - + # Copy coverage file to the coverage_reports directory cp ${module_name}.cov ../../../coverage_reports/ @@ -368,6 +372,7 @@ jobs: - name: Get dependencies run: | go mod tidy + # Run linter on the root module - name: Lint Root Module run: | @@ -390,6 +395,7 @@ jobs: echo "Linting failed for $total_errors submodule(s)." exit 1 # Fail the job if there are linting errors in submodules fi + # Job for checking filename conventions linting_party: name: Linting Party🥳 From 383fbd5794aecc2e2a4888272a07111d52f405c4 Mon Sep 17 00:00:00 2001 From: coolwednesday Date: Wed, 3 Dec 2025 12:13:25 +0530 Subject: [PATCH 28/32] fixed silent exits --- .github/workflows/go.yml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 7959285368..2fd05d718b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -187,10 +187,22 @@ jobs: # Combine coverage profiles echo "mode: atomic" > profile.cov - grep -h -v "mode:" gofr_only.cov submodules.cov | grep -v '/mock_' >> profile.cov + # Use || true to prevent grep from failing if no matches found + # Check if files exist before grepping + if [ -f gofr_only.cov ] && [ -f submodules.cov ]; then + grep -h -v "mode:" gofr_only.cov submodules.cov 2>/dev/null | grep -v '/mock_' >> profile.cov || true + elif [ -f gofr_only.cov ]; then + grep -v "mode:" gofr_only.cov 2>/dev/null | grep -v '/mock_' >> profile.cov || true + elif [ -f submodules.cov ]; then + grep -v "mode:" submodules.cov 2>/dev/null | grep -v '/mock_' >> profile.cov || true + fi - # Show coverage summary - go tool cover -func profile.cov + # Show coverage summary (only if profile has content) + if [ -s profile.cov ]; then + go tool cover -func profile.cov + else + echo "⚠️ Warning: No coverage data found" + fi # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage @@ -445,6 +457,10 @@ jobs: echo "has_modules=true" >> $GITHUB_OUTPUT else echo "✅ No submodule changes detected" + echo "ℹ️ This means either:" + echo " 1. No files changed in pkg/ submodules" + echo " 2. Changed files are in root pkg/gofr (not submodules)" + echo " 3. Changed files don't have go.mod in their directory" echo "modules=[]" >> $GITHUB_OUTPUT echo "has_modules=false" >> $GITHUB_OUTPUT fi From 9e3e41eb5a8e090767caca07e1d5b70427f93316 Mon Sep 17 00:00:00 2001 From: coolwednesday Date: Wed, 3 Dec 2025 12:29:25 +0530 Subject: [PATCH 29/32] added nil checks to prevent panic --- pkg/gofr/datasource/pubsub/kafka/conn.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/gofr/datasource/pubsub/kafka/conn.go b/pkg/gofr/datasource/pubsub/kafka/conn.go index 0708a720fa..cac30c7087 100644 --- a/pkg/gofr/datasource/pubsub/kafka/conn.go +++ b/pkg/gofr/datasource/pubsub/kafka/conn.go @@ -60,14 +60,23 @@ func (k *kafkaClient) getNewReader(topic string) Reader { } func (k *kafkaClient) DeleteTopic(_ context.Context, name string) error { + if k.conn == nil { + return errClientNotConnected + } return k.conn.DeleteTopics(name) } func (k *kafkaClient) Controller() (broker kafka.Broker, err error) { + if k.conn == nil { + return kafka.Broker{}, errClientNotConnected + } return k.conn.Controller() } func (k *kafkaClient) CreateTopic(_ context.Context, name string) error { + if k.conn == nil { + return errClientNotConnected + } topics := kafka.TopicConfig{Topic: name, NumPartitions: 1, ReplicationFactor: 1} return k.conn.CreateTopics(topics) From c2bfd51ed286309aec1c5c01ca4df3251278e9d1 Mon Sep 17 00:00:00 2001 From: coolwednesday Date: Wed, 3 Dec 2025 12:34:41 +0530 Subject: [PATCH 30/32] fixing silent checks for examples --- .github/workflows/go.yml | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 2fd05d718b..6aa3ec808c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -105,15 +105,30 @@ jobs: export APP_ENV=test # Run tests for the examples directory with coverage go test ./examples/... -v -short -covermode=atomic -coverprofile packageWithpbgo.cov -coverpkg=./examples/... - # Treat exit code 0 as success; exit code 1 may be harmless if output exists - if [ "${exit_code:-0}" -ne 0 ]; then - echo "⚠️ go test exited with $exit_code" + exit_code=$? + if [ $exit_code -eq 2 ]; then + echo "::error::Panic detected in examples tests" + exit 2 + elif [ $exit_code -ne 0 ]; then + echo "::error::Examples tests failed with exit code $exit_code" + exit $exit_code + fi + + # Filter out auto-generated files by protobuf and gofr framework from coverage report + # Use || true to prevent grep from failing if no matches found + if [ -f packageWithpbgo.cov ]; then + grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov || true + else + echo "⚠️ Warning: packageWithpbgo.cov not found, creating empty profile" + echo "mode: atomic" > profile.cov + fi + + # Display coverage statistics (only if profile has content) + if [ -s profile.cov ]; then + go tool cover -func profile.cov + else + echo "⚠️ Warning: No coverage data found in profile.cov" fi - # Filter out auto-generated files by protobuf and gofr framework from coverage report - - grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov - # Display coverage statistics - go tool cover -func profile.cov # Upload coverage report for the 1.24 Go version only - name: Upload Test Coverage From 3f1b64cd6b16614bf9563f333e4a02d86d6ccac0 Mon Sep 17 00:00:00 2001 From: coolwednesday Date: Wed, 3 Dec 2025 12:41:38 +0530 Subject: [PATCH 31/32] fixing silent checks for examples --- .github/workflows/go.yml | 108 ++++++++++++++++++++++++++++----------- 1 file changed, 78 insertions(+), 30 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 6aa3ec808c..b43369485d 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -90,7 +90,8 @@ jobs: go mod download - name: Start Zipkin - run: docker run -d -p 2005:9411 openzipkin/zipkin:latest + run: | + docker run -d -p 2005:9411 openzipkin/zipkin:latest || echo "⚠️ Warning: Failed to start Zipkin container (may already be running)" # Run tests with automatic retry on failures - name: Test with Retry Logic @@ -115,17 +116,20 @@ jobs: fi # Filter out auto-generated files by protobuf and gofr framework from coverage report + # Initialize profile with mode line first + echo "mode: atomic" > profile.cov + # Use || true to prevent grep from failing if no matches found - if [ -f packageWithpbgo.cov ]; then - grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov || true + if [ -f packageWithpbgo.cov ] && [ -s packageWithpbgo.cov ]; then + # Filter and append to profile (skip mode line) + grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov | grep -v "^mode:" >> profile.cov || true else - echo "⚠️ Warning: packageWithpbgo.cov not found, creating empty profile" - echo "mode: atomic" > profile.cov + echo "⚠️ Warning: packageWithpbgo.cov not found or empty" fi - # Display coverage statistics (only if profile has content) - if [ -s profile.cov ]; then - go tool cover -func profile.cov + # Display coverage statistics (only if profile has content beyond mode line) + if [ -s profile.cov ] && [ $(wc -l < profile.cov) -gt 1 ]; then + go tool cover -func profile.cov || echo "⚠️ Warning: Failed to generate coverage report" else echo "⚠️ Warning: No coverage data found in profile.cov" fi @@ -212,9 +216,9 @@ jobs: grep -v "mode:" submodules.cov 2>/dev/null | grep -v '/mock_' >> profile.cov || true fi - # Show coverage summary (only if profile has content) - if [ -s profile.cov ]; then - go tool cover -func profile.cov + # Show coverage summary (only if profile has content beyond mode line) + if [ -s profile.cov ] && [ $(wc -l < profile.cov) -gt 1 ]; then + go tool cover -func profile.cov || echo "⚠️ Warning: Failed to generate coverage report" else echo "⚠️ Warning: No coverage data found" fi @@ -248,16 +252,31 @@ jobs: working-directory: artifacts run: | echo "mode: atomic" > merged_profile.cov - grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov + # Check if files exist before grepping + if [ -f ./Example-Test-Report/profile.cov ] && [ -f ./PKG-Coverage-Report/profile.cov ]; then + grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov || true + elif [ -f ./Example-Test-Report/profile.cov ]; then + grep -v "mode:" ./Example-Test-Report/profile.cov >> merged_profile.cov || true + elif [ -f ./PKG-Coverage-Report/profile.cov ]; then + grep -v "mode:" ./PKG-Coverage-Report/profile.cov >> merged_profile.cov || true + else + echo "⚠️ Warning: No coverage files found to merge" + fi # Calculate and output the total code coverage percentage - name: Parse code-coverage value working-directory: artifacts run: | - codeCoverage=$(go tool cover -func=merged_profile.cov | grep total | awk '{print $3}') - codeCoverage=${codeCoverage%?} - echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV - echo "✅ Total Code Coverage: $codeCoverage%" + if [ -s merged_profile.cov ] && [ $(wc -l < merged_profile.cov) -gt 1 ]; then + codeCoverage=$(go tool cover -func=merged_profile.cov | grep total | awk '{print $3}' || echo "0.0%") + codeCoverage=${codeCoverage%?} + echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV + echo "✅ Total Code Coverage: $codeCoverage%" + else + echo "⚠️ Warning: No coverage data to parse" + echo "CODE_COVERAGE=0.0" >> $GITHUB_ENV + echo "✅ Total Code Coverage: 0.0%" + fi # - name: Check if code-coverage is greater than threshold # run: | @@ -291,7 +310,11 @@ jobs: id: detect_submodules run: | # Find all directories containing a go.mod file within 'pkg' - SUBMODULES=$(find pkg -name "go.mod" -exec dirname {} \; | jq -R -s -c 'split("\n") | map(select(length > 0))') + SUBMODULES=$(find pkg -name "go.mod" -exec dirname {} \; | jq -R -s -c 'split("\n") | map(select(length > 0))' || echo '[]') + if [ "$SUBMODULES" = "[]" ] || [ -z "$SUBMODULES" ]; then + echo "⚠️ Warning: No submodules detected" + SUBMODULES='[]' + fi echo "submodules=$SUBMODULES" >> $GITHUB_OUTPUT # Test all submodules in parallel with retry logic @@ -311,25 +334,37 @@ jobs: # Process each submodule in parallel with a maximum of 4 parallel jobs echo $SUBMODULES | jq -c '.[]' | xargs -I{} -P 4 bash -c ' + set -e module={} echo "Testing module: $module" - cd $module + + if [ ! -d "$module" ]; then + echo "⚠️ Warning: Module directory $module does not exist, skipping" + exit 0 + fi + + cd "$module" || { echo "⚠️ Error: Failed to cd to $module"; exit 1; } # Extract module name (replace / with _) - module_name=$(echo $module | tr "/" "_") + module_name=$(echo "$module" | tr "/" "_") # Download dependencies for the submodule - go mod download - go mod tidy + go mod download || { echo "⚠️ Warning: Failed to download dependencies for $module"; } + go mod tidy || { echo "⚠️ Warning: Failed to tidy dependencies for $module"; } # Run tests with a focus on failed tests first - go test ./... -v -short -coverprofile=${module_name}.cov -coverpkg=./... - - # Copy coverage file to the coverage_reports directory - cp ${module_name}.cov ../../../coverage_reports/ + if go test ./... -v -short -coverprofile=${module_name}.cov -coverpkg=./...; then + # Copy coverage file to the coverage_reports directory if it exists + if [ -f "${module_name}.cov" ]; then + cp "${module_name}.cov" ../../../coverage_reports/ || echo "⚠️ Warning: Failed to copy coverage file for $module" + fi + else + echo "⚠️ Warning: Tests failed for module $module" + exit 1 + fi - cd - - ' + cd - || true + ' || echo "⚠️ Warning: Some submodule tests failed" # Upload submodule coverage reports as an artifact - name: Upload Coverage Reports @@ -370,11 +405,24 @@ jobs: working-directory: artifacts run: | echo "mode: atomic" > merged_profile.cov - grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov + # Check if files exist before grepping + if [ -f ./Example-Test-Report/profile.cov ] && [ -f ./PKG-Coverage-Report/profile.cov ]; then + grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov || true + elif [ -f ./Example-Test-Report/profile.cov ]; then + grep -v "mode:" ./Example-Test-Report/profile.cov >> merged_profile.cov || true + elif [ -f ./PKG-Coverage-Report/profile.cov ]; then + grep -v "mode:" ./PKG-Coverage-Report/profile.cov >> merged_profile.cov || true + else + echo "⚠️ Warning: No coverage files found to merge" + fi # Generate and print total coverage percentage - echo "Total Coverage:" - go tool cover -func=merged_profile.cov | tail -n 1 + if [ -s merged_profile.cov ] && [ $(wc -l < merged_profile.cov) -gt 1 ]; then + echo "Total Coverage:" + go tool cover -func=merged_profile.cov | tail -n 1 || echo "⚠️ Warning: Failed to generate coverage report" + else + echo "⚠️ Warning: No coverage data to display" + fi shell: bash # Upload merged coverage to CodeClimate for analysis From 82590eb132626cf76146f7b45455144672b5da7f Mon Sep 17 00:00:00 2001 From: coolwednesday Date: Wed, 3 Dec 2025 12:49:57 +0530 Subject: [PATCH 32/32] fixing wrong port intialisation --- .github/workflows/go.yml | 59 ++++++++++++++++++-------- examples/using-subscriber/main_test.go | 3 ++ 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b43369485d..f8d91d9f5a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -332,39 +332,64 @@ jobs: # Get the list of submodules SUBMODULES='${{ steps.detect_submodules.outputs.submodules }}' + # Check if we have any submodules to test + if [ "$SUBMODULES" = "[]" ] || [ -z "$SUBMODULES" ]; then + echo "ℹ️ No submodules to test" + exit 0 + fi + # Process each submodule in parallel with a maximum of 4 parallel jobs - echo $SUBMODULES | jq -c '.[]' | xargs -I{} -P 4 bash -c ' - set -e + # Use a temporary file to track failures (accessible from subshells) + FAILED_MODULES_FILE=$(mktemp) + echo $SUBMODULES | jq -c '.[]' | xargs -I{} -P 4 bash -c " module={} - echo "Testing module: $module" + echo \"Testing module: \$module\" - if [ ! -d "$module" ]; then - echo "⚠️ Warning: Module directory $module does not exist, skipping" + if [ ! -d \"\$module\" ]; then + echo \"⚠️ Warning: Module directory \$module does not exist, skipping\" exit 0 fi - cd "$module" || { echo "⚠️ Error: Failed to cd to $module"; exit 1; } + if ! cd \"\$module\" 2>/dev/null; then + echo \"⚠️ Error: Failed to cd to \$module\" + echo \"\$module\" >> \"$FAILED_MODULES_FILE\" + exit 0 + fi # Extract module name (replace / with _) - module_name=$(echo "$module" | tr "/" "_") + module_name=\$(echo \"\$module\" | tr \"/\" \"_\") - # Download dependencies for the submodule - go mod download || { echo "⚠️ Warning: Failed to download dependencies for $module"; } - go mod tidy || { echo "⚠️ Warning: Failed to tidy dependencies for $module"; } + # Download dependencies for the submodule (non-fatal) + go mod download || echo \"⚠️ Warning: Failed to download dependencies for \$module\" + go mod tidy || echo \"⚠️ Warning: Failed to tidy dependencies for \$module\" - # Run tests with a focus on failed tests first - if go test ./... -v -short -coverprofile=${module_name}.cov -coverpkg=./...; then + # Run tests - capture exit code (don't use set -e) + if go test ./... -v -short -coverprofile=\${module_name}.cov -coverpkg=./...; then # Copy coverage file to the coverage_reports directory if it exists - if [ -f "${module_name}.cov" ]; then - cp "${module_name}.cov" ../../../coverage_reports/ || echo "⚠️ Warning: Failed to copy coverage file for $module" + if [ -f \"\${module_name}.cov\" ]; then + cp \"\${module_name}.cov\" ../../../coverage_reports/ || echo \"⚠️ Warning: Failed to copy coverage file for \$module\" fi + echo \"✅ Tests passed for module \$module\" else - echo "⚠️ Warning: Tests failed for module $module" - exit 1 + echo \"❌ Tests failed for module \$module\" + echo \"\$module\" >> \"$FAILED_MODULES_FILE\" fi cd - || true - ' || echo "⚠️ Warning: Some submodule tests failed" + " || true + + # Check if any modules failed + if [ -s "$FAILED_MODULES_FILE" ]; then + echo "::error::The following submodules had test failures:" + while IFS= read -r module; do + echo "::error:: - $module" + done < "$FAILED_MODULES_FILE" + rm -f "$FAILED_MODULES_FILE" + exit 1 + else + echo "✅ All submodule tests passed" + rm -f "$FAILED_MODULES_FILE" + fi # Upload submodule coverage reports as an artifact - name: Upload Coverage Reports diff --git a/examples/using-subscriber/main_test.go b/examples/using-subscriber/main_test.go index 7dd7de1584..f8d3050365 100644 --- a/examples/using-subscriber/main_test.go +++ b/examples/using-subscriber/main_test.go @@ -21,6 +21,9 @@ func TestMain(m *testing.M) { } func TestMainInitialization(t *testing.T) { + // Use NewServerConfigs to get a free metrics port and avoid port conflicts + _ = testutil.NewServerConfigs(t) + log := testutil.StdoutOutputForFunc(func() { go main()