Skip to content

Commit

Permalink
merge the test and count warning step
Browse files Browse the repository at this point in the history
  • Loading branch information
Umang01-hash committed Jan 13, 2025
1 parent 9e01054 commit 9ce10e5
Showing 1 changed file with 78 additions and 81 deletions.
159 changes: 78 additions & 81 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches:
- main
- development
- workflow_warning_step_refactor
paths-ignore:
- 'docs/**'
pull_request:
Expand All @@ -16,77 +17,77 @@ on:
- 'docs/**'

jobs:
Example-Unit-Testing:
name: Example Unit Testing (v${{ matrix.go-version }})🛠
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.23', '1.22']

services:
kafka:
image: bitnami/kafka:3.4
ports:
- "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:9092
KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: true
KAFKA_BROKER_ID: 1
KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: [email protected]:9093
ALLOW_PLAINTEXT_LISTENER: yes
KAFKA_CFG_NODE_ID: 1

redis:
image: redis:7.0.5
ports:
- "2002:6379"
options: "--entrypoint redis-server"

mysql:
image: mysql:8.2.0
ports:
- "2001:3306"
env:
MYSQL_ROOT_PASSWORD: "password"
MYSQL_DATABASE: "test"

steps:
- name: Checkout code into go module directory
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
id: Go

- name: Get dependencies
run: |
go mod download
- name: Start Zipkin
run: docker run -d -p 2005:9411 openzipkin/zipkin:latest

- name: Test
run: |
export APP_ENV=test
go test gofr.dev/examples/... -v -short -coverprofile packageWithpbgo.cov -coverpkg=gofr.dev/examples/...
grep -vE '^gofr\.dev\/.*\.pb\.go' packageWithpbgo.cov > profile.cov
go tool cover -func profile.cov
- name: Upload Test Coverage
if: ${{ matrix.go-version == '1.22'}}
uses: actions/upload-artifact@v4
with:
name: Example-Test-Report
path: profile.cov
# Example-Unit-Testing:
# name: Example Unit Testing (v${{ matrix.go-version }})🛠
# runs-on: ubuntu-latest
# strategy:
# matrix:
# go-version: ['1.23', '1.22']
#
# services:
# kafka:
# image: bitnami/kafka:3.4
# ports:
# - "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:9092
# KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: true
# KAFKA_BROKER_ID: 1
# KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: [email protected]:9093
# ALLOW_PLAINTEXT_LISTENER: yes
# KAFKA_CFG_NODE_ID: 1
#
# redis:
# image: redis:7.0.5
# ports:
# - "2002:6379"
# options: "--entrypoint redis-server"
#
# mysql:
# image: mysql:8.2.0
# ports:
# - "2001:3306"
# env:
# MYSQL_ROOT_PASSWORD: "password"
# MYSQL_DATABASE: "test"
#
# steps:
# - name: Checkout code into go module directory
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
#
# - name: Set up Go ${{ matrix.go-version }}
# uses: actions/setup-go@v5
# with:
# go-version: ${{ matrix.go-version }}
# id: Go
#
# - name: Get dependencies
# run: |
# go mod download
#
# - name: Start Zipkin
# run: docker run -d -p 2005:9411 openzipkin/zipkin:latest
#
# - name: Test
# run: |
# export APP_ENV=test
# go test gofr.dev/examples/... -v -short -coverprofile packageWithpbgo.cov -coverpkg=gofr.dev/examples/...
# grep -vE '^gofr\.dev\/.*\.pb\.go' packageWithpbgo.cov > profile.cov
# go tool cover -func profile.cov
#
# - name: Upload Test Coverage
# if: ${{ matrix.go-version == '1.22'}}
# uses: actions/upload-artifact@v4
# with:
# name: Example-Test-Report
# path: profile.cov

PKG-Unit-Testing:
name: PKG Unit Testing (v${{ matrix.go-version }})🛠
Expand All @@ -111,17 +112,13 @@ jobs:
run: |
go mod download
- name: Test
- name: Test and Count Warnings
id: test-and-count-warnings
run: |
export APP_ENV=test
go test gofr.dev/pkg/... -v -short -coverprofile package.cov -coverpkg=gofr.dev/pkg/...
warning_count=$(go test gofr.dev/pkg/... -v -short -coverprofile package.cov -coverpkg=gofr.dev/pkg/... | tee /dev/tty | grep -c "WARNING" || true)
grep -v '/mock_' package.cov > profile.cov
go tool cover -func profile.cov
- name: Count Warnings
id: count-warnings
run: |
warning_count=$(go test gofr.dev/pkg/... -v | grep -c "WARNING" || true)
echo "Warnings found: $warning_count"
echo "warning_count=$warning_count" >> $GITHUB_ENV
Expand All @@ -130,7 +127,7 @@ jobs:
if [ ${{ env.warning_count }} -gt 10 ]; then
echo "Too many warnings: ${{ env.warning_count }}"
exit 1
fi
fi
- name: Upload Test Coverage
if: ${{ matrix.go-version == '1.22'}}
Expand All @@ -142,7 +139,7 @@ jobs:
parse_coverage:
name: Code Coverage
runs-on: ubuntu-latest
needs: [ Example-Unit-Testing,PKG-Unit-Testing]
needs: [ PKG-Unit-Testing]
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
Expand Down Expand Up @@ -222,7 +219,7 @@ jobs:
upload_coverage:
name: Upload Coverage📊
runs-on: ubuntu-latest
needs: [Example-Unit-Testing,PKG-Unit-Testing]
needs: [PKG-Unit-Testing]
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development'}}
steps:
- name: Check out code into the Go module directory
Expand Down

0 comments on commit 9ce10e5

Please sign in to comment.