Update beckn_ci.yml
testing for root directory and if test file not present
This commit is contained in:
73
.github/workflows/beckn_ci.yml
vendored
73
.github/workflows/beckn_ci.yml
vendored
@@ -3,12 +3,10 @@ name: CI/CD Pipeline
|
|||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- beckn-onix-v1.0-develop # Trigger when a PR is raised for merging into `beck-onix-v1.0-develop`
|
- beckn-onix-v1.0-develop
|
||||||
|
|
||||||
env:
|
env:
|
||||||
# AR_LOCATION: "${{ secrets.GCP_PROJECT_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_AR_REPO }}"
|
APP_DIRECTORY: "shared/plugin" # Root directory to start searching from
|
||||||
APP_DIRECTORY: "shared/plugin"
|
|
||||||
# REF_BRANCH: "feature/signing_plugin"
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint_and_test:
|
lint_and_test:
|
||||||
@@ -20,67 +18,39 @@ jobs:
|
|||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: ${{ env.REF_BRANCH }} # Make sure we're on the 'test' branch for checking out code
|
ref: ${{ env.REF_BRANCH }}
|
||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
|
|
||||||
# 2. Debugging: List files in the repository root after checkout
|
# 2. Set up Go environment
|
||||||
- name: List files in the root directory
|
|
||||||
run: |
|
|
||||||
echo "Current working directory is: $(pwd)"
|
|
||||||
echo "Listing files in the root directory:"
|
|
||||||
ls -al
|
|
||||||
|
|
||||||
# 3. 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'
|
||||||
|
|
||||||
# 4. Navigate to the app directory
|
# 3. Install golangci-lint
|
||||||
- name: Navigate to app directory
|
|
||||||
run: |
|
|
||||||
echo "Changing directory to ${{ env.APP_DIRECTORY }}"
|
|
||||||
cd ${{ env.APP_DIRECTORY }}
|
|
||||||
echo "Listing files in ${{ env.APP_DIRECTORY }} directory:"
|
|
||||||
ls -al # List files in the ${{ env.APP_DIRECTORY }} directory
|
|
||||||
|
|
||||||
# 5. Install golangci-lint
|
|
||||||
- name: Install golangci-lint
|
- name: Install golangci-lint
|
||||||
run: |
|
run: |
|
||||||
echo "Installing golangci-lint..."
|
|
||||||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||||
echo "golangci-lint installed to: $(go env GOPATH)/bin/"
|
|
||||||
ls -l $(go env GOPATH)/bin/ # Debugging: List the contents of the bin directory
|
|
||||||
|
|
||||||
# 6. Verify golangci-lint binary location
|
# 4. Run golangci-lint on the entire APP_DIRECTORY (including subdirectories)
|
||||||
- name: Verify golangci-lint binary
|
|
||||||
run: |
|
|
||||||
echo "Checking if golangci-lint is installed..."
|
|
||||||
ls $(go env GOPATH)/bin/ # Debugging: Check if golangci-lint is present
|
|
||||||
if [ ! -f $(go env GOPATH)/bin/golangci-lint ]; then
|
|
||||||
echo "golangci-lint was not found, exiting."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 7. Run Linter
|
|
||||||
- name: Run golangci-lint
|
- name: Run golangci-lint
|
||||||
run: |
|
run: |
|
||||||
echo "Running golangci-lint..."
|
golangci-lint run ${{ env.APP_DIRECTORY }}
|
||||||
cd ${{ env.APP_DIRECTORY }}
|
|
||||||
golangci-lint run
|
|
||||||
|
|
||||||
# 8. Run unit tests with coverage
|
# 5. Run unit tests with coverage recursively for all Go files
|
||||||
- name: Run unit tests with coverage
|
- name: Run unit tests with coverage
|
||||||
run: |
|
run: |
|
||||||
cd ${{ env.APP_DIRECTORY }}
|
# Run tests recursively for all Go files
|
||||||
echo "Running unit tests..."
|
go test -v -coverprofile=coverage.out ${{ env.APP_DIRECTORY }}/...
|
||||||
go test -v -coverprofile=coverage.out
|
|
||||||
|
# Generate coverage report
|
||||||
go tool cover -func=coverage.out | tee coverage.txt
|
go tool cover -func=coverage.out | tee coverage.txt
|
||||||
|
|
||||||
# 9. Check if coverage is >= 90%
|
# 6. Check if coverage is >= 90%, but only check coverage if tests exist
|
||||||
- name: Check coverage percentage
|
- name: Check coverage percentage
|
||||||
run: |
|
run: |
|
||||||
cd ${{ env.APP_DIRECTORY }}
|
# Check if coverage file exists
|
||||||
|
if [ -f coverage.out ]; then
|
||||||
# Extract total coverage percentage from the output
|
# Extract total coverage percentage from the output
|
||||||
coverage=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
|
coverage=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
|
||||||
|
|
||||||
@@ -93,16 +63,14 @@ jobs:
|
|||||||
else
|
else
|
||||||
echo "Coverage is 90% or above. Continuing the job."
|
echo "Coverage is 90% or above. Continuing the job."
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo "No coverage file found. Skipping coverage check."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 7. Build the Go code
|
||||||
# 10. Build the Go code
|
|
||||||
- name: Build Go code
|
- name: Build Go code
|
||||||
run: |
|
run: |
|
||||||
echo "Building the Go application..."
|
go build -o myapp ${{ env.APP_DIRECTORY }}/...
|
||||||
cd ${{ env.APP_DIRECTORY }}
|
|
||||||
go build -o myapp
|
|
||||||
|
|
||||||
# Verify if the build was successful
|
|
||||||
if [ ! -f myapp ]; then
|
if [ ! -f myapp ]; then
|
||||||
echo "Build failed: myapp executable was not created."
|
echo "Build failed: myapp executable was not created."
|
||||||
exit 1
|
exit 1
|
||||||
@@ -110,3 +78,4 @@ jobs:
|
|||||||
echo "Build succeeded: myapp executable created."
|
echo "Build succeeded: myapp executable created."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
4
|
||||||
|
|||||||
Reference in New Issue
Block a user