Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always override existing environment variables with the prefix OCTOCOV_ #282

Merged
merged 2 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,13 @@ octocov detect pull request number following order.
2. Get pull request number from [`GITHUB_REF`](https://docs.github.com/en/actions/learn-github-actions/variables) ( e.g. `refs/pull/1/merge` ).
3. Get branch name from [`GITHUB_REF`](https://docs.github.com/en/actions/learn-github-actions/variables) ( e.g. `refs/heads/branch/branch/name` ) and detect pull request number using GitHub API.

### Override environment variables

If an environment variable with prefix `OCTOCOV_` is set, it is used as an unprefixed environment variable in octocov.

For example, if `OCTOCOV_GITHUB_REF` is set, it is handled as `GITHUB_REF` in octocov.

This feature allows [environment variables that cannot normally be overridden](https://docs.github.com/en/actions/learn-github-actions/variables#naming-conventions-for-environment-variables) to be changed on octocov.

## Install

Expand Down
8 changes: 3 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ func main() {
continue
}
k2 := strings.TrimPrefix(k, envPrefix)
if os.Getenv(k2) == "" {
if err := os.Setenv(k2, v); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err) //nostyle:handlerrors
os.Exit(1)
}
if err := os.Setenv(k2, v); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err) //nostyle:handlerrors
os.Exit(1)
}
}
cmd.Execute()
Expand Down