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

Adds support for GitHub action ENV variables #21

Merged
merged 14 commits into from
Dec 21, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import com.bmuschko.gradle.docker.DockerExtension;
import com.bmuschko.gradle.docker.DockerRemoteApiPlugin;
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage;

import java.util.Arrays;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unused imports

import java.util.Optional;
import java.util.Set;
import java.util.List;
import java.util.stream.Collectors;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
Expand Down Expand Up @@ -109,13 +112,16 @@ private boolean isReleaseVersion(Project project) {
}

private String getBranchTag() {
// Use the value of CIRCLE_BRANCH environment variable if defined (that is, the branch name used
// to build in CI), otherwise for local builds use 'test'
return getEnvironmentVariable("CIRCLE_BRANCH")
.map(String::trim)
.map(branch -> branch.replaceAll("[^A-Za-z0-9\\.\\_\\-]", ""))
.filter(branch -> !branch.isEmpty())
.orElse("test");
// Use the value of CIRCLE_BRANCH/ GITHUB_REF environment variable if defined (that is, the branch name used
// to build in CI), otherwise for local builds use 'test'
return getEnvironmentVariable("CIRCLE_BRANCH")
.or(()-> getEnvironmentVariable("GITHUB_REF"))
// Extracting BRANCH_NAME from GITHUB_REF environment variable which is normally in `refs/heads/{BRANCH_NAME} format.
.map(branch -> branch.replaceAll("refs\\/heads\\/", ""))
.map(String::trim)
.map(branch -> branch.replaceAll("[^A-Za-z0-9\\.\\_\\-]", ""))
.filter(branch -> !branch.isEmpty())
.orElse("test");
}

private Optional<String> tryGetBuildSha() {
Expand Down