From a3876ded220596d39a6d983f70fbf4516c5921bf Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Thu, 23 Jan 2020 23:28:22 -0500 Subject: [PATCH 01/12] ci: test circleci ref #158 Signed-off-by: Artur Troian --- .circleci/config.yml | 114 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..1a78c49 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,114 @@ +version: 2 +docker_job_setup: &docker_job + docker: + - image: circleci/golang:1.13.6 + working_directory: /go/src/github.com/VolantMQ/volantmq + +attach_workspace: &workspace + attach_workspace: + at: /go/src/github.com/VolantMQ/volantmq + +jobs: + pull-sources: + <<: *docker_job + steps: + - checkout + - run: + name: go mod tidy + command: go mod tidy + - persist_to_workspace: + root: /go/src/github.com/VolantMQ + paths: + - volantmq + lint: + <<: *docker_job + steps: + - run: + name: Install golangci-lint + command: | + go get -u github.com/golangci/golangci-lint/cmd/golangci-lint + - run: + name: lint + command: | + golangci-lint run + test: + <<: *docker_job + steps: + - <<: *workspace + - run: + name: Setup Code Climate test-reporter + command: | + # download test reporter as a static binary + mkdir -p /tmp/codeclimate + curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > /tmp/codeclimate/cc-test-reporter + chmod +x /tmp/codeclimate/cc-test-reporter + - run: + name: Tests + command: | + /tmp/codeclimate/cc-test-reporter before-build + ./go.test.sh + /tmp/codeclimate/cc-test-reporter --coverage-input-type coverage --exit-code $? + test-build-docker: + <<: *docker_job + steps: + - <<: *workspace + - run: + name: Docker build + command: | + ./dockerBuildLocal.sh + build-docker: + <<: *docker_job + steps: + - <<: *workspace + - run: + name: Docker build + command: | + ./dockerBuildLocal.sh volantmq/volantmq:${CIRCLE_TAG} + docker login -u \$DOCKER_USERNAME -p \$DOCKER_PASSWORD + docker push volantmq/volantmq:${CIRCLE_TAG} + +workflows: + version: 2 + test-on-commit: + jobs: + - pull-sources: + filters: + tags: + ignore: /.*/ + - test: + requires: + - pull-sources + filters: + tags: + ignore: /.*/ + - test-build-docker: + requires: + - test + filters: + tags: + ignore: /.*/ + release: + jobs: + - pull-source: + filters: + tags: + only: /^[vV]?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/ + branches: + ignore: /.*/ + - test: + requires: + - pull-source + filters: + tags: + only: /^[vV]?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/ + branches: + ignore: /.*/ + - build-docker: + context: volantmq + requires: + - test + filters: + tags: + only: /^[vV]?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/ + branches: + ignore: /.*/ From c16f6ce981a18692e81df0919aec623d6fbb01f4 Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Thu, 23 Jan 2020 23:50:58 -0500 Subject: [PATCH 02/12] ci: lint step attach workspace Signed-off-by: Artur Troian --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1a78c49..d2e87b5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,6 +23,7 @@ jobs: lint: <<: *docker_job steps: + - <<: *workspace - run: name: Install golangci-lint command: | @@ -43,6 +44,7 @@ jobs: curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > /tmp/codeclimate/cc-test-reporter chmod +x /tmp/codeclimate/cc-test-reporter - run: + shell: /bin/bash name: Tests command: | /tmp/codeclimate/cc-test-reporter before-build From 24a5364cb14d2c570fe826496049bbcd29cb72cf Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Thu, 23 Jan 2020 23:57:10 -0500 Subject: [PATCH 03/12] ci: enable lint step Signed-off-by: Artur Troian --- .circleci/config.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d2e87b5..9bea378 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -77,12 +77,18 @@ workflows: filters: tags: ignore: /.*/ - - test: + - lint: requires: - pull-sources filters: tags: ignore: /.*/ + - test: + requires: + - lint + filters: + tags: + ignore: /.*/ - test-build-docker: requires: - test From 3991210d5cd688b3f475ca3af286660ab6e2c5cb Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Fri, 24 Jan 2020 10:11:37 -0500 Subject: [PATCH 04/12] ci: remove last token from attach_workspace Signed-off-by: Artur Troian --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9bea378..fd32c47 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,7 @@ docker_job_setup: &docker_job attach_workspace: &workspace attach_workspace: - at: /go/src/github.com/VolantMQ/volantmq + at: /go/src/github.com/VolantMQ jobs: pull-sources: From 1464502fabb423ce5a7a781c50c880582fa27f4c Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Fri, 24 Jan 2020 10:40:06 -0500 Subject: [PATCH 05/12] ci: add after-build command to test reporter Signed-off-by: Artur Troian --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fd32c47..1e0a018 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -49,7 +49,7 @@ jobs: command: | /tmp/codeclimate/cc-test-reporter before-build ./go.test.sh - /tmp/codeclimate/cc-test-reporter --coverage-input-type coverage --exit-code $? + /tmp/codeclimate/cc-test-reporter after-build --exit-code $? test-build-docker: <<: *docker_job steps: From 8443a14a6efe3982f9b73a3d07e58cb6cbe3f9cb Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Fri, 24 Jan 2020 10:46:08 -0500 Subject: [PATCH 06/12] test: rename output file to coverage.out Signed-off-by: Artur Troian --- go.test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.test.sh b/go.test.sh index 6be26e3..de9e27d 100755 --- a/go.test.sh +++ b/go.test.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash set -e -echo "" > coverage.txt +echo "" > coverage.out for d in $(go list ./... | grep -v vendor); do go test -race -coverprofile=profile.out -covermode=atomic ${d} if [[ -f profile.out ]]; then - cat profile.out >> coverage.txt + cat profile.out >> coverage.out rm profile.out fi done From df9a2dbf1b07b39b3fcec9c911ac199f521c858f Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Fri, 24 Jan 2020 10:52:10 -0500 Subject: [PATCH 07/12] test: rename go.test to go.test.codeclimate Refactor way of gathering output from package list Signed-off-by: Artur Troian --- go.test.codeclimate.sh | 11 +++++++++++ go.test.sh | 12 ------------ 2 files changed, 11 insertions(+), 12 deletions(-) create mode 100755 go.test.codeclimate.sh delete mode 100755 go.test.sh diff --git a/go.test.codeclimate.sh b/go.test.codeclimate.sh new file mode 100755 index 0000000..31917eb --- /dev/null +++ b/go.test.codeclimate.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e + +for pkg in $(go list ./... | grep -v main); do + go test -coverprofile=$(echo ${pkg} | tr / -).cover ${pkg} +done + +echo "mode: set" > c.out +grep -h -v "^mode:" ./*.cover >> c.out +rm -f *.cover diff --git a/go.test.sh b/go.test.sh deleted file mode 100755 index de9e27d..0000000 --- a/go.test.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -set -e -echo "" > coverage.out - -for d in $(go list ./... | grep -v vendor); do - go test -race -coverprofile=profile.out -covermode=atomic ${d} - if [[ -f profile.out ]]; then - cat profile.out >> coverage.out - rm profile.out - fi -done From 1ec2da001f520d94d324f83fa5c11ff4ec2b95c1 Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Fri, 24 Jan 2020 10:54:20 -0500 Subject: [PATCH 08/12] ci: apply new name of test script Signed-off-by: Artur Troian --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1e0a018..0d3b346 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -48,7 +48,7 @@ jobs: name: Tests command: | /tmp/codeclimate/cc-test-reporter before-build - ./go.test.sh + ./go.test.codeclimate.sh /tmp/codeclimate/cc-test-reporter after-build --exit-code $? test-build-docker: <<: *docker_job From bf156819af440582f89e4b0cb52b97db506c0720 Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Fri, 24 Jan 2020 11:07:27 -0500 Subject: [PATCH 09/12] ci: debug info for tests Signed-off-by: Artur Troian --- go.test.codeclimate.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/go.test.codeclimate.sh b/go.test.codeclimate.sh index 31917eb..47a3b6c 100755 --- a/go.test.codeclimate.sh +++ b/go.test.codeclimate.sh @@ -2,6 +2,8 @@ set -e +echo "starting tests" + for pkg in $(go list ./... | grep -v main); do go test -coverprofile=$(echo ${pkg} | tr / -).cover ${pkg} done @@ -9,3 +11,5 @@ done echo "mode: set" > c.out grep -h -v "^mode:" ./*.cover >> c.out rm -f *.cover + +echo "tests finished" From 367db8761941e845d845e49ce450f53043d6ba9e Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Fri, 24 Jan 2020 11:18:28 -0500 Subject: [PATCH 10/12] ci: use codecov Signed-off-by: Artur Troian --- .circleci/config.yml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0d3b346..4607c97 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,6 +8,9 @@ attach_workspace: &workspace attach_workspace: at: /go/src/github.com/VolantMQ +orbs: + codecov: codecov/codecov@1.0.5 + jobs: pull-sources: <<: *docker_job @@ -36,20 +39,13 @@ jobs: <<: *docker_job steps: - <<: *workspace - - run: - name: Setup Code Climate test-reporter - command: | - # download test reporter as a static binary - mkdir -p /tmp/codeclimate - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > /tmp/codeclimate/cc-test-reporter - chmod +x /tmp/codeclimate/cc-test-reporter - run: shell: /bin/bash name: Tests command: | - /tmp/codeclimate/cc-test-reporter before-build - ./go.test.codeclimate.sh - /tmp/codeclimate/cc-test-reporter after-build --exit-code $? + ./go.test.codecov.sh + - codecov/upload: + file: coverage.txt test-build-docker: <<: *docker_job steps: From c76c2a2338eb433e4d3650cd2e276886cf03f1ac Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Fri, 24 Jan 2020 11:36:54 -0500 Subject: [PATCH 11/12] ci: update version to 2.1 add dedicated script to generate codecov Signed-off-by: Artur Troian --- .circleci/config.yml | 8 ++++---- go.test.codecov.sh | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100755 go.test.codecov.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 4607c97..9957b97 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,4 @@ -version: 2 +version: 2.1 docker_job_setup: &docker_job docker: - image: circleci/golang:1.13.6 @@ -66,7 +66,7 @@ jobs: docker push volantmq/volantmq:${CIRCLE_TAG} workflows: - version: 2 + version: 2.1 test-on-commit: jobs: - pull-sources: @@ -93,7 +93,7 @@ workflows: ignore: /.*/ release: jobs: - - pull-source: + - pull-sources: filters: tags: only: /^[vV]?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/ @@ -101,7 +101,7 @@ workflows: ignore: /.*/ - test: requires: - - pull-source + - pull-sources filters: tags: only: /^[vV]?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/ diff --git a/go.test.codecov.sh b/go.test.codecov.sh new file mode 100755 index 0000000..d6f9a84 --- /dev/null +++ b/go.test.codecov.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -e + +echo "" > coverage.txt + +for d in $(go list ./... | grep -v vendor); do + go test -race -coverprofile=profile.out -covermode=atomic ${d} + if [[ -f profile.out ]]; then + cat profile.out >> coverage.txt + rm profile.out + fi +done From be54ba170113d75be91e1ce6c24be74caf811547 Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Fri, 24 Jan 2020 12:07:19 -0500 Subject: [PATCH 12/12] ci: try github actions Signed-off-by: Artur Troian --- .github/workflows/build.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8796552 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,22 @@ +on: [push, pull_request] +name: Validate +strategy: + matrix: + go-version: [1.13.6] + platform: [ubuntu-latest] +runs-on: ${{ matrix.platform }} +with: + go-version: ${{ matrix.go-version }} +jobs: + lint: + steps: + - name: Install Go + uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go-version }} + - name: Checkout code + uses: actions/checkout@v1 + - name: Install golangci-lint + run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.22.2 + - name: lint + run: golangci-lint run