From d84fd1cfbdad8b9b9f1e4053a4408ce3c32d8495 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Tue, 6 Nov 2018 00:52:45 +0100 Subject: [PATCH] try gitlab-ci --- .ci/check-gofmt | 8 ++++++++ .ci/check-testfiles | 25 +++++++++++++++++++++++++ .gitlab-ci.yml | 34 ++++++++++++++++++++++++++++++++++ .test-coverage | 33 --------------------------------- bot/filter.go | 8 ++++---- bot/hostname.go | 4 ++-- bot/priority.go | 6 +++--- bot/replace.go | 8 ++++---- bot/send.go | 8 ++++---- circle.yml | 41 ----------------------------------------- 10 files changed, 84 insertions(+), 91 deletions(-) create mode 100755 .ci/check-gofmt create mode 100755 .ci/check-testfiles create mode 100644 .gitlab-ci.yml delete mode 100755 .test-coverage delete mode 100644 circle.yml diff --git a/.ci/check-gofmt b/.ci/check-gofmt new file mode 100755 index 0000000..4a1c0b2 --- /dev/null +++ b/.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/.ci/check-testfiles b/.ci/check-testfiles new file mode 100755 index 0000000..132ff73 --- /dev/null +++ b/.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.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/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..079adbd --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,34 @@ +image: golang:latest +stages: + - build + - test + +before_script: + - mkdir -p /go/src/git.sum7.eu/genofire/ + - cp -R /builds/genofire/logmania /go/src/git.sum7.eu/genofire/logmania + - cd /go/src/git.sum7.eu/genofire/logmania + - go get -d -t ./... + +build-my-project: + stage: build + script: + - go install git.sum7.eu/genofire/logmania + artifacts: + paths: + - /go/bin/logmania + +test-my-project: + stage: test + script: + - ./.ci/check-gofmt + - ./.ci/check-testfiles + - ./.ci/check-misspell + - go test $(go list ./... | grep -v /vendor/) -v -coverprofile .testCoverage.txt + artifacts: + paths: + - .testCoverage.txt + +test-race-my-project: + stage: test + script: + - go test -race ./... diff --git a/.test-coverage b/.test-coverage deleted file mode 100755 index 8eb8329..0000000 --- a/.test-coverage +++ /dev/null @@ -1,33 +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" - -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 -if [ "$FAIL" -eq 0 ]; then - goveralls -v -coverprofile=profile.cov -service=$CI -repotoken=$COVERALLS_REPO_TOKEN - bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN -f profile.cov -fi - -exit $FAIL diff --git a/bot/filter.go b/bot/filter.go index ede3450..f51edb0 100644 --- a/bot/filter.go +++ b/bot/filter.go @@ -11,7 +11,7 @@ func NewFilter(db *database.DB) *Command { Name: "filter", Description: "list and configurate regex filter for channel by message content", Commands: []*Command{ - &Command{ + { Name: "add", Description: "add regex filter for channel: [channel] regex", Action: func(from string, params []string) string { @@ -32,7 +32,7 @@ func NewFilter(db *database.DB) *Command { return fmt.Sprintf("add regex for \"%s\" to %s", of, regex) }, }, - &Command{ + { Name: "del", Description: "del regex filter for channel: [channel] regex", Action: func(from string, params []string) string { @@ -50,7 +50,7 @@ func NewFilter(db *database.DB) *Command { return "deleted" }, }, - &Command{ + { Name: "all", Description: "list of all channels", Action: func(from string, params []string) string { @@ -64,7 +64,7 @@ func NewFilter(db *database.DB) *Command { return msg }, }, - &Command{ + { Name: "channel", Description: "list of given channel: channel", Action: func(from string, params []string) string { diff --git a/bot/hostname.go b/bot/hostname.go index 66fbd3d..0e684f5 100644 --- a/bot/hostname.go +++ b/bot/hostname.go @@ -12,7 +12,7 @@ func NewHostname(db *database.DB) *Command { Name: "hostname", Description: "alternative short (host)names for long IP-Addresses or URLs (and time of last recieved input)", Commands: []*Command{ - &Command{ + { Name: "set", Description: "set or replace a hostname: IPAddress/Hostname NewHostname", Action: func(from string, params []string) string { @@ -31,7 +31,7 @@ func NewHostname(db *database.DB) *Command { return fmt.Sprintf("set for %s the hostname %s", addr, name) }, }, - &Command{ + { Name: "del", Description: "delete a hostname: IPAddress/Hostname", Action: func(from string, params []string) string { diff --git a/bot/priority.go b/bot/priority.go index 68b52c8..6ade64a 100644 --- a/bot/priority.go +++ b/bot/priority.go @@ -13,7 +13,7 @@ func NewPriority(db *database.DB) *Command { Name: "priority", Description: "list and configurate priority in channel", Commands: []*Command{ - &Command{ + { Name: "set", Description: "set max priority of channel: [channel] Priority", Action: func(from string, params []string) string { @@ -43,7 +43,7 @@ func NewPriority(db *database.DB) *Command { return fmt.Sprintf("set filter for %s to %s", to, max.String()) }, }, - &Command{ + { Name: "all", Description: "list of all channels", Action: func(from string, params []string) string { @@ -54,7 +54,7 @@ func NewPriority(db *database.DB) *Command { return msg }, }, - &Command{ + { Name: "channel", Description: "list of given channel: channel", Action: func(from string, params []string) string { diff --git a/bot/replace.go b/bot/replace.go index 45df105..c26cff4 100644 --- a/bot/replace.go +++ b/bot/replace.go @@ -11,7 +11,7 @@ func NewReplace(db *database.DB) *Command { Name: "replace", Description: "list and configurate replace content of message for channel", Commands: []*Command{ - &Command{ + { Name: "add", Description: "add regex replace for channel: [channel] regex replace", Action: func(from string, params []string) string { @@ -34,7 +34,7 @@ func NewReplace(db *database.DB) *Command { return fmt.Sprintf("add replace in \"%s\" for \"%s\" to \"%s\"", of, regex, value) }, }, - &Command{ + { Name: "del", Description: "del regex replace for channel: [channel] regex replace", Action: func(from string, params []string) string { @@ -54,7 +54,7 @@ func NewReplace(db *database.DB) *Command { }, }, - &Command{ + { Name: "all", Description: "list of all channels", Action: func(from string, params []string) string { @@ -68,7 +68,7 @@ func NewReplace(db *database.DB) *Command { return msg }, }, - &Command{ + { Name: "channel", Description: "list of given channel: channel", Action: func(from string, params []string) string { diff --git a/bot/send.go b/bot/send.go index 381f0b8..bdb41f4 100644 --- a/bot/send.go +++ b/bot/send.go @@ -11,7 +11,7 @@ func NewSend(db *database.DB) *Command { Name: "send", Description: "list and configurate destination for hostnames", Commands: []*Command{ - &Command{ + { Name: "add", Description: "add a destination for host with: IPAddress/Hostname [to]", Action: func(from string, params []string) string { @@ -43,7 +43,7 @@ func NewSend(db *database.DB) *Command { return fmt.Sprintf("added %s in list of %s", to, host) }, }, - &Command{ + { Name: "del", Description: "del a destination for host with: IPAddress/Hostname [to]", Action: func(from string, params []string) string { @@ -63,7 +63,7 @@ func NewSend(db *database.DB) *Command { return "not found host" }, }, - &Command{ + { Name: "all", Description: "list of all hosts with there channels", Action: func(from string, params []string) string { @@ -85,7 +85,7 @@ func NewSend(db *database.DB) *Command { return msg }, }, - &Command{ + { Name: "channel", Description: "list all host of given channel: channel", Action: func(from string, params []string) string { diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 26c2cf8..0000000 --- a/circle.yml +++ /dev/null @@ -1,41 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: circleci/golang:latest - working_directory: /go/src/dev.sum7.eu/genofire/logmania - steps: - - checkout - - run: go get -t -d -v ./... - - run: go install dev.sum7.eu/genofire/logmania - - store_artifacts: - path: /go/bin/ - destination: logmania - test: - docker: - - image: circleci/golang:latest - working_directory: /go/src/dev.sum7.eu/genofire/logmania - steps: - - checkout - - run: go get -t -d -v ./... - - run: go get github.com/mattn/goveralls - - run: go get golang.org/x/tools/cmd/cover - - run: ./.test-coverage circle-ci - - store_test_results: - path: ./ - destination: profile.cov - test_race: - docker: - - image: circleci/golang:latest - working_directory: /go/src/dev.sum7.eu/genofire/logmania - steps: - - checkout - - run: go get -t -d -v ./... - - run: go test -race ./... -workflows: - version: 2 - build_and_tests: - jobs: - - build - - test - - test_race