From 917e7db85b982fe34939c111ac86f31a867c7519 Mon Sep 17 00:00:00 2001 From: Geno Date: Tue, 1 Jun 2021 15:30:05 +0200 Subject: [PATCH] migrate ci to woodpicker - fix lint - install python3 - fix database - fix coverage (use own) --- {contrib/ci => .ci}/check-gofmt | 1 + {contrib/ci => .ci}/check-testfiles | 7 ++-- .drone.yml | 26 --------------- .woodpecker.yml | 29 +++++++++++++++++ README.md | 12 ++++--- circle.yml | 50 ----------------------------- contrib/ci/check-coverage | 43 ------------------------- web/webtest/main.go | 6 +++- 8 files changed, 46 insertions(+), 128 deletions(-) rename {contrib/ci => .ci}/check-gofmt (99%) rename {contrib/ci => .ci}/check-testfiles (64%) delete mode 100644 .drone.yml create mode 100644 .woodpecker.yml delete mode 100644 circle.yml delete mode 100755 contrib/ci/check-coverage diff --git a/contrib/ci/check-gofmt b/.ci/check-gofmt similarity index 99% rename from contrib/ci/check-gofmt rename to .ci/check-gofmt index 4a1c0b2..df9d8eb 100755 --- a/contrib/ci/check-gofmt +++ b/.ci/check-gofmt @@ -6,3 +6,4 @@ if [ -n "$result" ]; then echo "$result" exit 1 fi + diff --git a/contrib/ci/check-testfiles b/.ci/check-testfiles similarity index 64% rename from contrib/ci/check-testfiles rename to .ci/check-testfiles index 57dbe56..7c2b5fa 100755 --- a/contrib/ci/check-testfiles +++ b/.ci/check-testfiles @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # checks if every desired package has test files import os @@ -11,11 +11,11 @@ missing = False for root, dirs, files in os.walk("."): # ignore some paths - if root == "." or root == "./database/graphite" or root.startswith("./vendor") or root.startswith("./."): + if root == "." or root.startswith("./vendor") or root.startswith("./.") or root.startswith("./docs"): continue # source files but not test files? - if len(filter(source_re.match, files)) > 0 and len(filter(test_re.match, files)) == 0: + if len([f for f in files if source_re.match(f)]) > 0 and len([f for f in files if test_re.match(f)]) == 0: print("no test files for {}".format(root)) missing = True @@ -23,3 +23,4 @@ if missing: sys.exit(1) else: print("every package has test files") + diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 1b06a57..0000000 --- a/.drone.yml +++ /dev/null @@ -1,26 +0,0 @@ -pipeline: - # Library does not need to build - #build: - # image: golang:latest - # commands: - # - go get -d -t ./... - # - go install - test-coverage: - image: golang:latest - commands: - - go get -u github.com/mattn/goveralls - - go get -u golang.org/x/tools/cmd/cover - - go get -d -t ./... - - ./contrib/ci/check-coverage drone.io - codestyle: - image: golang:latest - commands: - - ./contrib/ci/check-testfiles - - ./contrib/ci/check-gofmt - - go get github.com/client9/misspell/cmd/misspell - - misspell -error . - test-race: - image: golang:latest - commands: - - go get -d -t ./... - - go test -race ./... diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..3f12964 --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,29 @@ +services: + database: + image: cockroachdb/cockroach:latest + commands: + - cockroach start-single-node --insecure + +pipeline: + lint: + image: golang:latest + commands: + - apt update + - apt install python3 --yes + - ./.ci/check-testfiles + - ./.ci/check-gofmt + - go get github.com/client9/misspell/cmd/misspell + - misspell -error . + + test-coverage: + image: golang:latest + commands: + - go get -d -t ./... + - go test -ldflags "-X dev.sum7.eu/genofire/golang-lib/web/webtest.DBConnection=postgres://root:root@database:26257/defaultdb?sslmode=disable" $(go list ./... | grep -v /vendor/) -v -failfast -p 1 -coverprofile .testCoverage.txt + - go tool cover -func=".testCoverage.txt" + + test-race: + image: golang:latest + commands: + - go get -d -t ./... + - go test -ldflags "-X dev.sum7.eu/genofire/golang-lib/web/webtest.DBConnection=postgres://root:root@database:26257/defaultdb?sslmode=disable" $(go list ./... | grep -v /vendor/) -race diff --git a/README.md b/README.md index f366c35..747b607 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # golang-lib -[![DroneCI](https://ci.sum7.eu/api/badges/genofire/golang-lib/status.svg?branch=master)](https://ci.sum7.eu/genofire/golang-lib) -[![Travis](https://travis-ci.org/genofire/golang-lib.svg?branch=master)](https://travis-ci.org/genofire/golang-lib) [![CircleCI](https://circleci.com/gh/genofire/golang-lib/tree/master.svg?style=shield)](https://circleci.com/gh/genofire/golang-lib/tree/master) -[![Coverage](https://coveralls.io/repos/github/genofire/golang-lib/badge.svg?branch=master)](https://coveralls.io/github/genofire/golang-lib?branch=master) -[![codecov](https://codecov.io/gh/genofire/golang-lib/branch/master/graph/badge.svg)](https://codecov.io/gh/genofire/golang-lib) +[![DroneCI](https://ci.sum7.eu/api/badges/genofire/golang-lib/status.svg?branch=main)](https://ci.sum7.eu/genofire/golang-lib) [![Go Report Card](https://goreportcard.com/badge/dev.sum7.eu/genofire/golang-lib)](https://goreportcard.com/report/dev.sum7.eu/genofire/golang-lib) -[![GoDoc](https://godoc.org/dev.sum7.eu/genofire/golang-lib?status.svg)](https://godoc.org/dev.sum7.eu/genofire/golang-lib) +[![GoDoc](https://pkg.go.dev/dev.sum7.eu/genofire/golang-lib?status.svg)](https://godoc.org/dev.sum7.eu/genofire/golang-lib) some packages collected for easy and often used functions + +- `file`: Read and Save - JSON, TOML +- `database`: Start by Config, Migrate +- `worker`: cronjob +- `web`: helpers for golang-gin framework e.g. websocket, metrics, status, auth diff --git a/circle.yml b/circle.yml deleted file mode 100644 index ee4ea06..0000000 --- a/circle.yml +++ /dev/null @@ -1,50 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: circleci/golang:latest - working_directory: /go/src/github.com/genofire/golang-lib - steps: - - checkout - - run: go get -d -t ./... - - run: go install - test-coverage: - docker: - - image: circleci/golang:latest - working_directory: /go/src/github.com/genofire/golang-lib - steps: - - checkout - - run: go get -d -t ./... - - run: go get github.com/mattn/goveralls - - run: go get golang.org/x/tools/cmd/cover - - run: ./contrib/ci/check-coverage circle-ci - - store_test_results: - path: ./ - destination: profile.cov - codestyle: - docker: - - image: circleci/golang:latest - working_directory: /go/src/github.com/genofire/golang-lib - steps: - - checkout - - run: go get -d -t ./... - - run: ./contrib/ci/check-testfiles - - run: ./contrib/ci/check-gofmt - - run: go get github.com/client9/misspell/cmd/misspell - - run: misspell -error . - test_race: - docker: - - image: circleci/golang:latest - working_directory: /go/src/github.com/genofire/golang-lib - steps: - - checkout - - run: go get -d -t ./... - - run: go test -race ./... -workflows: - version: 2 - build_and_tests: - jobs: - #- build # Library does not need to build - - test-coverage - - codestyle - - test_race diff --git a/contrib/ci/check-coverage b/contrib/ci/check-coverage deleted file mode 100755 index 955e074..0000000 --- a/contrib/ci/check-coverage +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -# Issue: https://github.com/mattn/goveralls/issues/20 -# Source: https://github.com/uber/go-torch/blob/63da5d33a225c195fea84610e2456d5f722f3963/.test-cover.sh -CI=$1 -echo "run for $CI" - -# circle-ci -# travis-ci -# travis-pro - - -if [ "$CI" == "circle-ci" ]; then - cd ${GOPATH}/src/github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME} -fi - -echo "mode: count" > profile.cov -FAIL=0 - -# Standard go tooling behavior is to ignore dirs with leading underscors -for dir in $(find . -maxdepth 10 -not -path './vendor/*' -not -path './.git*' -not -path '*/_*' -type d); -do - if ls $dir/*.go &> /dev/null; then - go test -v -covermode=count -coverprofile=profile.tmp $dir || FAIL=$? - if [ -f profile.tmp ] - then - tail -n +2 < profile.tmp >> profile.cov - rm profile.tmp - fi - fi -done - -# Failures have incomplete results, so don't send -[ "$FAIL" -ne 0 ] && exit 1 - -# ci not publishing -[ "$CI" == "" ] && exit 0 - -if [ "$CODECOV_TOKEN" != "" ]; then - bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN -f profile.cov -fi -if [ "$COVERALLS_REPO_TOKEN" != "" ] ; then - goveralls -v -coverprofile=profile.cov -service=$CI -repotoken=$COVERALLS_REPO_TOKEN -fi diff --git a/web/webtest/main.go b/web/webtest/main.go index 589065d..6f4a66b 100644 --- a/web/webtest/main.go +++ b/web/webtest/main.go @@ -16,6 +16,10 @@ import ( "dev.sum7.eu/genofire/golang-lib/web" ) +var ( + DBConnection = "user=root password=root dbname=defaultdb host=localhost port=26257 sslmode=disable" +) + type testServer struct { db *database.Database gin *gin.Engine @@ -32,7 +36,7 @@ type Login struct { func New(assert *assert.Assertions) *testServer { // db setup dbConfig := database.Database{ - Connection: "user=root password=root dbname=defaultdb host=localhost port=26257 sslmode=disable", + Connection: DBConnection, Testdata: true, Debug: false, LogLevel: 0,