Skip to content

Commit

Permalink
Merge pull request #1385 from gofr-dev/workflow_warning_step_refactor
Browse files Browse the repository at this point in the history
Workflow warning step refactor
  • Loading branch information
Umang01-hash authored Jan 17, 2025
2 parents 5f6d962 + 4863600 commit ee75965
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,22 @@ jobs:
run: |
go mod download
- name: Test
- name: Test and Count Warnings
run: |
export APP_ENV=test
go test gofr.dev/pkg/... -v -short -coverprofile package.cov -coverpkg=gofr.dev/pkg/...
warning_count=$(go test gofr.dev/pkg/... -v -short -coverprofile package.cov -coverpkg=gofr.dev/pkg/... | tee /dev/tty | grep -c "WARNING" || true)
grep -v '/mock_' package.cov > profile.cov
go tool cover -func profile.cov
- name: Count Warnings
id: count-warnings
run: |
warning_count=$(go test gofr.dev/pkg/... -v | grep -c "WARNING" || true)
codeCoverage=$(go tool cover -func profile.cov | awk '/total/ {print substr($3, 1, length($3)-1)}')
echo "Warnings found: $warning_count"
echo "warning_count=$warning_count" >> $GITHUB_ENV
echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV
- name: Fail if too many warnings
run: |
if [ ${{ env.warning_count }} -gt 10 ]; then
echo "Too many warnings: ${{ env.warning_count }}"
exit 1
fi
fi
- name: Upload Test Coverage
if: ${{ matrix.go-version == '1.22'}}
Expand Down Expand Up @@ -169,8 +165,10 @@ jobs:
# - 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;
# if (( $(echo "$codeCoverage < 92" | bc -l) )); then
# echo "code coverage cannot be less than 92%, currently its $codeCoverage%"
# exit 1
# fi
Submodule-Unit-Testing:
name: Submodule Unit Testing (v${{ matrix.go-version }})🛠
runs-on: ubuntu-latest
Expand Down Expand Up @@ -206,11 +204,22 @@ jobs:
# Run tests for the submodule and generate coverage
export APP_ENV=test
go test ./... -v -short -coverprofile=${module_name}.cov -coverpkg=./...
warning_count=$(go test ./... -v -short -coverprofile=${module_name}.cov -coverpkg=./... | tee /dev/tty | grep -c "WARNING" || true)
total_warning_count=$((total_warning_count + warning_count))
# Return to the root directory
cd -
done
echo "Total warnings found: $total_warning_count"
echo "total_warning_count=$total_warning_count" >> $GITHUB_ENV
- name: Fail if too many warnings
run: |
if [ ${{ env.total_warning_count }} -gt 10 ]; then
echo "Too many warnings: ${{ env.total_warning_count }}"
exit 1
fi
- name: Upload Coverage Reports
uses: actions/upload-artifact@v3
Expand Down

0 comments on commit ee75965

Please sign in to comment.