forked from CrunchyData/pg_featureserv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve github ci (add linter check, test, packaging)
- Loading branch information
1 parent
a2c4317
commit 2f49abb
Showing
4 changed files
with
149 additions
and
8 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,34 @@ | ||
name: Linter | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
pre-commit: | ||
name: Pre-commit | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.19.x | ||
|
||
- uses: actions/setup-python@v3 | ||
with: | ||
python-version: 3.9.x | ||
|
||
- name: Install pre-commit | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y curl | ||
sudo pip install --upgrade pip | ||
sudo pip install pre-commit | ||
pre-commit install --install-hooks | ||
- name: Install golangci-lint | ||
run: | | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.49.0 | ||
- name: Run pre-commit | ||
run: | | ||
pre-commit run -a -v |
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
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,106 @@ | ||
# This workflow will install Go dependencies, run tests for 4 versions of Go | ||
# For more information see: https://support.github.com/features/actions | ||
|
||
name: Unit tests | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- ".github/workflows/*.yml" | ||
- "**/*.go" | ||
- "**/go.mod" | ||
- "**/go.sum" | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
env: | ||
POSTGRES_VERSION: "12" | ||
POSTGIS_VERSION: "3.0" | ||
POSTGRES_DB: pg_featureserv | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
|
||
jobs: | ||
go-test: | ||
name: Run go unit tests | ||
strategy: | ||
matrix: | ||
go-version: ["1.13", "1.16", "1.18", "1.19"] | ||
runs-on: ubuntu-latest | ||
|
||
services: | ||
postgis: | ||
image: postgis/postgis # unable to handle var in image name. Was: "postgis/postgis:${POSTGRES_VERSION}-${POSTGIS_VERSION}-alpine" | ||
env: | ||
POSTGRES_DB: pg_featureserv # mandatory duplicate | ||
POSTGRES_USER: postgres # mandatory duplicate | ||
POSTGRES_PASSWORD: postgres # mandatory duplicate | ||
ports: | ||
# Maps tcp port 5432 on service container to the host | ||
- 5432:5432 | ||
|
||
steps: | ||
- name: 'Install Go' | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- uses: actions/checkout@v3 | ||
|
||
- name: Install cobertura | ||
run: | | ||
go get github.com/boumenot/gocover-cobertura | ||
go install github.com/boumenot/gocover-cobertura | ||
- name: Run test | ||
run: | | ||
# run test: | ||
export DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost/${POSTGRES_DB}" | ||
PKGS=$(go list ./... | grep -v /vendor/) | ||
DEPS=$(go list ./... | grep -v vendor | grep -v test | xargs | sed 's/ /,/g') | ||
go test ${PKGS} -v \ | ||
-coverprofile=coverage_${{ matrix.go-version }}.out \ | ||
-covermode=count \ | ||
-coverpkg ${DEPS} | ||
- name: Generate report | ||
run: | | ||
go run github.com/boumenot/gocover-cobertura < coverage_${{ matrix.go-version }}.out > coverage-unit_${{ matrix.go-version }}.xml | ||
- name: compute valid coverage total | ||
run: | | ||
go tool cover -func=coverage_${{ matrix.go-version }}.out | ||
- name: Code Coverage Report | ||
uses: irongut/[email protected] | ||
with: | ||
filename: coverage-unit_*.xml | ||
badge: true | ||
fail_below_min: true | ||
format: markdown | ||
hide_branch_rate: false | ||
hide_complexity: true | ||
indicators: true | ||
output: both | ||
thresholds: '60 80' | ||
|
||
- name: Add Coverage PR Comment | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
if: github.event_name == 'pull_request' | ||
with: | ||
path: code-coverage-results.md | ||
|
||
# TODO: retrieve and publish test results | ||
# - name: Upload unit test results | ||
# uses: actions/upload-artifact@v3 | ||
# with: | ||
# name: python-test-results | ||
# path: junit/test-results-unit.xml | ||
|
||
- name: Upload coverage results | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: go-coverage-results | ||
path: coverage-unit_*.xml |
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