Skip to content

refactor: Rename and improve code quality workflow #2

refactor: Rename and improve code quality workflow

refactor: Rename and improve code quality workflow #2

name: Code Quality and Tests
on:
push:
paths-ignore:
- "**/*.md"
jobs:
lint-and-vet:
name: Lint and Vet Code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup GO
uses: actions/setup-go@v5
with:
go-version: '^1.22.0'
- name: Install GO linter
run: |
sudo apt-get install golint
- name: Run go linter
run: |
golint -set_exit_status ./...
- name: Run go Vet
run: |
go vet ./...
run-tests:
name: Run Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup GO
uses: actions/setup-go@v5
with:
go-version: '^1.22.0'
- name: Execute Tests and Generate Coverage Report
run: |
go test ./... -coverprofile coverage.out -covermode count
go tool cover -func coverage.out
- name: Check Test Coverage Threshold
env:
TESTCOVERAGE_THRESHOLD: 75
run: |
echo "Quality Gate: checking test coverage is above threshold ..."
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
totalCoverage=`go tool cover -func=coverage.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