From cca8a0a88c94a7529f4df403c8217a845e9acd10 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Fri, 24 Aug 2018 01:21:35 +0200 Subject: [PATCH] cleanup ci --- .drone.yml | 18 ++++-- .travis.yml | 11 ++++ README.md | 2 + circle.yml | 68 +++++++++++++++------ .test-coverage => contrib/ci/check-coverage | 18 ++++-- contrib/ci/check-gofmt | 8 +++ contrib/ci/check-testfiles | 25 ++++++++ file/main_test.go | 2 +- 8 files changed, 124 insertions(+), 28 deletions(-) rename .test-coverage => contrib/ci/check-coverage (77%) create mode 100755 contrib/ci/check-gofmt create mode 100755 contrib/ci/check-testfiles diff --git a/.drone.yml b/.drone.yml index dc498a5..41a90a5 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,19 +1,27 @@ pipeline: - test: + # 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 -d -t ./... - go get -u github.com/mattn/goveralls - go get -u golang.org/x/tools/cmd/cover - - ./.test-coverage + - go get -d -t ./... + - ./contrib/ci/check-coverage drone.io codestyle: image: golang:latest commands: + - go get -d -t ./... + - ./contrib/ci/check-testfiles + - ./contrib/ci/check-gofmt - go get github.com/client9/misspell/cmd/misspell - misspell -error . - - if [ -n "$(gofmt -s -l .)" ]; then echo "Go code is not formatted, run 'gofmt -s -w .'" >&2; exit 1; fi test-race: image: golang:latest commands: - go get -d -t ./... - - go test -v -cover --race ./... + - go test -race ./... diff --git a/.travis.yml b/.travis.yml index fa3283d..557587c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,14 @@ go: - tip install: - go get -t dev.sum7.eu/genofire/golang-lib/... + - go get github.com/mattn/goveralls + - go get golang.org/x/tools/cmd/cover + - go get github.com/client9/misspell/cmd/misspell +script: + - cd $GOPATH/src/dev.sum7.eu/genofire/golang-lib + # - go install # Library does not need to build + - ./contrib/ci/check-coverage travis-ci + - ./contrib/ci/check-testfiles + - ./contrib/ci/check-gofmt + - misspell -error . + - go test -race ./... diff --git a/README.md b/README.md index dd138dd..f366c35 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![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) [![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) + some packages collected for easy and often used functions diff --git a/circle.yml b/circle.yml index ac5a5bc..ee4ea06 100644 --- a/circle.yml +++ b/circle.yml @@ -1,18 +1,50 @@ -machine: - environment: - GOROOT: "" - PATH: "/usr/local/go/bin:/usr/local/go_workspace/bin:~/.go_workspace/bin:${PATH}" - GOPATH: "${HOME}/.go_workspace" - -dependencies: - override: - - mkdir -p ~/.go_workspace/src/github.com/${CIRCLE_PROJECT_USERNAME} - - ln -s ${HOME}/${CIRCLE_PROJECT_REPONAME} ${HOME}/.go_workspace/src/github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME} - - go get -t -d -v ./... - -test: - pre: - - go get -u github.com/mattn/goveralls - - go get -u golang.org/x/tools/cmd/cover - override: - - ./.test-coverage circle-ci +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/.test-coverage b/contrib/ci/check-coverage similarity index 77% rename from .test-coverage rename to contrib/ci/check-coverage index 73b6e7f..955e074 100755 --- a/.test-coverage +++ b/contrib/ci/check-coverage @@ -4,6 +4,11 @@ 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 @@ -25,9 +30,14 @@ do done # Failures have incomplete results, so don't send -if [ "$FAIL" -eq 0 ]; then - bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN -f profile.cov +[ "$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 - -exit $FAIL diff --git a/contrib/ci/check-gofmt b/contrib/ci/check-gofmt new file mode 100755 index 0000000..4a1c0b2 --- /dev/null +++ b/contrib/ci/check-gofmt @@ -0,0 +1,8 @@ +#!/bin/bash + +result="$(gofmt -s -l . | grep -v '^vendor/' )" +if [ -n "$result" ]; then + echo "Go code is not formatted, run 'gofmt -s -w .'" >&2 + echo "$result" + exit 1 +fi diff --git a/contrib/ci/check-testfiles b/contrib/ci/check-testfiles new file mode 100755 index 0000000..57dbe56 --- /dev/null +++ b/contrib/ci/check-testfiles @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# checks if every desired package has test files + +import os +import re +import sys + +source_re = re.compile(".*\.go") +test_re = re.compile(".*_test\.go") +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("./."): + continue + + # source files but not test files? + if len(filter(source_re.match, files)) > 0 and len(filter(test_re.match, files)) == 0: + print("no test files for {}".format(root)) + missing = True + +if missing: + sys.exit(1) +else: + print("every package has test files") diff --git a/file/main_test.go b/file/main_test.go index d9ed60c..535c6a0 100644 --- a/file/main_test.go +++ b/file/main_test.go @@ -54,7 +54,7 @@ func TestSaveJSON(t *testing.T) { err = SaveJSON(tmpfile.Name(), tmpfile.Name) assert.Error(err, "could not save func") - err = SaveJSON("/dev/null", 4) + err = SaveJSON("/proc/readonly", 4) assert.Error(err, "could not save to /dev/null") var testvalue int