Skip to content

Commit

Permalink
chore: improve github ci (add linter check, test, packaging)
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitdm-oslandia committed Nov 9, 2022
1 parent a2c4317 commit 2f49abb
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 8 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/linter.yml
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
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml → .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
on: [push, pull_request]
name: Package

on: [pull_request]
jobs:
ci:
name: CI
build_package:
name: Build and package
strategy:
matrix:
go-version: [1.16.x]
Expand All @@ -10,16 +12,13 @@ jobs:
steps:

- name: 'Install Go'
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Checkout
uses: actions/checkout@v3

- name: Test
run: make test

- name: Build
run: make build

Expand Down
106 changes: 106 additions & 0 deletions .github/workflows/unit-test.yml
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

# pg_featureserv

[![.github/workflows/ci.yml](https://github.com/CrunchyData/pg_featureserv/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/CrunchyData/pg_featureserv/actions/workflows/ci.yml)
[![.github/workflows/package.yml](https://github.com/CrunchyData/pg_featureserv/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/CrunchyData/pg_featureserv/actions/workflows/ci.yml)

[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/benoitdm-oslandia/pg_featureserv/master.svg)](https://results.pre-commit.ci/latest/github/benoitdm-oslandia/pg_featureserv/master)

A lightweight RESTful geospatial feature server for [PostGIS](https://postgis.net/), written in [Go](https://golang.org/).
It supports the [*OGC API - Features*](https://ogcapi.ogc.org/features/) REST API standard.
Expand Down

0 comments on commit 2f49abb

Please sign in to comment.