From a4dbd2102ff3fd3a65f9653af5c7bddd8b54d643 Mon Sep 17 00:00:00 2001
From: Philipp Borucki
Date: Thu, 26 Oct 2023 22:06:26 +0200
Subject: [PATCH] test: add workflow for code coverage
---
.github/workflows/create coverage badge.yml | 61 +++++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 .github/workflows/create coverage badge.yml
diff --git a/.github/workflows/create coverage badge.yml b/.github/workflows/create coverage badge.yml
new file mode 100644
index 00000000..7ad53528
--- /dev/null
+++ b/.github/workflows/create coverage badge.yml
@@ -0,0 +1,61 @@
+name: Create code coverage badge
+
+on:
+ pull_request:
+ branches:
+ - develop
+ - main
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ name: Update coverage badge
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+ 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.
+
+ - name: Setup go
+ uses: actions/setup-go@v2
+ with:
+ go-version: '1.14.4'
+
+ - uses: actions/cache@v2
+ with:
+ path: ~/go/pkg/mod
+ key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+ restore-keys: |
+ ${{ runner.os }}-go-
+
+ - name: Run Test
+ run: |
+ go test -v ./... -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@v12
+ 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."
+
+ - name: Push changes
+ if: steps.verify-changed-files.outputs.files_changed == 'true'
+ uses: ad-m/github-push-action@master
+ with:
+ github_token: ${{ github.token }}
+ branch: ${{ github.head_ref }}
\ No newline at end of file