Skip to content

Commit

Permalink
Add coverage workflow and badge (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergerad authored Nov 23, 2023
1 parent c3605f9 commit 873899a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 37 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Test src and generate coverage badge

on:
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
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.

- name: Setup go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'

- name: Run lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55

- name: Go build
run: go build -v ./...

- 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@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 "[email protected]"
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 }}
37 changes: 0 additions & 37 deletions .github/workflows/test.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Relax
#### *...there's no need to panic.*

![Coverage](https://img.shields.io/badge/Coverage-100.0%25-brightgreen)

In some situations, encountering a panic can be problematic. For example:
* If your REST server panics while handling a POST request, you may end up with a dangling resource in your database;
* Applications that write state to filesystems may produce irrecoverable state if a series of dependant file writes is interrupted by a panic; and
Expand Down

0 comments on commit 873899a

Please sign in to comment.