diff --git a/.circleci/config.yml b/.circleci/config.yml index 7941406..954d9a3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,51 +1,53 @@ -defaults: &defaults - working_directory: /go/src/moul.io/golang-repo-template - docker: - - image: circleci/golang:1.12 - environment: - GO111MODULE: "on" +version: 2.1 -install_retry: &install_retry - run: - name: install retry - command: | - command -v wget &>/dev/null && wget -O /tmp/retry "https://github.com/moul/retry/releases/download/v0.5.0/retry_$(uname -s)_$(uname -m)" || true - if [ ! -f /tmp/retry ]; then command -v curl &>/dev/null && curl -L -o /tmp/retry "https://github.com/moul/retry/releases/download/v0.5.0/retry_$(uname -s)_$(uname -m)"; fi - chmod +x /tmp/retry - /tmp/retry --version +executors: + golang: + working_directory: /go/src/moul.io/golang-repo-template + docker: + - image: circleci/golang:1.12 + environment: + GO111MODULE: "on" + DOCKER_IMAGE: moul/golang-repo-template + +commands: + install-retry: + steps: + - run: command -v wget &>/dev/null && wget -O /tmp/retry "https://github.com/moul/retry/releases/download/v0.5.0/retry_$(uname -s)_$(uname -m)" || true + - run: if [ ! -f /tmp/retry ]; then command -v curl &>/dev/null && curl -L -o /tmp/retry "https://github.com/moul/retry/releases/download/v0.5.0/retry_$(uname -s)_$(uname -m)"; fi + - run: chmod +x /tmp/retry + - run: /tmp/retry --version + install-golangci-lint: + steps: + - run: /tmp/retry -m 3 curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.15.0 + +orbs: + codecov: codecov/codecov@1.0.2 -version: 2 jobs: - go.build: - <<: *defaults + go-build: + executor: golang steps: - checkout - - *install_retry + - install-retry - run: /tmp/retry -m 3 go mod download - run: /tmp/retry -m 3 make install - - run: /tmp/retry -m 3 go test -v ./... - - run: /tmp/retry -m 3 curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.15.0 + - run: /tmp/retry -m 3 make test + - install-golangci-lint - run: PATH=$PATH:$(pwd)/bin /tmp/retry -m 3 make lint + - codecov/upload: + file: coverage.txt - docker.build: - <<: *defaults + docker-build: + executor: golang steps: - checkout - #- run: - # name: Install Docker Compose - # command: | - # umask 022 - # curl -L https://github.com/docker/compose/releases/download/1.11.4/docker-compose-`uname -s`-`uname -m` > ~/docker-compose - setup_remote_docker: docker_layer_caching: true - - *install_retry - - run: /tmp/retry -m 3 docker build -t moul/golang-repo-template . - + - install-retry + - run: /tmp/retry -m 3 docker build -t ${DOCKER_IMAGE} . workflows: - version: 2 - build_and_integration: + main: jobs: - - go.build - - docker.build - # requires: docker.build? + - go-build + - docker-build diff --git a/.gitignore b/.gitignore index 060c689..60f6c2f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *~ *# .#* +coverage.txt # Vendors node_modules/ diff --git a/Makefile b/Makefile index 48f09b0..91a40b6 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,15 @@ install: .PHONY: test test: - set -e; for dir in `find . -type f -name "go.mod" | sed -r 's@/[^/]+$$@@' | sort | uniq`; do \ - (set -xe; cd $$dir; $(GO) test -v -cover -race ./...); \ - done + echo "" > /tmp/coverage.txt + set -e; for dir in `find . -type f -name "go.mod" | sed -r 's@/[^/]+$$@@' | sort | uniq`; do ( set -xe; \ + cd $$dir; \ + $(GO) test -v -cover -coverprofile=/tmp/profile.out -covermode=atomic -race ./...; \ + if [ -f /tmp/profile.out ]; then \ + cat /tmp/profile.out >> /tmp/coverage.txt; \ + rm -f /tmp/profile.out; \ + fi); done + mv /tmp/coverage.txt . .PHONY: lint lint: diff --git a/README.md b/README.md index cd6f033..bb6e0ee 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ [![GitHub release](https://img.shields.io/github/release/moul/golang-repo-template.svg)](https://github.com/moul/golang-repo-template/releases) [![Go Report Card](https://goreportcard.com/badge/moul.io/golang-repo-template)](https://goreportcard.com/report/moul.io/golang-repo-template) [![CodeFactor](https://www.codefactor.io/repository/github/moul/golang-repo-template/badge)](https://www.codefactor.io/repository/github/moul/golang-repo-template) +[![codecov](https://codecov.io/gh/moul/golang-repo-template/branch/master/graph/badge.svg)](https://codecov.io/gh/moul/golang-repo-template) [![Docker Metrics](https://images.microbadger.com/badges/image/moul/golang-repo-template.svg)](https://microbadger.com/images/moul/golang-repo-template) [![Made by Manfred Touron](https://img.shields.io/badge/made%20by-Manfred%20Touron-blue.svg?style=flat)](https://manfred.life/) diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..b238a6d --- /dev/null +++ b/main_test.go @@ -0,0 +1,6 @@ +package main + +func Example() { + main() + // Output: Hello World! +}