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

[deploy_maven] allow for release repo override via command line #350

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion maven/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# under the License.
#

_DEPLOY_MAVEN_RELEASE_REPO_KEY = "DEPLOY_MAVEN_RELEASE_REPO"

def _parse_maven_coordinates(coordinates_string, enforce_version_template=True):
coordinates = coordinates_string.split(':')
Expand Down Expand Up @@ -315,6 +316,10 @@ def _deploy_maven_impl(ctx):
src_jar_link = "lib.srcjar"
pom_xml_link = ctx.attr.target[MavenDeploymentInfo].pom.basename

release_repo = ctx.attr.release
if _DEPLOY_MAVEN_RELEASE_REPO_KEY in ctx.var:
release_repo = ctx.var[_DEPLOY_MAVEN_RELEASE_REPO_KEY]
Comment on lines +319 to +321
Copy link
Member

Choose a reason for hiding this comment

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

I agree with the approach of using --define! This is aligned with how we override the version being deployed:

bazel run --define version=$(cat VERSION) //:deploy-maven -- release

A couple of points:

  1. Since we're allowing users to override the release repo, we should also allow them to override the snapshot repo.
  2. As version is all lowercase, so should be deploy_maven_release_repo; and for terseness, I'd call it just release_repo. (As this is a run target, the key need not be globally unique.)

With all that in mind, and simplifying the Starlark a little:

Suggested change
release_repo = ctx.attr.release
if _DEPLOY_MAVEN_RELEASE_REPO_KEY in ctx.var:
release_repo = ctx.var[_DEPLOY_MAVEN_RELEASE_REPO_KEY]
snapshot_repo = ctx.var.get("snapshot_repo", default=ctx.attr.snapshot)
release_repo = ctx.var.get("release_repo", default=ctx.attr.release)

(requires additional update to L330: "{snapshot}": snapshot_repo,)


ctx.actions.expand_template(
template = ctx.file._deployment_script,
output = deploy_maven_script,
Expand All @@ -323,7 +328,7 @@ def _deploy_maven_impl(ctx):
"$SRCJAR_PATH": src_jar_link,
"$POM_PATH": pom_xml_link,
"{snapshot}": ctx.attr.snapshot,
"{release}": ctx.attr.release
"{release}": release_repo,
}
)

Expand Down