From e617e88786c88b712a254cc0ac489ecf04e97397 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 | 30 ++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100755 .ci/check-gofmt create mode 100755 .ci/check-testfiles create mode 100644 .gitlab-ci.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..4b2b009 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,30 @@ +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 + - go test $(go list ./... | grep -v /vendor/) -v -coverprofile .testCoverage.txt + +test-race-my-project: + stage: test + script: + - go test -race ./...