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
Merged

Conversation

JBAhire
Copy link
Member

@JBAhire JBAhire commented Dec 21, 2020

This PR,

  • adds support for tag on the basis of GitHub Branch
  • adds support for GitHub SHA variable.

@JBAhire JBAhire requested a review from a team as a code owner December 21, 2020 13:48
.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"))

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?

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?

Copy link
Contributor

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.

Copy link
Member Author

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"))
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

Comment on lines 117 to 125
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"));
Copy link
Contributor

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):

Suggested change
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"));

JBAhire and others added 3 commits December 21, 2020 21:23
…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;
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

@aaron-steinfeld aaron-steinfeld merged commit 58901a8 into main Dec 21, 2020
@aaron-steinfeld aaron-steinfeld deleted the adds-gha branch December 21, 2020 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants