From 8c62f770bcc3a47adb69f03ddefc678dbecb1af5 Mon Sep 17 00:00:00 2001 From: Arsham Arya Date: Thu, 18 Apr 2024 14:24:49 +0330 Subject: [PATCH] add: generate coverage action. --- .github/workflows/gen_coverage.yaml | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/gen_coverage.yaml diff --git a/.github/workflows/gen_coverage.yaml b/.github/workflows/gen_coverage.yaml new file mode 100644 index 0000000..36720bb --- /dev/null +++ b/.github/workflows/gen_coverage.yaml @@ -0,0 +1,52 @@ +name: Generate Test Coverage + +on: + push: + branches: [ main ] + workflow_dispatch: + +jobs: + + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + go: [1.20, 1.21] + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: Build + run: go install + + - name: Test + run: | + go test -v -coverpkg ./... -cover ./... -coverprofile coverage.out + go tool cover -func coverage.out -o coverage.out + + - name: Go Coverage Badge + uses: tj-actions/coverage-badge-go@v1 + if: ${{ runner.os == 'Linux' && matrix.go == '1.21' }} + with: + green: 80 + filename: coverage.out + + - uses: stefanzweifel/git-auto-commit-action@v4 + id: auto-commit-action + with: + commit_message: Apply Code Coverage Badge + skip_fetch: true + skip_checkout: true + file_pattern: ./README.md + + - name: Push Changes + if: steps.auto-commit-action.outputs.changes_detected == 'true' + uses: ad-m/github-push-action@master + with: + github_token: ${{ github.token }} + branch: ${{ github.ref }}