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/.drone.yml b/.drone.yml deleted file mode 100644 index b978b49..0000000 --- a/.drone.yml +++ /dev/null @@ -1,34 +0,0 @@ -workspace: - base: /go - path: src/dev.sum7.eu/genofire/wifictld-analyzer - -pipeline: - build: - image: golang:latest - commands: - - go get ./... - - go build - codestyle: - image: golang:latest - commands: - - 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: - image: golang:latest - commands: - - go get github.com/stretchr/testify/assert - - go test ./... -v -cover - test-race: - image: golang:latest - commands: - - go get github.com/stretchr/testify/assert - - go test ./... -v -race - release: - image: plugins/gitea-release - base_url: https://dev.sum7.eu - secrets: [ gitea_token ] - files: /go/bin/analyzer - draft: true - when: - event: tag diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..f73e981 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,50 @@ +image: golang:latest +stages: + - build + - test + - deploy + +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" + - mv "/go/bin/$CI_PROJECT_NAME" "/builds/$CI_PROJECT_PATH" + artifacts: + paths: + - config_example.conf + - "$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 ./... + +deploy: + stage: deploy + only: + - master + script: + - go install "dev.sum7.eu/$CI_PROJECT_PATH" + - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null + - scp -6 -o StrictHostKeyChecking=no -P $SSH_PORT "/go/bin/$CI_PROJECT_NAME" "$CI_PROJECT_NAME@$SSH_HOST":/opt/$CI_PROJECT_NAME/bin + - ssh -6 -o StrictHostKeyChecking=no -p $SSH_PORT "$CI_PROJECT_NAME@$SSH_HOST" sudo /usr/bin/systemctl restart $CI_PROJECT_NAME diff --git a/README.md b/README.md new file mode 100644 index 0000000..59f41e5 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# wifictld-analyzer +[![Build Status](https://dev.sum7.eu/genofire/wifictld-analyzer/badges/master/build.svg)](https://dev.sum7.eu/genofire/wifictld-analyzer/pipelines) +[![Go Report Card](https://goreportcard.com/badge/dev.sum7.eu/genofire/wifictld-analyzer)](https://goreportcard.com/report/dev.sum7.eu/genofire/wifictld-analyzer) +[![GoDoc](https://godoc.org/dev.sum7.eu/genofire/wifictld-analyzer?status.svg)](https://godoc.org/dev.sum7.eu/genofire/wifictld-analyzer) + + +## Get wifictld-analyzer + +#### Download + +Latest Build binary from ci here: + +[Download All](https://dev.sum7.eu/genofire/wifictld-analyzer/-/jobs/artifacts/master/download/?job=build-my-project) (with config example) + +[Download Binary](https://dev.sum7.eu/genofire/wifictld-analyzer/-/jobs/artifacts/master/raw/wifictld-analyzer?inline=false&job=build-my-project) + +#### Build + +```bash +go get -u dev.sum7.eu/genofire/wifictld-analyzer +``` + +## Configure + +see `config_example.conf` + +## Start / Boot + +_/lib/systemd/system/wifictld-analyzer.service_ : +``` +[Unit] +Description=wifictld-analyzer +After=network.target + +[Service] +Type=simple +# User=notRoot +ExecStart=/opt/go/bin/wifictld-analyzer controller /etc/wifictld-analyzer.conf +Restart=always +RestartSec=5sec + +[Install] +WantedBy=multi-user.target +``` + +Start: `systemctl start wifictld-analyzer` +Autostart: `systemctl enable wifictld-analyzer` diff --git a/example.conf b/config_example.conf similarity index 100% rename from example.conf rename to config_example.conf