Skip to content

Commit

Permalink
Merge pull request #192 from agamm/add-gitlab-support
Browse files Browse the repository at this point in the history
Add gitlab support
  • Loading branch information
gdm85 authored Dec 1, 2020
2 parents f1c5f0d + 7595826 commit f28e79e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,27 @@ 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) named `COVERALLS_TOKEN`.

```yml
test:
timeout: 30m
stage: test
artifacts:
paths:
- coverage.txt
dependencies:
- build:env
when: always
script:
- go test -covermode atomic -coverprofile=coverage.txt ./...
- go get github.com/mattn/goveralls
- goveralls -service=gitlab -coverprofile=coverage.txt
```
## Coveralls Enterprise
If you are using Coveralls Enterprise and have a self-signed certificate, you need to skip certificate verification:
Expand Down
1 change: 1 addition & 0 deletions gitinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions gitinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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",
},
Expand Down Expand Up @@ -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{
Expand Down
7 changes: 7 additions & 0 deletions goveralls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -407,6 +409,11 @@ 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_MERGE_REQUEST_IID"); prNumber != "" {
// pull request id from GitHub when building on GitLab
pullRequest = prNumber
} else if prNumber := os.Getenv("CI_EXTERNAL_PULL_REQUEST_IID"); prNumber != "" {
pullRequest = prNumber
}

if *service == "" && os.Getenv("TRAVIS_JOB_ID") != "" {
Expand Down

0 comments on commit f28e79e

Please sign in to comment.