diff --git a/.github/workflows/beckn_ci.yml b/.github/workflows/beckn_ci.yml index 17db47f..64d4ff0 100644 --- a/.github/workflows/beckn_ci.yml +++ b/.github/workflows/beckn_ci.yml @@ -3,12 +3,10 @@ name: CI/CD Pipeline on: pull_request: 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: - # AR_LOCATION: "${{ secrets.GCP_PROJECT_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_AR_REPO }}" - APP_DIRECTORY: "shared/plugin" - # REF_BRANCH: "feature/signing_plugin" + APP_DIRECTORY: "shared/plugin" # Root directory to start searching from jobs: lint_and_test: @@ -20,89 +18,59 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - ref: ${{ env.REF_BRANCH }} # Make sure we're on the 'test' branch for checking out code + ref: ${{ env.REF_BRANCH }} fetch-depth: 1 - # 2. Debugging: List files in the repository root after checkout - - 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 + # 2. Set up Go environment - name: Set up Go 1.24.0 uses: actions/setup-go@v4 with: go-version: '1.24.0' - # 4. Navigate to the app directory - - 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 + # 3. Install golangci-lint - name: Install golangci-lint run: | - echo "Installing golangci-lint..." 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 - - 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 + # 4. Run golangci-lint on the entire APP_DIRECTORY (including subdirectories) - name: Run golangci-lint run: | - echo "Running golangci-lint..." - cd ${{ env.APP_DIRECTORY }} - golangci-lint run + golangci-lint run ${{ env.APP_DIRECTORY }} - # 8. Run unit tests with coverage + # 5. Run unit tests with coverage recursively for all Go files - name: Run unit tests with coverage run: | - cd ${{ env.APP_DIRECTORY }} - echo "Running unit tests..." - go test -v -coverprofile=coverage.out + # Run tests recursively for all Go files + go test -v -coverprofile=coverage.out ${{ env.APP_DIRECTORY }}/... + + # Generate coverage report 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 run: | - cd ${{ env.APP_DIRECTORY }} - # Extract total coverage percentage from the output - coverage=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//') + # Check if coverage file exists + if [ -f coverage.out ]; then + # Extract total coverage percentage from the output + coverage=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//') - echo "Total coverage: $coverage%" + echo "Total coverage: $coverage%" - # Check if coverage is greater than or equal to 90% - if (( $(echo "$coverage < 90" | bc -l) )); then - echo "Coverage is below 90%. Failing the job." - exit 1 + # Check if coverage is greater than or equal to 90% + if (( $(echo "$coverage < 90" | bc -l) )); then + echo "Coverage is below 90%. Failing the job." + exit 1 + else + echo "Coverage is 90% or above. Continuing the job." + fi else - echo "Coverage is 90% or above. Continuing the job." + echo "No coverage file found. Skipping coverage check." fi - - # 10. Build the Go code + # 7. Build the Go code - name: Build Go code run: | - echo "Building the Go application..." - cd ${{ env.APP_DIRECTORY }} - go build -o myapp - - # Verify if the build was successful + go build -o myapp ${{ env.APP_DIRECTORY }}/... if [ ! -f myapp ]; then echo "Build failed: myapp executable was not created." exit 1 @@ -110,3 +78,4 @@ jobs: echo "Build succeeded: myapp executable created." fi +4