En/error fields #6103
Workflow file for this run
This file contains 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: Workflow-Pipeline | |
# Define when this workflow should run | |
on: | |
# Run on push events to main or development branches | |
push: | |
branches: | |
- main | |
- development | |
paths-ignore: | |
- 'docs/**' # Ignore changes to docs folder | |
# Run on pull requests to main or development branches | |
pull_request: | |
branches: | |
- main | |
- development | |
paths-ignore: | |
- 'docs/**' # Ignore changes to docs folder | |
# Define the jobs that this workflow will run | |
jobs: | |
# Job for testing the examples directory | |
Example-Unit-Testing: | |
name: Example Unit Testing (v${{ matrix.go-version }})🛠 | |
runs-on: ubuntu-latest | |
# Define a matrix strategy to test against multiple Go versions | |
strategy: | |
matrix: | |
go-version: ['1.24','1.23', '1.22'] | |
# Continue with other jobs if one version fails | |
fail-fast: false | |
# Define service containers that tests depend on | |
services: | |
# Kafka service | |
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 service | |
redis: | |
image: redis:7.0.5 | |
ports: | |
- "2002:6379" | |
options: "--entrypoint redis-server" | |
# MySQL service | |
mysql: | |
image: mysql:8.2.0 | |
ports: | |
- "2001:3306" | |
env: | |
MYSQL_ROOT_PASSWORD: "password" | |
MYSQL_DATABASE: "test" | |
# Steps to execute for this job | |
steps: | |
- name: Checkout code into go module directory | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Full git history for accurate testing | |
# Set up the Go environment with the specified version | |
- 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 | |
# 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 gofr.dev/examples/... -v -short -coverprofile packageWithpbgo.cov -coverpkg=gofr.dev/examples/... | |
# Filter out auto-generated files by protobuf and gofr framework from coverage report | |
grep -vE '^gofr\.dev\/.*(\.pb\.go|hello\.proto|hello_grpc\.pb\.go|health_client\.go|hello_client\.go|hello_gofr\.go|health_gofr\.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'}} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Example-Test-Report | |
path: profile.cov | |
# Job for testing the pkg directory | |
PKG-Unit-Testing: | |
name: PKG Unit Testing (v${{ matrix.go-version }})🛠 | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
go-version: ['1.24','1.23', '1.22'] | |
fail-fast: false | |
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 | |
# Run pkg tests with automatic retry logic | |
- name: Test with Retry Logic | |
id: test | |
uses: nick-fields/retry@v3 | |
with: | |
timeout_minutes: 5 | |
max_attempts: 2 | |
command: | | |
export APP_ENV=test | |
# Run tests for the pkg directory with coverage | |
cd pkg | |
go test ./... -v -short -coverprofile package.cov -coverpkg=./... | |
# Filter out mock files from coverage report | |
grep -v '/mock_' package.cov > profile.cov | |
mv profile.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'}} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: PKG-Coverage-Report | |
path: profile.cov | |
# Job for analyzing and reporting code coverage | |
parse_coverage: | |
name: Code Coverage | |
runs-on: ubuntu-latest | |
# This job runs after both Example and PKG testing are complete | |
needs: [ Example-Unit-Testing,PKG-Unit-Testing ] | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v4 | |
# Download coverage reports from previous jobs | |
- name: Download Coverage Report | |
uses: actions/download-artifact@v4 | |
with: | |
path: artifacts | |
# Merge the coverage reports from Example and PKG tests | |
- name: Merge Coverage Files | |
working-directory: artifacts | |
run: | | |
awk '!/^mode: / && FNR==1{print "mode: set"} {print}' ./Example-Test-Report/profile.cov > merged_profile.cov | |
tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov | |
# 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 | |
# - name: Check if code-coverage is greater than threshold | |
# run: | | |
# codeCoverage=${{ env.CODE_COVERAGE }} | |
# codeCoverage=${codeCoverage%??} | |
# if [[ $codeCoverage -lt 92 ]]; then echo "code coverage cannot be less than 92%, currently its ${{ env.CODE_COVERAGE }}%" && exit 1; fi; | |
# Job for testing submodules inside the pkg directory | |
Submodule-Unit-Testing: | |
name: Submodule Unit Testing (v${{ matrix.go-version }})🛠 | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
go-version: ['1.24','1.23', '1.22'] | |
fail-fast: false | |
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 | |
# Find all submodules (directories with go.mod files) in the pkg directory | |
- name: Detect Submodules | |
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))') | |
echo "submodules=$SUBMODULES" >> $GITHUB_OUTPUT | |
# Test all submodules in parallel with retry logic | |
- name: Test Submodules with Retry and Parallelism | |
id: test_submodules | |
uses: nick-fields/retry@v3 | |
with: | |
timeout_minutes: 5 | |
max_attempts: 2 | |
command: | | |
export APP_ENV=test | |
# Create a directory for coverage reports | |
mkdir -p coverage_reports | |
# Get the list of submodules | |
SUBMODULES='${{ steps.detect_submodules.outputs.submodules }}' | |
# Process each submodule in parallel with a maximum of 4 parallel jobs | |
echo $SUBMODULES | jq -c '.[]' | xargs -I{} -P 4 bash -c ' | |
module={} | |
echo "Testing module: $module" | |
cd $module | |
# Extract module name (replace / with _) | |
module_name=$(echo $module | tr "/" "_") | |
# Download dependencies for the submodule | |
go mod download | |
go mod tidy | |
# 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/ | |
cd - | |
' | |
# Upload submodule coverage reports as an artifact | |
- name: Upload Coverage Reports | |
uses: actions/upload-artifact@v4 | |
with: | |
name: submodule-coverage-reports | |
path: coverage_reports/*.cov | |
# Job for uploading coverage to external services (CodeClimate) | |
upload_coverage: | |
name: Upload Coverage📊 | |
runs-on: ubuntu-latest | |
# This job only needs example and pkg test results, not submodules | |
needs: [Example-Unit-Testing, PKG-Unit-Testing] | |
# Only run this job on pushes to the development branch | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development'}} | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v4 | |
# Download coverage artifacts | |
- name: Download Coverage Report | |
uses: actions/download-artifact@v4 | |
with: | |
path: artifacts | |
# Merge coverage from example and pkg tests only | |
- name: Merge Coverage Files | |
working-directory: artifacts | |
run: | | |
echo "mode: set" > merged_profile.cov | |
tail -n +2 ./Example-Test-Report/profile.cov >> merged_profile.cov | |
tail -n +2 ./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 | |
shell: bash | |
# Upload merged coverage to CodeClimate for analysis | |
- name: Upload | |
uses: paambaati/[email protected] | |
env: | |
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | |
with: | |
coverageLocations: artifacts/merged_profile.cov:gocov | |
prefix: gofr.dev | |
# Job for code quality checks | |
code_quality: | |
name: Code Quality🎖️ | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v4 | |
- name: Set up Go environment | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '1.24' | |
cache: false | |
# Install the linting tool | |
- name: Install golangci-lint | |
run: | | |
go install github.com/golangci/golangci-lint/cmd/[email protected] | |
- name: Get dependencies | |
run: | | |
go mod tidy | |
# Run linter on the root module | |
- name: Lint Root Module | |
run: | | |
golangci-lint run --out-format=colored-line-number --timeout=5m | |
# Run linter on each submodule | |
- name: Lint Submodules | |
run: | | |
echo "Searching for submodules..." | |
total_errors=0 # Initialize error counter | |
for module in $(find pkg -name "go.mod" -exec dirname {} \;); do | |
echo "Linting submodule: $module" | |
# Change directory to the submodule and run golangci-lint | |
cd $module | |
go mod tidy | |
golangci-lint run --timeout 9m0s || total_errors=$((total_errors + 1)) | |
cd - # Return to the root directory | |
done | |
echo "Total submodule lint errors: $total_errors" | |
if [ $total_errors -gt 0 ]; then | |
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🥳 | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Set up Go environment | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.24 | |
# Check file naming conventions using ls-lint | |
- name: Check for file names errors | |
uses: ls-lint/[email protected] | |
with: | |
config: .ls-lint.yml |