[Minor] #17
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: Tests | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-go@v3 | |
with: | |
go-version: "^1.20.6" | |
- name: Setup GO environment | |
run: | | |
go mod download | |
go install golang.org/x/lint/golint@latest | |
go get . | |
- name: Lint | |
run: | | |
golint -set_exit_status ./... | |
- name: Vet | |
run: | | |
go vet ./... | |
- name: Unit tests | |
run: | | |
sudo go test -tags test ./... -coverprofile coverage.out -covermode count | |
sudo go tool cover -func coverage.out | |
- name: Check Codecov in pull request | |
if: github.event_name == 'pull_request' | |
with: | |
flags: 'no-update-pr-badge' | |
uses: codecov/codecov-action@v3 | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
- name: Upload coverage reports to Codecov | |
if: github.event_name != 'pull_request' | |
uses: codecov/codecov-action@v3 | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
- name: Quality Gate - Test coverage shall be above threshold | |
env: | |
TESTCOVERAGE_THRESHOLD: ${{ vars.MIN_COVERAGE }} | |
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 | |
- name: Build | |
run: go build -o dns | |