Skip to content

Commit

Permalink
Support prow
Browse files Browse the repository at this point in the history
Instead of requiring to map the prow env vars to other values, directly
use the env vars defined here:

https://github.com/kubernetes/test-infra/blob/master/prow/jobs.md#job-environment-variables

Add paragraph to README.md explaining the usage.
  • Loading branch information
dhiller committed Aug 28, 2020
1 parent 21feffd commit c00a60a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,42 @@ If you are using Coveralls Enterprise and have a self-signed certificate, you ne
$ goveralls -insecure
```

## Prow

Goveralls can be used in [prow](https://github.com/kubernetes/test-infra/tree/master/prow) presubmit jobs, picking up the prow [environment variables](https://github.com/kubernetes/test-infra/blob/master/prow/jobs.md#job-environment-variables) `PULL_REFS` and `PULL_NUMBER` to determine the branch and PR number automatically.

To avoid leaking your coveralls repo token you can use the `COVERALLS_TOKEN_FILE` env variable, so that a token gets read and used in the api call.

When configuring your prow job you can mount a defined secret containing your token like this:

```yaml
...
- name: coveralls
always_run: true
optional: false
spec:
containers:
- image: gcr.io/k8s-testimages/...
env:
- name: COVERALLS_TOKEN_FILE
value: /etc/secrets/coveralls/token
command:
- "goveralls -service=prow"
volumeMounts:
- name: coveralls
mountPath: /etc/secrets/coveralls
readOnly: true
volumes:
- name: coveralls
secret:
secretName: coveralls-token
...
```

```shell
$ goveralls -service=prow
```

# Authors

* Yasuhiro Matsumoto (a.k.a. mattn)
Expand Down
1 change: 1 addition & 0 deletions gitinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ var varNames = [...]string{
"CI_BRANCH", "APPVEYOR_REPO_BRANCH",
"WERCKER_GIT_BRANCH", "DRONE_BRANCH",
"BUILDKITE_BRANCH", "BRANCH_NAME",
"PULL_REFS",
}

func loadBranchFromEnv() string {
Expand Down
2 changes: 2 additions & 0 deletions goveralls.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ func process() error {
pullRequest = prNumber
} else if prNumber := os.Getenv("CI_PR_NUMBER"); prNumber != "" {
pullRequest = prNumber
} else if prNumber := os.Getenv("PULL_NUMBER"); prNumber != "" {
pullRequest = prNumber
} else if os.Getenv("GITHUB_EVENT_NAME") == "pull_request" {
number := githubEvent["number"].(float64)
pullRequest = strconv.Itoa(int(number))
Expand Down

0 comments on commit c00a60a

Please sign in to comment.