-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from MikeYast/add-git-workflow
Add linter, test run and coverage calculation
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Go CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
test_and_lint: | ||
name: Test, Lint, and Coverage | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.20 | ||
|
||
- name: Install dependencies | ||
run: go mod download | ||
|
||
- name: Run tests with coverage | ||
run: go test ./... -v -coverprofile=coverage.out | ||
|
||
- name: Calculate coverage | ||
run: go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}' | ||
id: coverage | ||
|
||
- name: Check coverage threshold | ||
run: | | ||
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}') | ||
if (( $(echo "$COVERAGE < 75.0" | bc -l) )); then | ||
echo "ERROR: Code coverage ($COVERAGE%) is below the threshold of 75%." | ||
exit 1 | ||
else | ||
echo "Code coverage ($COVERAGE%) meets the threshold of 75%." | ||
fi | ||
- name: Install GolangCI-Lint | ||
run: go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
|
||
- name: Run GolangCI-Lint | ||
run: golangci-lint run |