-
Notifications
You must be signed in to change notification settings - Fork 104
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
(PDK-718) Add --template-ref argument for upstream template repo tags #434
Conversation
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.
Is there a use case for caching the template-ref
in the answers file when they are using the default template-url
? I could see that leading to problems down the line...
I wasn't sure how that should play out at the time. I think you're right though. I'll rebase once I figure out how this is supposed to work with the templatedir changes in #433. |
See also PDK-815 where we are probably going to stop comparing template refs directly and instead just see if there are any pending changes. |
@hunner can you rebase/cleanup this? It would be a great addition to the 1.5 release |
The logic for handling the template-url/template-ref is passed around in various places and morphed by several tickets' changes, so trying to think of how to best make the url/ref work in a consistent manner. Information for
At least, this is a stab at solving resolution generically. |
In your proposal, there is a slight mix-up between the For improved clarity, I would suggest handling the url and ref always together, and make the Information for the template location can come from four places, ordered by priority:
The last thing I take issue with is the skip-and-delete ("SAD") on a 404. This is already happening, see e.g. PDK-914, and was quite annoying to me. Consider the situation the user is in after a SAD incident:
Instead of SAD, the PDK could throw an error and stop evaluation ("EASE"). Let's consider the user's case after the PDK EASEd them:
|
@DavidS Okay. I agree that handling the repo url and ref together is needed, but adding the branch as the url fragment is not part of the git design. This may be odd UX-wise, but looks like it's easier to handle in the code than separate Would you also propose that users can do a single Using the I would not want to provide a default ref of As for EASE vs SAD, yes error states are probably better for people to handle.
|
|
@DavidS okay looks like URI can encode the path and handle the fragment for file paths too: [1] pry(main)> u = URI.parse(URI.encode("file:///foo/bar#test") + "#" + URI.encode("branch#name/test"))
=> #<URI::Generic file:/foo/bar%23test#branch%23name/test>
[2] pry(main)> u.scheme
=> "file"
[3] pry(main)> URI.decode(u.path)
=> "/foo/bar#test"
[4] pry(main)> URI.decode(u.fragment)
=> "branch#name/test" |
Perfect. |
c8272af
to
bc1fc88
Compare
Would be great to get this merged. |
c2919fc
to
2398f71
Compare
This seems to be pretty functional for tag & branch refs of local (absolute paths without a schema) or remote ( Local-dir branch resetting doesn't try to match the branch name to the remote ref, so if the local branch is "master" but I need to fix rubocop, and write/update lots of specs. |
29542d2
to
b190dc8
Compare
If the module being updated is using the default template *and* the template ref is a tag *and* the PDK is being run from a package install, then update the module to use the latest tag of the template. In all other cases, get the ref from the `template_url` metadata value (and if there is no ref in the `template_url` metadata value, use the default template ref which is the latest tag for package installs or `master` otherwise).
35ee2b1
to
05001ad
Compare
380a622
to
b6a9d58
Compare
lib/pdk/module/templatedir.rb
Outdated
@@ -82,7 +92,7 @@ def metadata | |||
'pdk-version' => PDK::Util::Version.version_string, | |||
} | |||
|
|||
result['template-url'] = @repo ? @repo : @path | |||
result['template-url'] = @cloned_from |
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.
@rodjek So this seems to still show inconsistency with the latest update. Still seeing this:
"pdk-version": "1.10.0.pre (remotes/hunner/add_template_ref-0-gb6a9d585c8)",
"template-url": "https://github.com/puppetlabs/pdk-templates#pin-puppet",
"template-ref": "heads/master-0-ge07e4fd"
@scotje @rodjek What's our stance on this? I'm not a fan of the strings that imply "branch" being inconsistent between the template-url
and template-ref
where one says pin-puppet
and the other says heads/master
.
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.
Added a few minor comments but nothing that should block this from being merged!
Checked out the branch and played around a bit and it all seems to work as I would expect. :)
explicit_uri ||= Addressable::URI.parse(uri_safe(explicit_url)) | ||
explicit_uri.fragment = explicit_ref || default_template_ref | ||
else | ||
explicit_uri = nil |
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.
This else
block seems redundant? My understanding is that explicit_url = opts.fetch(:'template-url', nil)
above will set the value to nil
already in this case.
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.
Yeah, this is kind of unfortunate variable naming explicit_url
vs explicit_uri
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.
Ah indeed. That is unfortunate. :)
lib/pdk/util/template_uri.rb
Outdated
default_uri.fragment = default_template_ref | ||
|
||
ary = [] | ||
ary << { type: _('--template-url'), uri: explicit_uri, allow_fallback: false } |
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.
Should this one also have a conditional on the end?
ary << { type: _('--template-url'), uri: explicit_uri, allow_fallback: false } | |
ary << { type: _('--template-url'), uri: explicit_uri, allow_fallback: false } if explicit_uri |
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 guess it doesn't matter since entries with a nil
value for the uri
are skipped later, but is there a reason to knowingly add an incomplete entry to this list?
lib/pdk/generate/module.rb
Outdated
# If the user specifies our template via the command line, remove the | ||
# saved template-url answer. | ||
# Only update the answers files after metadata has been written. | ||
if template_uri.git_remote == PDK::Util::TemplateURI.default_template_uri.git_remote |
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 this can be simplified now to:
if template_uri.git_remote == PDK::Util::TemplateURI.default_template_uri.git_remote | |
if template_uri.default? |
spec/unit/pdk/cli/util_spec.rb
Outdated
end | ||
end | ||
|
||
context 'when template-url has been specified but not template-url' do |
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.
context 'when template-url has been specified but not template-url' do | |
context 'when template-url has been specified but not template-ref' do |
35bc88e
to
56f52a1
Compare
I rolled the url/refs together internally into a single "uri" that should be considered the template target and broken apart with the URI & decode methods when needed separately.
PDK::Util
functions as discussed on the PR comments on github.PDK::Util.template_uri()
takes options hash for the opts.fetch in case users pass --arguments, but is a class method. I don't really like this, but it's probably needed to fulfill the requirements discussed in the PR.file:///...
urls are treated as remote paths, but absolute paths such asc:/...
or/...
are treated as local paths and use directly. This behavior was pre-existing.user@host:<0-65535>/path
in which I interpret this as a URI instead of an SCP url)pdk new *
generators as they are not used to specify or change templates and actually create edge cases by being used to do so. The arguments should only be specified during a pdk convert or apdk new module
file:///<drive>:/...
scheme or/<drive>:/
leading-slash to be URI-compatible. I represent paths that lack thefile://
scheme as/<drive>:/
internally and strip the leading / when used for commands or serialization in metadata.json.