[TASK] add gitlab-ci

This commit is contained in:
Martin/Geno 2019-02-14 01:32:27 +01:00
parent bcfdc26bb9
commit cad2441716
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
13 changed files with 87 additions and 56 deletions

8
.ci/check-gofmt Executable file
View File

@ -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

25
.ci/check-testfiles Executable file
View File

@ -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")

35
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,35 @@
image: golang:latest
stages:
- build
- test
before_script:
- mkdir -p /go/src/dev.sum7.eu/$CI_PROJECT_NAMESPACE/
- cp -R /builds/$CI_PROJECT_PATH /go/src/dev.sum7.eu/$CI_PROJECT_NAMESPACE/
- cd /go/src/dev.sum7.eu/$CI_PROJECT_PATH
- go get -d -t ./...
build-my-project:
stage: build
script:
- go install dev.sum7.eu/$CI_PROJECT_PATH
artifacts:
paths:
- /go/bin/$CI_PROJECT_NAME
test-my-project:
stage: test
script:
- go get github.com/client9/misspell/cmd/misspell
- misspell -error .
- ./.ci/check-gofmt
- ./.ci/check-testfiles
- 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 ./...

View File

@ -1 +1,5 @@
# hook2xmpp [![CircleCI](https://circleci.com/gh/genofire/hook2xmpp/tree/master.svg?style=shield)](https://circleci.com/gh/genofire/hook2xmpp/tree/master) [![Coverage Status](https://coveralls.io/repos/github/genofire/hook2xmpp/badge.svg?branch=master)](https://coveralls.io/github/genofire/hook2xmpp?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/genofire/hook2xmpp)](https://goreportcard.com/report/github.com/genofire/hook2xmpp) [![GoDoc](https://godoc.org/github.com/genofire/hook2xmpp?status.svg)](https://godoc.org/github.com/genofire/hook2xmpp) # hook2xmpp
[![Build Status](https://dev.sum7.eu/genofire/hook2xmpp/badges/master/build.svg)](https://dev.sum7.eu/genofire/hook2xmpp/pipelines)
[![Go Report Card](https://goreportcard.com/badge/dev.sum7.eu/genofire/hook2xmpp)](https://goreportcard.com/report/dev.sum7.eu/genofire/hook2xmpp)
[![GoDoc](https://godoc.org/dev.sum7.eu/genofire/hook2xmpp?status.svg)](https://godoc.org/dev.sum7.eu/genofire/hook2xmpp)

View File

@ -1,35 +0,0 @@
notify:
webhooks:
- url: https://hook2xmpp.pub.warehost.de/circleci
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 ./...
- go install github.com/genofire/hook2xmpp/cmd/hook2xmpp
post:
- cp ~/.go_workspace/bin/hook2xmpp hook2xmpp.bin
- tar -cvzf hook2xmpp-builded.tar.gz hook2xmpp.bin config_example.conf
- mv hook2xmpp-builded.tar.gz $CIRCLE_ARTIFACTS
test:
pre:
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover
override:
- ./.test-coverage circle-ci
deployment:
staging:
branch: master
commands:
- ./deploy.sh $HOST_FOR_STAGING $PORT_FOR_STAGING

1
circleci/main_test.go Normal file
View File

@ -0,0 +1 @@
package circleci

View File

@ -1,3 +1,4 @@
log_level = 50
webserver_bind = ":8080" webserver_bind = ":8080"
[xmpp] [xmpp]

View File

@ -1,14 +0,0 @@
#!/bin/bash
host=$1
port=$2
remote="circleci@${host}"
echo "deploying..."
ssh -p $port $remote sudo systemctl stop hook2xmpp;
RETVAL=$?
[ $RETVAL -ne 0 ] && exit 1
scp -q -P $port ~/.go_workspace/bin/hook2xmpp $remote:~/bin/hook2xmpp;
RETVAL=$?
ssh -p $port $remote sudo systemctl start hook2xmpp;
[ $RETVAL -eq 0 ] && RETVAL=$?
[ $RETVAL -ne 0 ] && exit 1
echo "deployed"

View File

@ -1,4 +1,4 @@
package circleci package grafana
import ( import (
"fmt" "fmt"

1
grafana/main_test.go Normal file
View File

@ -0,0 +1 @@
package grafana

View File

@ -28,6 +28,8 @@ func main() {
log.Panicf("error on read config: %s", err) log.Panicf("error on read config: %s", err)
} }
log.SetLevel(config.LogLevel)
// load config // load config
options := xmpp.Options{ options := xmpp.Options{
Host: config.XMPP.Host, Host: config.XMPP.Host,
@ -90,7 +92,6 @@ func main() {
log.Infof("started hock2xmpp with %s", client.JID()) log.Infof("started hock2xmpp with %s", client.JID())
notify("startup of hock2xmpp") notify("startup of hock2xmpp")
// Wait for system signal // Wait for system signal
sigs := make(chan os.Signal, 1) sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

View File

@ -1,6 +1,9 @@
package runtime package runtime
import "github.com/bdlm/std/logger"
type Config struct { type Config struct {
LogLevel logger.Level `toml:"log_level"`
WebserverBind string `toml:"webserver_bind"` WebserverBind string `toml:"webserver_bind"`
XMPP struct { XMPP struct {

1
runtime/xmpp_test.go Normal file
View File

@ -0,0 +1 @@
package runtime