From a8d7d37f2d071f848f055df775ab1da708dc95f8 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 24 Feb 2021 14:50:53 +0000 Subject: [PATCH] ci: Updated CI/CD to use GitHub actions instead of Travis (#282) * ci: Removing .travis.yml from CI build * ci: Renamed flex.yaml to push_pr.yml and updated job names to match. * ci: Ignoring pushes to docs or examples * ci: Added snyk scan to build process * ci: Cleaning up make target build-ci * ci: Adding code coverage using Coveralls * ci: Adding release workflow * ci: Enabling docker login * ci: Updated CI to use Docker to run tests Co-authored-by: noly --- .dockerignore | 1 + .github/workflows/flex.yaml | 57 ----------- .github/workflows/push_pr.yml | 117 +++++++++++++++++++++++ .github/workflows/release.yml | 121 ++++++++++++++++++++++++ .gitignore | 1 + .travis.yml | 24 ----- Makefile | 46 ++++----- README.md | 3 +- build/Dockerfile | 12 +++ build/ci.mk | 53 +++++++++++ build/deps.mk | 1 + .goreleaser.yml => build/goreleaser.yml | 27 ++---- build/release.mk | 24 +++++ build/testing.mk | 38 ++++---- integration-test/Dockerfile | 3 +- tools/go.mod | 1 + tools/go.sum | 13 +++ tools/tools.go | 1 + 18 files changed, 394 insertions(+), 149 deletions(-) delete mode 100644 .github/workflows/flex.yaml create mode 100644 .github/workflows/push_pr.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .travis.yml create mode 100644 build/Dockerfile create mode 100644 build/ci.mk rename .goreleaser.yml => build/goreleaser.yml (64%) create mode 100644 build/release.mk diff --git a/.dockerignore b/.dockerignore index c5754ad6..27747907 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ bin docs .git +vendor diff --git a/.github/workflows/flex.yaml b/.github/workflows/flex.yaml deleted file mode 100644 index c5dea949..00000000 --- a/.github/workflows/flex.yaml +++ /dev/null @@ -1,57 +0,0 @@ -name: Run tests - -on: [push, pull_request] -# if we want to limit builds on changes to code only - # pull_request: - # paths: - # - "**/*.go" - # push: - # paths: - # - "**/*.go" - # - "**/*.yaml" - -jobs: - test-linux: - strategy: - matrix: - # we can add multiple versions of go here. each one will generate a different (parallel) build - go: ['1.13.4'] - # we can also add multiple oses here. in conjunction with other parameters (go version for example) it will generate - # multiple parallel builds - os: [ubuntu-16.04] # ubuntu-16.04 and ubuntu-18.04 available out of the box - name: Run integration tests in ${{matrix.os}} with go ${{matrix.go}} - runs-on: ${{matrix.os}} - steps: - - name: checkout code - uses: actions/checkout@v2 - - name: install go - uses: actions/setup-go@v2 - with: - go-version: ${{matrix.go}} - - name: run integration tests - run: | - make build-ci - # we could have included windows above, but we can't becuase we don't have "make" in windows - # we should at some point create a powershell script similar to it - test-windows: - strategy: - matrix: - go: ['1.13.4'] - os: [windows-2019] # only 2019 one avaialable out of the box - name: Run integration tests in ${{matrix.os}} with go ${{matrix.go}} - runs-on: ${{matrix.os}} - steps: - - name: checkout - uses: actions/checkout@v2 - - name: install go - uses: actions/setup-go@v2 - with: - go-version: ${{matrix.go}} - - name: run unit tests - # we don't have 'make' on windows. - run: | - go test ./... - - name: run integration tests - # we don't have 'make' on windows. - run: | - go test --tags=integration ./... diff --git a/.github/workflows/push_pr.yml b/.github/workflows/push_pr.yml new file mode 100644 index 00000000..fe1cd686 --- /dev/null +++ b/.github/workflows/push_pr.yml @@ -0,0 +1,117 @@ +--- +name: Push/PR pipeline + +on: + push: + branches: + - '**' + tags-ignore: + - '**' + paths-ignore: + - README.md + - 'docs/**' + - 'examples/**' + +env: + REPO_FULL_NAME: ${{ github.event.repository.full_name }} + ORIGINAL_REPO_NAME: "newrelic/nri-flex" + GO_VERSION: '1.15' + +jobs: + + test-nix: + strategy: + matrix: + os: [ ubuntu-20.04 ] + name: Run unit tests in ${{matrix.os}} + runs-on: ${{matrix.os}} + steps: + - name: checkout code + uses: actions/checkout@v2 + - name: Run unit tests + run: make ci/test + - name: Convert coverage.out to lcov.info + run: make ci/convert-coverage + - name: Coveralls Parallel + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + path-to-lcov: lcov.info + flag-name: run-linux + parallel: true + + test-integration-nix: + name: Run integration tests + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.OHAI_DOCKER_HUB_ID }} + password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }} + - name: Run integration tests + run: make test-integration + + snyk: + name: Run security checks via snyk + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.OHAI_DOCKER_HUB_ID }} + password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }} + - name: Scan code for vulnerabilities + env: + SNYK_TOKEN: ${{ secrets.COREINT_SNYK_TOKEN }} + run: make ci/snyk-test + + test-windows: + strategy: + matrix: + go: [ '1.16' ] + os: [ windows-2019 ] + name: Run unit and integration tests in ${{matrix.os}} with go ${{matrix.go}} + runs-on: ${{matrix.os}} + steps: + - name: checkout + uses: actions/checkout@v2 + - name: install go + uses: actions/setup-go@v2 + with: + go-version: ${{matrix.go}} + - name: run unit tests + # we don't have 'make' on windows. + run: | + go test ./... + - name: run integration tests + # we don't have 'make' on windows. + run: | + go test --tags=integration ./... + + test-build: + name: Test binary compilation for all platforms:arch + runs-on: ubuntu-20.04 + steps: + - name: checkout + uses: actions/checkout@v2 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.OHAI_DOCKER_HUB_ID }} + password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }} + - name: Build all platforms:arch + run: make ci/pre-release + + finish: + name: Finish + needs: [ test-nix, test-windows ] + runs-on: ubuntu-20.04 + steps: + - name: Coveralls Finished + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + parallel-finished: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..e890a332 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,121 @@ +--- +name: Release pipeline + +on: + release: + types: + - prereleased + tags: + - 'v*' + +env: + GO_VERSION: '1.15' + TAG: ${{ github.event.release.tag_name }} + IS_RELEASE: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # needed for goreleaser + +jobs: + + test-nix: + strategy: + matrix: + os: [ ubuntu-20.04 ] + name: Run unit tests in ${{matrix.os}} + runs-on: ${{matrix.os}} + steps: + - name: checkout code + uses: actions/checkout@v2 + - name: Run unit tests + run: make ci/test + - name: Convert coverage.out to lcov.info + run: make ci/convert-coverage + - name: Coveralls Parallel + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + path-to-lcov: lcov.info + flag-name: run-linux + parallel: true + + test-integration-nix: + name: Run integration tests + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.OHAI_DOCKER_HUB_ID }} + password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }} + - name: Run integration tests + run: make test-integration + + snyk: + name: Run security checks via snyk + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.OHAI_DOCKER_HUB_ID }} + password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }} + - name: Scan code for vulnerabilities + env: + SNYK_TOKEN: ${{ secrets.COREINT_SNYK_TOKEN }} + run: make ci/snyk-test + + test-windows: + strategy: + matrix: + go: [ '1.15' ] + os: [ windows-2019 ] + name: Run unit and integration tests in ${{matrix.os}} with go ${{matrix.go}} + runs-on: ${{matrix.os}} + steps: + - name: checkout + uses: actions/checkout@v2 + - name: install go + uses: actions/setup-go@v2 + with: + go-version: ${{matrix.go}} + - name: run unit tests + # we don't have 'make' on windows. + run: | + go test ./... + - name: run integration tests + # we don't have 'make' on windows. + run: | + go test --tags=integration ./... + + prerelease: + name: Build and release binaries + runs-on: ubuntu-20.04 + needs: [ test-nix, test-windows, snyk, test-integration-nix ] + steps: + - uses: actions/checkout@v2 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.OHAI_DOCKER_HUB_ID }} + password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }} + - name: Pre release + run: make ci/pre-release + - name: Notify failure via Slack + if: ${{ failure() }} + uses: archive/github-actions-slack@master + with: + slack-bot-user-oauth-access-token: ${{ secrets.COREINT_SLACK_TOKEN }} + slack-channel: ${{ secrets.COREINT_SLACK_CHANNEL }} + slack-text: "❌ `${{ env.REPO_FULL_NAME }}`: prerelease pipeline failed." + + finish: + name: Finish + needs: [ prerelease ] + runs-on: ubuntu-20.04 + steps: + - name: Coveralls Finished + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + parallel-finished: true diff --git a/.gitignore b/.gitignore index e8cc6339..99a913b7 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ envvars flexConfigs/ results pkg/ +lcov.info diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 951c1653..00000000 --- a/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -language: go - -go: - - "1.13" - -services: - - docker - -script: make clean build-ci - -deploy: - - provider: script - cleanup: false - script: make release - on: - tags: true - -env: - global: - # github token - - secure: "qz3I7trkvwFz8ad22VA1FVtAW0xTnp55nuFCMo/drQ2kopMulPLXtIm3chTEnjErbTNuPAIYWLL1VkK2fUSnOLyblFSoxtndJtW63zZ0gsSFS1Lk+Dd//XpPaq3sxCPY3vD3ogYXexogEH79W+6tJL5Pci6p+Tgln37J+dWehEB4FuAanUJERyjdZ0mIWkPiz3NJNXKqPK9HsL9zp6H12s3JL78XDluG8aul39jMDbnczwLjLTOfpGdwAFzWchgFOlKwheuHsHUXk6NkO53vHbl489dOzJ+2Yzk9flS6p9xp9pDVOni3qcJoiWDGkayg2gDHOjZ0WBuR2CMK68HcPYDdN/yeqMkZqDXuEW7HiDQq4jvYT5tNHz+xAlWS/oYGICR8etriMxu5fh8itF6qnsEFtZANjqWf6XQIz9uvBjPG9bkdSf5ZkwJD88wPb0Bkin5HTyeODLbUyvPBK/ue4qrZ5UqmZ//BQ4Gu4dUlGa+/6HjZRUi40a4/Tg+epsayhdz9AJhT+XxK9vicSXKUF5bqX5ar4v+Xbw+PNVHMvWaBZ2J7I4SitEhZJ2AcwwB1lqBY1GcJLuLU6eDn3vD78k5qdcqWQ7FprlsrZ70V7WH3JdDoXoMqyaXOSDVN+FhPsb3ia0WhU1mE7MpGIms8ZkGHfxHbkPJuDZSrhKLkH0k=" - # Snyk token - - secure: "Y05CFwcRnLeLUWqGoPUrIzsQPglSBAyG1p5FTrCcF/qgMLSxF25cZtGez/foi+6hPF6abD4gFx8sJVEQaZGYhWuvqOpbhRbwx7l7sBRGiIzJ/23PIKUY0PhET2GJqBkMvE5DVUsUVPHHy2VRuCcjI5CSHzzDd8ix93YYDQhxpli3Ha4sLocmzmckfsCcHPXqF1Tz0B6KAuK8SDzkrqqJ+s8xOPby6Vkcd8k+GcKXSOh4dPhc2vjbYZn6Asn0jUN4z51HH/nbmsMDZbM4A3eRXtxWh4WCfY0GmPZpBQWuIJGTKwGjs37ASAH9r5w+f3XG5pTtsQaJoFur/VG0rnKma//2BaHB/fcE+6C506Iva5Ln566chMjP5+guL/S+yBZkEJXRF3gdgmmuJVQBxxWXKMxBpV+a6bwbVxOGkIDGwDtW/3uZrUlGD4nFjxVUt+yFZq53lHjGm7Z8J/qeYZZo1wu7y5oU9g6ZjHrVq1ng7IfalFpYWc6yx89a/woT8RfJJDRkB14kwHwTK6LSUO8BGZ0/yRj4EALMh+wRzbv0LS7fpL5Ei40/tbxbCyvRBjdeywXRtH36jgB7OOmhLwP+VonqpQrLEnlyOIvk7v1/LvPJJFdd5UneytY5yZ09F0jGcEvGuUsCL9yxk5dS+YTezB07xprsUjXD7+Bui9h1ftk=" diff --git a/Makefile b/Makefile index bf8d4206..b9f4205c 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,18 @@ -PROJECT_NAME := $(shell basename $(shell pwd)) -NATIVEOS := $(shell go version | awk -F '[ /]' '{print $$4}') -NATIVEARCH := $(shell go version | awk -F '[ /]' '{print $$5}') -GO_PKGS := $(shell go list ./... | grep -v -e "/vendor/" -e "/example") -SRCDIR ?= . -BUILD_DIR := ./bin/ -COVERAGE_DIR := ./coverage/ -COVERMODE = atomic - -GO_CMD = go -GODOC = godocdown +INTEGRATION := flex +PROJECT_NAME = nri-$(INTEGRATION) +NATIVEOS := $(shell go version | awk -F '[ /]' '{print $$4}') +NATIVEARCH := $(shell go version | awk -F '[ /]' '{print $$5}') +SRCDIR ?= . +BUILD_DIR ?= $(CURDIR)/bin +COVERAGE_FILE ?= coverage.out + +GO_VERSION ?= 1.15 +GO_CMD ?= go +GODOC ?= godocdown GOLINTER = golangci-lint GOLINTER_VERSION = v1.24.0 -GORELEASER_VERSION := v0.132.1 -GORELEASER_SHA256 := 6c0145df61140ec1bffe4048b9ef3e105e18a89734816e7a64f342d3f9267691 -GORELEASER_BIN ?= bin/goreleaser - # Determine packages by looking into pkg/* ifneq ("$(wildcard ${SRCDIR}/pkg/*)","") PACKAGES = $(wildcard ${SRCDIR}/pkg/*) @@ -34,30 +30,18 @@ BINS=$(foreach cmd,${COMMANDS},$(notdir ${cmd})) all: build # Humans running make: -build: check-version clean lint test-unit coverage compile document +build: check-version clean deps lint test-unit compile document # Build command for CI tooling -build-ci: check-version clean lint test-integration +build-ci: check-version clean deps lint test-coverage clean: @echo "=== $(PROJECT_NAME) === [ clean ]: removing binaries and coverage file..." - @rm -rfv $(BUILD_DIR)/* $(COVERAGE_DIR)/* + @rm -rfv $(BUILD_DIR)/* $(COVERAGE_FILE) bin: @mkdir -p $(BUILD_DIR) -$(GORELEASER_BIN): bin - @echo "=== $(PROJECT_NAME) === [ release/deps ]: Installing goreleaser" - @(wget -qO /tmp/goreleaser.tar.gz https://github.com/goreleaser/goreleaser/releases/download/$(GORELEASER_VERSION)/goreleaser_$(GOOS)_x86_64.tar.gz) - @(tar -xf /tmp/goreleaser.tar.gz -C bin/) - @(rm -f /tmp/goreleaser.tar.gz) - -release/deps: $(GORELEASER_BIN) - -release: clean release/deps compile-only - @echo "=== $(PROJECT_NAME) === [ release ]: Releasing new version..." - @$(GORELEASER_BIN) release - # Import fragments include build/deps.mk include build/compile.mk @@ -66,5 +50,7 @@ include build/testing.mk include build/util.mk include build/document.mk include build/docker.mk +include build/ci.mk +include build/release.mk .PHONY: all build build-ci diff --git a/README.md b/README.md index 54c483bd..69886be8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ [![Community Plus header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Community_Plus.png)](https://opensource.newrelic.com/oss-category/#community-plus) -[![Build Status](https://travis-ci.org/newrelic/nri-flex.svg?branch=master)](https://travis-ci.org/newrelic/nri-flex) +![Build Status](https://github.com/newrelic/nri-flex/actions/workflows/push_pr.yml/badge.svg) +[![Coverage Status](https://coveralls.io/repos/github/newrelic/nri-flex/badge.svg?branch=master)](https://coveralls.io/github/newrelic/nri-flex?branch=master) # New Relic Flex diff --git a/build/Dockerfile b/build/Dockerfile new file mode 100644 index 00000000..0c202b3c --- /dev/null +++ b/build/Dockerfile @@ -0,0 +1,12 @@ +ARG GO_VERSION=1.15 + +FROM golang:$GO_VERSION + +WORKDIR /app + +COPY build /app/build +COPY tools /app/tools + +COPY go.mod go.sum Makefile /app/ + +RUN make deps diff --git a/build/ci.mk b/build/ci.mk new file mode 100644 index 00000000..42df0dc7 --- /dev/null +++ b/build/ci.mk @@ -0,0 +1,53 @@ +CI_BUILDER_TAG ?= nri-$(INTEGRATION)-builder + +.PHONY : ci/deps +ci/deps: + @docker build \ + -t $(CI_BUILDER_TAG) \ + --build-arg GO_VERSION=$(GO_VERSION) \ + -f $(CURDIR)/build/Dockerfile $(CURDIR) + +.PHONY : ci/snyk-test +ci/snyk-test: + @docker run --rm -t \ + --name "nri-$(INTEGRATION)-snyk-test" \ + -v $(CURDIR):/go/src/github.com/newrelic/nri-$(INTEGRATION) \ + -w /go/src/github.com/newrelic/nri-$(INTEGRATION) \ + -e SNYK_TOKEN \ + snyk/snyk:golang snyk test --severity-threshold=high + +.PHONY : ci/pre-release +ci/pre-release: ci/deps + @docker run --rm -t \ + --name "nri-$(INTEGRATION)-release" \ + -v $(CURDIR):/go/src/github.com/newrelic/nri-$(INTEGRATION) \ + -w /go/src/github.com/newrelic/nri-$(INTEGRATION) \ + -e IS_RELEASE \ + -e GITHUB_TOKEN \ + -e TAG \ + $(CI_BUILDER_TAG) \ + make release + +.PHONY : ci/test +ci/test: ci/deps + @docker run --rm -t \ + --name "nri-$(INTEGRATION)-release" \ + -v $(CURDIR):/go/src/github.com/newrelic/nri-$(INTEGRATION) \ + -w /go/src/github.com/newrelic/nri-$(INTEGRATION) \ + -e IS_RELEASE \ + -e GITHUB_TOKEN \ + -e TAG \ + $(CI_BUILDER_TAG) \ + make build-ci + +.PHONY : ci/convert-coverage +ci/convert-coverage: ci/deps + @docker run --rm -t \ + --name "nri-$(INTEGRATION)-release" \ + -v $(CURDIR):/go/src/github.com/newrelic/nri-$(INTEGRATION) \ + -w /go/src/github.com/newrelic/nri-$(INTEGRATION) \ + -e IS_RELEASE \ + -e GITHUB_TOKEN \ + -e TAG \ + $(CI_BUILDER_TAG) \ + make convert-coverage diff --git a/build/deps.mk b/build/deps.mk index f516a2ac..ddb87c68 100644 --- a/build/deps.mk +++ b/build/deps.mk @@ -11,6 +11,7 @@ GOTOOLS ?= GOTOOLS += github.com/axw/gocov/gocov GOTOOLS += github.com/AlekSi/gocov-xml GOTOOLS += github.com/robertkrimen/godocdown/godocdown +GOTOOLS += github.com/jandelgado/gcov2lcov VENDOR_CMD = $(GO_CMD) mod vendor diff --git a/.goreleaser.yml b/build/goreleaser.yml similarity index 64% rename from .goreleaser.yml rename to build/goreleaser.yml index 55f77af4..b62a7da3 100644 --- a/.goreleaser.yml +++ b/build/goreleaser.yml @@ -6,35 +6,28 @@ builds: ldflags: - -s -w -X github.com/newrelic/nri-flex/internal/load.IntegrationVersion={{.Version}} goos: - - linux - - darwin - - windows + - linux + - darwin + - windows goarch: - - 386 - - amd64 - - arm - - arm64 - ignore: - - goos: darwin - goarch: 386 + - 386 + - amd64 + - arm + - arm64 archives: - - replacements: - darwin: Darwin - linux: Linux - windows: Windows - amd64: x86_64 - files: + - files: - LICENSE - README.md - CHANGELOG.md - examples/* + name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Version }}_{{ .Arch }}" # Used to change `armv6` to `arm` format_overrides: - goos: windows format: zip checksum: name_template: 'checksums.txt' snapshot: - name_template: "{{ .Tag }}" + name_template: "{{ .Version }}-snapshot" changelog: sort: asc filters: diff --git a/build/release.mk b/build/release.mk new file mode 100644 index 00000000..353fab3a --- /dev/null +++ b/build/release.mk @@ -0,0 +1,24 @@ +GORELEASER_VERSION ?= v0.157.0 +GORELEASER_BIN ?= $(CURDIR)/bin/goreleaser +GORELEASER_CONFIG ?= --config $(CURDIR)/build/goreleaser.yml +PKG_FLAGS ?= --rm-dist +IS_RELEASE ?= false # Default to safe mode which is pre-release + +ifneq ($(IS_RELEASE), true) + PKG_FLAGS += --snapshot +endif + +$(GORELEASER_BIN): bin + @echo "=== $(PROJECT_NAME) === [ release/deps ]: Installing goreleaser" + @(wget -qO /tmp/goreleaser.tar.gz https://github.com/goreleaser/goreleaser/releases/download/$(GORELEASER_VERSION)/goreleaser_$(GOOS)_x86_64.tar.gz) + @(tar -xf /tmp/goreleaser.tar.gz -C $(CURDIR)/bin/) + @(rm -f /tmp/goreleaser.tar.gz) + @echo "=== [$(GORELEASER_BIN)] goreleaser downloaded" + +.PHONY : release/deps +release/deps: $(GORELEASER_BIN) + +.PHONY : release +release: clean release/deps compile-only + @echo "=== $(PROJECT_NAME) === [ release ]: Releasing new version..." + $(GORELEASER_BIN) release $(GORELEASER_CONFIG) $(PKG_FLAGS) diff --git a/build/testing.mk b/build/testing.mk index e1da47e3..9be7b159 100644 --- a/build/testing.mk +++ b/build/testing.mk @@ -3,6 +3,13 @@ # GOLINTER_BIN = bin/$(GOLINTER) +TEST_PATTERN ?=. +TEST_OPTIONS ?= + +TEST_FLAGS += -failfast +TEST_FLAGS += -race + +GO_TEST ?= test $(TEST_OPTIONS) $(TEST_FLAGS) ./... -run $(TEST_PATTERN) -timeout=10m $(GOLINTER_BIN): bin @echo "=== $(PROJECT_NAME) === [ lint ]: Installing $(GOLINTER)..." @@ -22,30 +29,25 @@ test-only: test-unit .PHONY: test-unit test-unit: @echo "=== $(PROJECT_NAME) === [ unit-test ]: running unit tests..." - @mkdir -p $(COVERAGE_DIR) - @$(GO_CMD) test -tags unit -covermode=$(COVERMODE) -coverprofile $(COVERAGE_DIR)/unit.tmp $(GO_PKGS) + @$(GO_CMD) $(GO_TEST) + +.PHONY : test-coverage +test-coverage: TEST_FLAGS += -covermode=atomic -coverprofile=$(COVERAGE_FILE) +test-coverage: + @echo "=== $(PROJECT_NAME) === [ test-coverage ]: running unit tests with coverage..." + @$(GO_CMD) $(GO_TEST) + +.PHONY : convert-coverage +convert-coverage: + @(gcov2lcov -infile=$(COVERAGE_FILE) -outfile=lcov.info) .PHONY: test-integration -test-integration: setup test +test-integration: setup @echo "=== $(PROJECT_NAME) === [ integration-test ]: running integration tests..." - @mkdir -p $(COVERAGE_DIR) @sh ./integration-test/ci-test.sh -.PHONY: cover-report -cover-report: - @echo "=== $(PROJECT_NAME) === [ cover-report ]: generating coverage results..." - @mkdir -p $(COVERAGE_DIR) - @echo 'mode: $(COVERMODE)' > $(COVERAGE_DIR)/coverage.out - @cat $(COVERAGE_DIR)/*.tmp | grep -v 'mode: $(COVERMODE)' >> $(COVERAGE_DIR)/coverage.out || true - @$(GO_CMD) tool cover -html=$(COVERAGE_DIR)/coverage.out -o $(COVERAGE_DIR)/coverage.html - @echo "=== $(PROJECT_NAME) === [ cover-report ]: $(COVERAGE_DIR)coverage.html" - -.PHONY: cover-view -cover-view: cover-report - @$(GO_CMD) tool cover -html=$(COVERAGE_DIR)/coverage.out - .PHONY : test-linux test-linux: @(echo "=== $(PROJECT_NAME) === [ unit-test-linux ]: running unit tests for Linux...") @(docker build -t nri-flex-test -f ./integration-test/Dockerfile .) - @(docker run --rm -it nri-flex-test go test ./...) + @(docker run --rm -it nri-flex-test make test-unit) diff --git a/integration-test/Dockerfile b/integration-test/Dockerfile index 8c3a9b9e..db333109 100644 --- a/integration-test/Dockerfile +++ b/integration-test/Dockerfile @@ -6,7 +6,6 @@ WORKDIR /app COPY go.mod go.sum /app/ -RUN go mod download +RUN go mod vendor COPY . . - diff --git a/tools/go.mod b/tools/go.mod index c5c2bbb2..25987b99 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -5,5 +5,6 @@ go 1.13 require ( github.com/AlekSi/gocov-xml v0.0.0-20190121064608-3a14fb1c4737 github.com/axw/gocov v1.0.0 + github.com/jandelgado/gcov2lcov v1.0.4 github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481 ) diff --git a/tools/go.sum b/tools/go.sum index 0f2bb0b5..6734af6c 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -2,8 +2,17 @@ github.com/AlekSi/gocov-xml v0.0.0-20190121064608-3a14fb1c4737 h1:JZHBkt0GhM+ARQ github.com/AlekSi/gocov-xml v0.0.0-20190121064608-3a14fb1c4737/go.mod h1:w1KSuh2JgIL3nyRiZijboSUwbbxOrTzWwyWVFUHtXBQ= github.com/axw/gocov v1.0.0 h1:YsqYR66hUmilVr23tu8USgnJIJvnwh3n7j5zRn7x4LU= github.com/axw/gocov v1.0.0/go.mod h1:LvQpEYiwwIb2nYkXY2fDWhg9/AsYqkhmrCshjlUJECE= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/jandelgado/gcov2lcov v1.0.4 h1:ADwQPyNsxguqzznIbfQTENwY9FU88JdXEvpdHR9c48A= +github.com/jandelgado/gcov2lcov v1.0.4/go.mod h1:NnSxK6TMlg1oGDBfGelGbjgorT5/L3cchlbtgFYZSss= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481 h1:jMxcLa+VjJKhpCwbLUXAD15wJ+hhvXMLujCl3MkXpfM= github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481/go.mod h1:C9WhFzY47SzYBIvzFqSvHIR6ROgDo4TtdTuRaOMjF/s= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -11,3 +20,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20190617190820-da514acc4774 h1:CQVOmarCBFzTx0kbOU0ru54Cvot8SdSrNYjZPhQl+gk= golang.org/x/tools v0.0.0-20190617190820-da514acc4774/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/tools/tools.go b/tools/tools.go index 24e4444d..790b7335 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -5,5 +5,6 @@ package tools import ( _ "github.com/AlekSi/gocov-xml" _ "github.com/axw/gocov/gocov" + _ "github.com/jandelgado/gcov2lcov" _ "github.com/robertkrimen/godocdown/godocdown" )