Added coverage badge workflow #27
Workflow file for this run
This file contains 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: Go coverage badge # The name of the workflow that will appear on Github | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
name: Update coverage badge | |
permissions: | |
contents: write # We need write access to the repo | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
#persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. | |
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. | |
ref: ${{github.event.pull_request.head.ref}} | |
repository: ${{github.event.pull_request.head.repo.full_name}} | |
persist-credentials: false | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup go | |
uses: actions/setup-go@v4 | |
with: | |
go-version-file: 'go.mod' | |
- name: Run Test | |
run: | | |
go test -v ./pkg/... -covermode=count -coverprofile=coverage.out | |
go tool cover -func=coverage.out -o=coverage.out | |
- name: Go Coverage Badge # Pass the `coverage.out` output to this action | |
uses: tj-actions/coverage-badge-go@v2 | |
with: | |
filename: coverage.out | |
- name: Verify Changed files | |
uses: tj-actions/verify-changed-files@v16 | |
id: verify-changed-files | |
with: | |
files: README.md | |
- name: Commit changes | |
if: steps.verify-changed-files.outputs.files_changed == 'true' | |
run: | | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git add README.md | |
git commit -m "chore: Updated coverage badge." | |
git config --local --unset-all "http.https://github.com/.extraheader" | |
# git remote set-url origin https://kleineshertz@github.com/kleineshertz/capillaries.git | |
# git remote set-url origin https://x-access-token:${{secrets.GITHUB_TOKEN}}@github.com/kleineshertz/capillaries | |
- name: Push changes | |
if: steps.verify-changed-files.outputs.files_changed == 'true' | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
# branch: ${{ github.head_ref }} | |
branch: ${{github.event.pull_request.head.ref}} | |
repository: ${{github.event.pull_request.head.repo.full_name}} | |
force_with_lease: false | |