feat: coverage on PRs #13
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This workflow will build a golang project | |
| # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | |
| name: Go CI build and test | |
| on: | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: '1.24' | |
| - name: Install dependencies | |
| run: go mod tidy | |
| - name: Build | |
| id: go_build | |
| run: go build -v ./... | |
| - name: Run tests with coverage | |
| id: go_test | |
| run: | | |
| go test ./... -coverprofile=coverage.out | |
| go tool cover -func=coverage.out > coverage.txt | |
| coverage=$(tail -n 1 coverage.txt | awk '{print $3}') | |
| echo "Overall test coverage: $coverage" | |
| echo "setting coverage brief" | |
| echo "coverage=$coverage" >> $GITHUB_ENV | |
| echo "Setting details" | |
| { | |
| echo 'coverage_details<<EOF' | |
| cat coverage.txt | |
| echo EOF | |
| } >> "$GITHUB_ENV" | |
| echo "done setting" | |
| - name: Echo Coverage Result | |
| run: | | |
| echo "Overall test coverage: ${{ env.coverage }}" | |
| - name: Create comment | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| token: ${{ secrets.PAT_TOKEN }} | |
| issue-number: ${{ github.event.pull_request.number }}' | |
| edit-mode: append | |
| body: | | |
| ## Test Coverage Report | |
| The overall test coverage is **$${{ env.coverage }}**. | |
| ### Coverage Details | |
| ``` | |
| ${{ env.coverage_details}} | |
| ``` | |