test #532
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
| name: test | |
| on: [push] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| test: | |
| name: test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: checkout | |
| uses: actions/checkout@v4 | |
| - name: setup go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| - name: test | |
| run: make test | |
| - name: check test coverage | |
| id: coverage | |
| uses: vladopajic/go-test-coverage@v2 | |
| with: | |
| config: ./.github/.testcoverage.yml | |
| git-branch: badges | |
| git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }} | |
| # Post coverage report as comment | |
| - name: get pull request ID | |
| id: get_pr_id | |
| run: | | |
| # Make an API call to find the pull request associated with this branch | |
| PR_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| "https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${{ github.ref_name }}&state=open") | |
| # Parse the PR ID if a pull request is found | |
| PR_ID=$(echo "$PR_DATA" | jq -r '.[0].number') | |
| # Output the PR ID if it exists | |
| if [ "$PR_ID" != "null" ]; then | |
| echo "pull_request_id=$PR_ID" >> $GITHUB_ENV | |
| else | |
| echo "No open pull request found for this branch." | |
| fi | |
| - name: find if coverage report is already present | |
| uses: peter-evans/find-comment@v3 | |
| id: fc | |
| with: | |
| issue-number: ${{ env.pull_request_id }} | |
| comment-author: 'github-actions[bot]' | |
| body-includes: 'Total test coverage: ' | |
| - name: post coverage report | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| issue-number: ${{ env.pull_request_id }} | |
| comment-id: ${{ steps.fc.outputs.comment-id }} | |
| body: | | |
| '``` | |
| ${{ fromJSON(steps.coverage.outputs.report) }} | |
| ```' | |
| edit-mode: replace |