diff --git a/.circleci/check-coverage b/.circleci/check-coverage deleted file mode 100755 index 44c39b6..0000000 --- a/.circleci/check-coverage +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# Issue: https://github.com/mattn/goveralls/issues/20 -# Source: https://github.com/uber/go-torch/blob/63da5d33a225c195fea84610e2456d5f722f3963/.test-cover.sh - -cd ${GOPATH}/src/github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME} - -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 './.git*' -not -path '*/_*' -type d | grep -v '^./vendor/'); -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 -[ "$FAIL" -ne 0 ] && exit 1 - -goveralls -service=circle-ci -v -coverprofile=profile.cov -bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN -f profile.cov diff --git a/.circleci/check-gofmt b/.circleci/check-gofmt deleted file mode 100755 index 4a1c0b2..0000000 --- a/.circleci/check-gofmt +++ /dev/null @@ -1,8 +0,0 @@ -#!/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/.circleci/check-testfiles b/.circleci/check-testfiles deleted file mode 100755 index 320c3e1..0000000 --- a/.circleci/check-testfiles +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python3 -# 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(list(filter(source_re.match, files))) > 0 and len(list(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/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 6555c26..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,43 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: circleci/golang:latest - working_directory: /go/src/github.com/FreifunkBremen/yanic - steps: - - checkout - - run: go get -t ./... - - run: go install -ldflags "-X github.com/FreifunkBremen/yanic/cmd.VERSION=`git -C $GOPATH/src/github.com/FreifunkBremen/yanic rev-parse HEAD`" github.com/FreifunkBremen/yanic - - store_artifacts: - path: /go/bin/ - destination: yanic - test: - docker: - - image: circleci/golang:latest - working_directory: /go/src/github.com/FreifunkBremen/yanic - steps: - - checkout - - run: go get -t ./... - - run: go get github.com/mattn/goveralls - - run: go get golang.org/x/tools/cmd/cover - - run: ./.circleci/check-coverage - - store_test_results: - path: ./ - destination: profile.cov - - run: ./.circleci/check-gofmt - - run: ./.circleci/check-testfiles - test_race: - docker: - - image: circleci/golang:latest - working_directory: /go/src/github.com/FreifunkBremen/yanic - steps: - - checkout - - run: go get -t ./... - - run: go test -race ./... -workflows: - version: 2 - build_and_tests: - jobs: - - build - - test - - test_race diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..9c7e120 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,65 @@ +name: Test, Lint + +on: + push: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [1.17] + + steps: + - name: Setup Go ${{ matrix.go-version }} + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go-version }} + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.go-version }}-go- + + - name: Run tests + run: make test + + - uses: codecov/codecov-action@v2 + with: + file: coverage.out + + lint: + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [1.17] + + steps: + - name: Setup Go ${{ matrix.go-version }} + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go-version }} + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.go-version }}-go- + + - name: Run linter + uses: golangci/golangci-lint-action@v3 + with: + version: latest + skip-cache: true diff --git a/.gitignore b/.gitignore index be417c3..9421141 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,6 @@ _testmain.go webroot /config.toml /vendor -/bin \ No newline at end of file +/bin +coverage.html +coverage.out diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5414609 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ + +## testing + +.PHONY: coverage.out +coverage.out: + go test -race -covermode=atomic -coverprofile=$@ ./... + +coverage.html: coverage.out + go tool cover -html $< -o $@ + +.PHONY: test +test: coverage.out ## runs tests diff --git a/README.md b/README.md index 81ac92c..85a51a0 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,7 @@ __ __ _ Yet another node info collector ``` -[![CircleCI](https://circleci.com/gh/FreifunkBremen/yanic/tree/main.svg?style=shield)](https://circleci.com/gh/FreifunkBremen/yanic/tree/main) -[![Coverage Status](https://coveralls.io/repos/github/FreifunkBremen/yanic/badge.svg?branch=main)](https://coveralls.io/github/FreifunkBremen/yanic?branch=main) +[![Test, Lint](https://github.com/FreifunkBremen/yanic/actions/workflows/go.yml/badge.svg)](https://github.com/FreifunkBremen/yanic/actions/workflows/go.yml) [![codecov](https://codecov.io/gh/FreifunkBremen/yanic/branch/main/graph/badge.svg)](https://codecov.io/gh/FreifunkBremen/yanic) [![Go Report Card](https://goreportcard.com/badge/github.com/FreifunkBremen/yanic)](https://goreportcard.com/report/github.com/FreifunkBremen/yanic)