Feature/ci pipeline #11
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: Testing | |
on: | |
push: | |
branches: [master] | |
pull_request: | |
branches: [master] | |
workflow_dispatch: | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref }} | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: 1.22 | |
- name: Install dependencies | |
run: go mod download | |
- name: Run tests | |
run: go test -v -coverprofile=coverage.out ./... | |
- name: Extract coverage percentage | |
id: extract_coverage | |
run: | | |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}') | |
echo "COVERAGE=${COVERAGE}" >> $GITHUB_ENV | |
- name: Update README with coverage badge | |
run: | | |
COVERAGE=${{ env.COVERAGE }} | |
BADGE="[![Coverage](https://img.shields.io/badge/Coverage-${COVERAGE}-brightgreen)](./coverage.out)" | |
sed -i "1 s|.*|${BADGE}|" README.md | |
- name: Push README changes (PR Only) | |
if: ${{ github.event_name == 'pull_request' }} | |
uses: EndBug/add-and-commit@v9 | |
with: | |
default_author: github_actions | |
message: Update coverage badge in README | |
add: README.md | |
push: origin HEAD:${{ github.head_ref || github.ref_name }} |