Update beckn_ci_test.yml

new approach
This commit is contained in:
BushraS-Protean
2025-04-07 14:18:51 +05:30
committed by GitHub
parent c49ae7bdea
commit 69116b3e41

View File

@@ -1,64 +1,55 @@
name: CI/CD Test Pipeline
on:
pull_request:
branches:
- beckn-onix-v1.0-develop
env:
APP_DIRECTORY: "shared/plugin" # Root directory to start searching from
APP_DIRECTORY: "shared/plugin"
jobs:
lint_and_test:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
timeout-minutes: 10 # Increased timeout due to additional steps
timeout-minutes: 10
outputs:
coverage_ok: ${{ steps.coverage_check.outputs.coverage_ok }}
steps:
# 1. Checkout the code from the test branch (triggered by PR)
- name: Checkout code
uses: actions/checkout@v4
# 2. Set up Go environment
- name: Set up Go 1.24.0
uses: actions/setup-go@v4
with:
go-version: '1.24.0'
# 3. Install golangci-lint
- name: Install golangci-lint
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# 4. Run golangci-lint on the entire repo, starting from the root directory
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- name: Run golangci-lint
run: |
golangci-lint run ./... # This will lint all Go files in the repo and subdirectories
# 5. Run unit tests with coverage in the entire repository
run: golangci-lint run ./...
- name: Run unit tests with coverage
run: |
# Create a directory to store coverage files
mkdir -p $GITHUB_WORKSPACE/coverage_files
# Find all *_test.go files
test_files=$(find ./ -type f -name '*_test.go')
# Check if there are any test files
if [ -z "$test_files" ]; then
echo "No test cases found in the repository. Skipping test execution."
echo "No test cases found. Skipping."
exit 0
fi
# Run tests and store coverage for each test directory
for test_file in $test_files; do
test_dir=$(dirname "$test_file")
go_file="${test_file/_test.go/.go}"
echo "Running tests in $test_dir for $go_file"
go test -v -coverprofile=$GITHUB_WORKSPACE/coverage_files/coverage_$(basename "$go_file" .go).out $test_dir || echo "Tests failed, but continuing."
done
# 6. Check coverage for each generated coverage file
- name: Check coverage for each test file
id: coverage_check
run: |
echo "coverage_ok=true" >> $GITHUB_OUTPUT
coverage_files=$(find $GITHUB_WORKSPACE/coverage_files -name "coverage_*.out")
# If no coverage files were generated, exit without failure
if [ -z "$coverage_files" ]; then
echo "No coverage files found. Skipping coverage check."
exit 0
@@ -66,9 +57,29 @@ jobs:
for coverage_file in $coverage_files; do
echo "Checking coverage for $coverage_file"
coverage=$(go tool cover -func=$coverage_file | grep total | awk '{print $3}' | sed 's/%//')
echo "Coverage for $coverage_file: $coverage%"
echo "Coverage: $coverage%"
if (( $(echo "$coverage < 90" | bc -l) )); then
echo "Coverage for $coverage_file is below 90%. Failing the job."
exit 1
echo "coverage_ok=false" >> $GITHUB_OUTPUT
break
fi
done
require_exception_approval:
needs: lint_and_test
if: needs.lint_and_test.outputs.coverage_ok == 'false'
runs-on: ubuntu-latest
environment:
name: coverage-exception
url: https://your-coverage-dashboard.com # Optional
steps:
- name: Manual approval required
run: echo "Coverage < 90%. Approval required to continue."
proceed_with_merge:
needs: [lint_and_test, require_exception_approval]
if: |
needs.lint_and_test.outputs.coverage_ok == 'true' || success()
runs-on: ubuntu-latest
steps:
- name: Proceed with merge
run: echo "Coverage requirement met or exception approved. Merge allowed."