From 06871f92f59556b9cb4f895b1155450968824a66 Mon Sep 17 00:00:00 2001 From: Agam More Date: Thu, 12 Nov 2020 19:27:31 +0200 Subject: [PATCH 1/9] Add gitlab support --- README.md | 14 ++++++++++++++ gitinfo.go | 1 + gitinfo_test.go | 10 ++++++++++ goveralls.go | 4 ++++ 4 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 29c03fd..65803da 100644 --- a/README.md +++ b/README.md @@ -303,6 +303,20 @@ default value for `-repotoken`. You can use the `-v` flag to see verbose output. + +## Gitlab CI + +Store your Coveralls API token as an [Environment Variable](https://docs.gitlab.com/ee/ci/variables/#create-a-custom-variable-in-the-ui). + +``` +COVERALLS_TOKEN=your_token_goes_here +``` + +``` +$ go get github.com/mattn/goveralls +$ goveralls -service=gitlab -repotoken=$COVERALLS_TOKEN +``` + ## Coveralls Enterprise If you are using Coveralls Enterprise and have a self-signed certificate, you need to skip certificate verification: diff --git a/gitinfo.go b/gitinfo.go index d3c5a22..31360a5 100644 --- a/gitinfo.go +++ b/gitinfo.go @@ -136,6 +136,7 @@ var varNames = [...]string{ "CI_BRANCH", "APPVEYOR_REPO_BRANCH", "WERCKER_GIT_BRANCH", "DRONE_BRANCH", "BUILDKITE_BRANCH", "BRANCH_NAME", + "CI_COMMIT_REF_NAME", } func loadBranchFromEnv() string { diff --git a/gitinfo_test.go b/gitinfo_test.go index 252fda4..12a9093 100644 --- a/gitinfo_test.go +++ b/gitinfo_test.go @@ -25,6 +25,7 @@ func TestLoadBranchFromEnv(t *testing.T) { "DRONE_BRANCH": "drone-master", "BUILDKITE_BRANCH": "buildkite-master", "BRANCH_NAME": "jenkins-master", + "CI_COMMIT_REF_NAME": "gitlab-master", }, "master", }, @@ -39,6 +40,7 @@ func TestLoadBranchFromEnv(t *testing.T) { "DRONE_BRANCH": "drone-master", "BUILDKITE_BRANCH": "buildkite-master", "BRANCH_NAME": "jenkins-master", + "CI_COMMIT_REF_NAME": "gitlab-master", }, "circle-master", }, @@ -52,6 +54,7 @@ func TestLoadBranchFromEnv(t *testing.T) { "DRONE_BRANCH": "drone-master", "BUILDKITE_BRANCH": "buildkite-master", "BRANCH_NAME": "jenkins-master", + "CI_COMMIT_REF_NAME": "gitlab-master", }, "travis-master", }, @@ -97,6 +100,13 @@ func TestLoadBranchFromEnv(t *testing.T) { }, "drone-master", }, + { + "only CI_COMMIT_REF_NAME defined", + map[string]string{ + "CI_COMMIT_REF_NAME": "gitlab-master", + }, + "gitlab-master", + }, { "GitHub Action push event", map[string]string{ diff --git a/goveralls.go b/goveralls.go index 20b0135..c73fb33 100644 --- a/goveralls.go +++ b/goveralls.go @@ -354,6 +354,8 @@ func process() error { jobID = codeshipjobID } else if githubRunID := os.Getenv("GITHUB_RUN_ID"); githubRunID != "" { jobID = githubRunID + } else if gitlabRunID := os.Getenv("CI_PIPELINE_ID"); gitlabRunID != "" { + jobID = gitlabRunID } if *repotoken == "" && *repotokenfile != "" { @@ -407,6 +409,8 @@ func process() error { ghPR := githubEvent["pull_request"].(map[string]interface{}) ghHead := ghPR["head"].(map[string]interface{}) head = ghHead["sha"].(string) + } else if prNumber := os.Getenv("CI_EXTERNAL_PULL_REQUEST_IID"); prNumber != "" { + pullRequest = prNumber } if *service == "" && os.Getenv("TRAVIS_JOB_ID") != "" { From 64f29b1289ae7ff7389c49958e355e44b3cbf112 Mon Sep 17 00:00:00 2001 From: Agam More Date: Sun, 15 Nov 2020 06:21:43 +0200 Subject: [PATCH 2/9] Temp fix gomod --- go.mod | 2 ++ 1 file changed, 2 insertions(+) diff --git a/go.mod b/go.mod index d537042..cdbb29f 100644 --- a/go.mod +++ b/go.mod @@ -3,3 +3,5 @@ module github.com/mattn/goveralls go 1.11 require golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375 +replace github.com/mattn/goveralls => github.com/agamm/goveralls + From f233d1dd4047ca74af9a75733eb84fb02dd75b6c Mon Sep 17 00:00:00 2001 From: Agam More Date: Sun, 15 Nov 2020 06:33:30 +0200 Subject: [PATCH 3/9] Revert replace --- go.mod | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.mod b/go.mod index cdbb29f..d537042 100644 --- a/go.mod +++ b/go.mod @@ -3,5 +3,3 @@ module github.com/mattn/goveralls go 1.11 require golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375 -replace github.com/mattn/goveralls => github.com/agamm/goveralls - From 6939c6c2b70cc50741166a2c154a3e2cadfa0af6 Mon Sep 17 00:00:00 2001 From: Agam More Date: Sun, 15 Nov 2020 15:11:55 +0200 Subject: [PATCH 4/9] Replace example for gitlab --- README.md | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 65803da..7633b06 100644 --- a/README.md +++ b/README.md @@ -308,13 +308,21 @@ You can use the `-v` flag to see verbose output. Store your Coveralls API token as an [Environment Variable](https://docs.gitlab.com/ee/ci/variables/#create-a-custom-variable-in-the-ui). -``` -COVERALLS_TOKEN=your_token_goes_here -``` -``` -$ go get github.com/mattn/goveralls -$ goveralls -service=gitlab -repotoken=$COVERALLS_TOKEN +```yml +publish:coverage: + timeout: 30m + stage: publish + artifacts: + paths: + - covprofile + dependencies: + - build:env + when: always + script: + - go test -covermode atomic -coverprofile=covprofile ./... + - go get github.com/mattn/goveralls + - goveralls -service=gitlab -coverprofile=covprofile ``` ## Coveralls Enterprise From f299bb99870cc0792fb94867ae12a0784bcb7898 Mon Sep 17 00:00:00 2001 From: Agam Date: Sun, 15 Nov 2020 15:13:16 +0200 Subject: [PATCH 5/9] Update goveralls.go Co-authored-by: gdm85 --- goveralls.go | 1 + 1 file changed, 1 insertion(+) diff --git a/goveralls.go b/goveralls.go index c73fb33..71297ea 100644 --- a/goveralls.go +++ b/goveralls.go @@ -410,6 +410,7 @@ func process() error { ghHead := ghPR["head"].(map[string]interface{}) head = ghHead["sha"].(string) } else if prNumber := os.Getenv("CI_EXTERNAL_PULL_REQUEST_IID"); prNumber != "" { + // pull request id from GitHub when building on GitLab pullRequest = prNumber } From 66cdca9daef86f1f33e3f3ed560b5b12aedd5fd6 Mon Sep 17 00:00:00 2001 From: Agam More Date: Sun, 15 Nov 2020 15:18:46 +0200 Subject: [PATCH 6/9] Add CI_MERGE_REQUEST_ID to pr number --- goveralls.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/goveralls.go b/goveralls.go index c73fb33..f57ce2c 100644 --- a/goveralls.go +++ b/goveralls.go @@ -411,6 +411,8 @@ func process() error { head = ghHead["sha"].(string) } else if prNumber := os.Getenv("CI_EXTERNAL_PULL_REQUEST_IID"); prNumber != "" { pullRequest = prNumber + } else if prNumber := os.Getenv("CI_MERGE_REQUEST_ID"); prNumber != "" { + pullRequest = prNumber } if *service == "" && os.Getenv("TRAVIS_JOB_ID") != "" { From 746cab2bd4a401bed3c84fc79a93af03921a6c8e Mon Sep 17 00:00:00 2001 From: Agam Date: Sun, 15 Nov 2020 18:52:11 +0200 Subject: [PATCH 7/9] Update README.md Co-authored-by: gdm85 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7633b06..527ce65 100644 --- a/README.md +++ b/README.md @@ -315,7 +315,7 @@ publish:coverage: stage: publish artifacts: paths: - - covprofile + - coverage.txt dependencies: - build:env when: always From 35efbf5796019af4f6313732cfce26faef23dcd3 Mon Sep 17 00:00:00 2001 From: Agam Date: Sun, 15 Nov 2020 18:52:57 +0200 Subject: [PATCH 8/9] Apply suggestions from code review Co-authored-by: gdm85 --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 527ce65..4769cc5 100644 --- a/README.md +++ b/README.md @@ -308,7 +308,6 @@ You can use the `-v` flag to see verbose output. Store your Coveralls API token as an [Environment Variable](https://docs.gitlab.com/ee/ci/variables/#create-a-custom-variable-in-the-ui). - ```yml publish:coverage: timeout: 30m @@ -320,9 +319,9 @@ publish:coverage: - build:env when: always script: - - go test -covermode atomic -coverprofile=covprofile ./... + - go test -covermode atomic -coverprofile=coverage.txt ./... - go get github.com/mattn/goveralls - - goveralls -service=gitlab -coverprofile=covprofile + - goveralls -service=gitlab -coverprofile=coverage.txt ``` ## Coveralls Enterprise From b4f0357bb26e0f1dec720907ca1f075feecdb258 Mon Sep 17 00:00:00 2001 From: Agam More Date: Thu, 19 Nov 2020 12:26:40 +0200 Subject: [PATCH 9/9] CR changes --- README.md | 8 +++----- goveralls.go | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7633b06..a8b71b2 100644 --- a/README.md +++ b/README.md @@ -306,18 +306,16 @@ You can use the `-v` flag to see verbose output. ## Gitlab CI -Store your Coveralls API token as an [Environment Variable](https://docs.gitlab.com/ee/ci/variables/#create-a-custom-variable-in-the-ui). +Store your Coveralls API token as an [Environment Variable](https://docs.gitlab.com/ee/ci/variables/#create-a-custom-variable-in-the-ui) named `COVERALLS_TOKEN`. ```yml -publish:coverage: +test: timeout: 30m - stage: publish + stage: test artifacts: paths: - covprofile - dependencies: - - build:env when: always script: - go test -covermode atomic -coverprofile=covprofile ./... diff --git a/goveralls.go b/goveralls.go index 6e4378a..a9a6374 100644 --- a/goveralls.go +++ b/goveralls.go @@ -409,10 +409,10 @@ func process() error { ghPR := githubEvent["pull_request"].(map[string]interface{}) ghHead := ghPR["head"].(map[string]interface{}) head = ghHead["sha"].(string) - } else if prNumber := os.Getenv("CI_EXTERNAL_PULL_REQUEST_IID"); prNumber != "" { + } else if prNumber := os.Getenv("CI_MERGE_REQUEST_IID"); prNumber != "" { // pull request id from GitHub when building on GitLab pullRequest = prNumber - } else if prNumber := os.Getenv("CI_MERGE_REQUEST_ID"); prNumber != "" { + } else if prNumber := os.Getenv("CI_EXTERNAL_PULL_REQUEST_IID"); prNumber != "" { pullRequest = prNumber }