-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
.map(String::trim) | ||
.map(branch -> branch.replaceAll("[^A-Za-z0-9\\.\\_\\-]", "")) | ||
.filter(branch -> !branch.isEmpty()) | ||
.orElse("test"); | ||
} | ||
|
||
private Optional<String> tryGetBuildSha() { | ||
return getEnvironmentVariable("CIRCLE_SHA1") | ||
return getFirstAvailableEnvironmentVariable(Arrays.asList("CIRCLE_BRANCH", "GHA_BRANCH")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would this be on BRANCH
? I think we need a similar env for GHA?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need GITHUB_SHA
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GITHUB_SHA
is already available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted to previous function
return getEnvironmentVariable("CIRCLE_BRANCH") | ||
// Use the value of CIRCLE_BRANCH/ GHA_BRANCH environment variable if defined (that is, the branch name used | ||
// to build in CI), otherwise for local builds use 'test' | ||
return getFirstAvailableEnvironmentVariable(Arrays.asList("CIRCLE_BRANCH", "GHA_BRANCH")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment on hypertrace/attribute-service#45 (comment) - I think we should keep the plugin using standard variables. Can we move the normalization of the ref format into this code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
return getEnvironmentVariable("CIRCLE_BRANCH") | ||
.map(String::trim) | ||
.map(branch -> branch.replaceAll("[^A-Za-z0-9\\.\\_\\-]", "")) | ||
.filter(branch -> !branch.isEmpty()) | ||
.orElse(getEnvironmentVariable("GITHUB_REF") | ||
.map(String::trim) | ||
.map(branch -> branch.replaceAll("(.*)\\/", "")) | ||
.filter(branch -> !branch.isEmpty()) | ||
.orElse("test")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we do once we get the ref should be the same in either case - trim, normalize, replace special chars to make it a docker-acceptable format. Also, the current regex looks like it would break on branch names including slashes. How about (suggest you test this, since just writing in a browser):
return getEnvironmentVariable("CIRCLE_BRANCH") | |
.map(String::trim) | |
.map(branch -> branch.replaceAll("[^A-Za-z0-9\\.\\_\\-]", "")) | |
.filter(branch -> !branch.isEmpty()) | |
.orElse(getEnvironmentVariable("GITHUB_REF") | |
.map(String::trim) | |
.map(branch -> branch.replaceAll("(.*)\\/", "")) | |
.filter(branch -> !branch.isEmpty()) | |
.orElse("test")); | |
return getEnvironmentVariable("CIRCLE_BRANCH") | |
.or(getEnvironmentVariable("GITHUB_REF")) | |
.map(branch -> branch.replaceAll("refs\\/heads\\/", "")) | |
.map(String::trim) | |
.map(branch -> branch.replaceAll("[^A-Za-z0-9\\.\\_\\-]", "")) | |
.filter(branch -> !branch.isEmpty()) | |
.orElse("test")); |
hypertrace-gradle-docker-plugin/src/main/java/org/hypertrace/gradle/docker/DockerPlugin.java
Outdated
Show resolved
Hide resolved
hypertrace-gradle-docker-plugin/src/main/java/org/hypertrace/gradle/docker/DockerPlugin.java
Outdated
Show resolved
Hide resolved
…radle/docker/DockerPlugin.java Co-authored-by: Aaron Steinfeld <45047841+aaron-steinfeld@users.noreply.github.com>
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: unused imports
This PR,