Skip to content

update github action go version #77

update github action go version

update github action go version #77

Workflow file for this run

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Go
on:
push:
branches: [ "main" , "dev" , "dev-*" ]
paths-ignore:
- "**/*.md"
- "**/*.http"
pull_request:
branches: [ "main" ]
paths-ignore:
- "**/*.md"
- "**/*.http"
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.21"
- run: go version
- name: Vet
run: go vet ./...
- name: Unit tests
run: go test -v ./... -coverprofile=cover.out -covermode=count
- name: fix cover.out paths (_/home... -> ./)
run: |
cat cover.out
sed -i "s#_$(pwd)#.#g" cover.out
cat cover.out
- name: publish Go test results coverage
uses: actions/upload-artifact@v4
with:
name: code covarege report
path: cover.out
- name: coverage.html
run: go tool cover -html cover.out -o cover.html
- name: publish Go test results coverage
uses: actions/upload-artifact@v4
with:
name: code covarege report html
path: cover.html
# https://medium.com/synechron/how-to-set-up-a-test-coverage-threshold-in-go-and-github-167f69b940dc
- name: Quality Gate - Test coverage shall be above threshold
env:
TESTCOVERAGE_THRESHOLD: 90
run: |
echo "Quality Gate: checking test coverage is above threshold ..."
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
totalCoverage=`go tool cover -func=cover.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
echo "Current test coverage : $totalCoverage %"
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 >= $2)}') )); then
echo "OK"
else
echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
echo "Failed"
exit 1
fi