Update beckn_ci_test.yml
new approach
This commit is contained in:
53
.github/workflows/beckn_ci_test.yml
vendored
53
.github/workflows/beckn_ci_test.yml
vendored
@@ -6,47 +6,38 @@ on:
|
|||||||
- beckn-onix-v1.0-develop
|
- beckn-onix-v1.0-develop
|
||||||
|
|
||||||
env:
|
env:
|
||||||
APP_DIRECTORY: "shared/plugin" # Root directory to start searching from
|
APP_DIRECTORY: "shared/plugin"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint_and_test:
|
lint_and_test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name == 'pull_request'
|
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:
|
steps:
|
||||||
# 1. Checkout the code from the test branch (triggered by PR)
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# 2. Set up Go environment
|
|
||||||
- name: Set up Go 1.24.0
|
- name: Set up Go 1.24.0
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: '1.24.0'
|
go-version: '1.24.0'
|
||||||
|
|
||||||
# 3. Install golangci-lint
|
|
||||||
- name: Install golangci-lint
|
- name: Install golangci-lint
|
||||||
run: |
|
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
|
||||||
|
|
||||||
# 4. Run golangci-lint on the entire repo, starting from the root directory
|
|
||||||
- name: Run golangci-lint
|
- name: Run golangci-lint
|
||||||
run: |
|
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
|
|
||||||
- name: Run unit tests with coverage
|
- name: Run unit tests with coverage
|
||||||
run: |
|
run: |
|
||||||
# Create a directory to store coverage files
|
|
||||||
mkdir -p $GITHUB_WORKSPACE/coverage_files
|
mkdir -p $GITHUB_WORKSPACE/coverage_files
|
||||||
# Find all *_test.go files
|
|
||||||
test_files=$(find ./ -type f -name '*_test.go')
|
test_files=$(find ./ -type f -name '*_test.go')
|
||||||
# Check if there are any test files
|
|
||||||
if [ -z "$test_files" ]; then
|
if [ -z "$test_files" ]; then
|
||||||
echo "No test cases found in the repository. Skipping test execution."
|
echo "No test cases found. Skipping."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
# Run tests and store coverage for each test directory
|
|
||||||
for test_file in $test_files; do
|
for test_file in $test_files; do
|
||||||
test_dir=$(dirname "$test_file")
|
test_dir=$(dirname "$test_file")
|
||||||
go_file="${test_file/_test.go/.go}"
|
go_file="${test_file/_test.go/.go}"
|
||||||
@@ -54,11 +45,11 @@ jobs:
|
|||||||
go test -v -coverprofile=$GITHUB_WORKSPACE/coverage_files/coverage_$(basename "$go_file" .go).out $test_dir || echo "Tests failed, but continuing."
|
go test -v -coverprofile=$GITHUB_WORKSPACE/coverage_files/coverage_$(basename "$go_file" .go).out $test_dir || echo "Tests failed, but continuing."
|
||||||
done
|
done
|
||||||
|
|
||||||
# 6. Check coverage for each generated coverage file
|
|
||||||
- name: Check coverage for each test file
|
- name: Check coverage for each test file
|
||||||
|
id: coverage_check
|
||||||
run: |
|
run: |
|
||||||
|
echo "coverage_ok=true" >> $GITHUB_OUTPUT
|
||||||
coverage_files=$(find $GITHUB_WORKSPACE/coverage_files -name "coverage_*.out")
|
coverage_files=$(find $GITHUB_WORKSPACE/coverage_files -name "coverage_*.out")
|
||||||
# If no coverage files were generated, exit without failure
|
|
||||||
if [ -z "$coverage_files" ]; then
|
if [ -z "$coverage_files" ]; then
|
||||||
echo "No coverage files found. Skipping coverage check."
|
echo "No coverage files found. Skipping coverage check."
|
||||||
exit 0
|
exit 0
|
||||||
@@ -66,9 +57,29 @@ jobs:
|
|||||||
for coverage_file in $coverage_files; do
|
for coverage_file in $coverage_files; do
|
||||||
echo "Checking coverage for $coverage_file"
|
echo "Checking coverage for $coverage_file"
|
||||||
coverage=$(go tool cover -func=$coverage_file | grep total | awk '{print $3}' | sed 's/%//')
|
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
|
if (( $(echo "$coverage < 90" | bc -l) )); then
|
||||||
echo "Coverage for $coverage_file is below 90%. Failing the job."
|
echo "coverage_ok=false" >> $GITHUB_OUTPUT
|
||||||
exit 1
|
break
|
||||||
fi
|
fi
|
||||||
done
|
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."
|
||||||
|
|||||||
Reference in New Issue
Block a user