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

Fix dependencies v1 definition and conversion #2232

Merged
merged 2 commits into from
Jul 11, 2022

Conversation

carolynvs
Copy link
Member

What does this change

When I was implementing the dependencies v2 extension (advanced dependencies proposal), I realized that we had a regression in the v1 extension recently when we updated the porter.yaml schema to move reference and version underneath the bundle field, e.g.

dependencies:
  - name: mydep
     bundle:
        reference: getporter/mydep
        version: 1.0.0

I had to make two fixes to get the original test passing properly, plus update the test since there was a problem with closures that was making it pass when it shouldn't have.

Fix yaml tag for dependency version

There was a typo in the yaml tag for a dependency's version in porter.yaml. It has always been version, and we intended to just move reference and version underneath a new bundle field. It was accidentally set to versions, but none of the other code, tests or examples were
updated to that value (yay!)

This reverts the yaml tag back to version (singular). I'm not bumping the schema version since this actually matches what the schema has always been, it's just fixing a bug where version completely didn't work for a bit.

Set AllowPrerelease on deps v1 extension

When we are converting a porter.yaml to a bundle.json and populating the v1 dependencies extension metadata, we accidentally stopped populating AllowPrerelease (which was in use previously). Before we updated the dependency schema in preparation for a v2 of the dependency extension this value was set explicitly in the porter.yaml. When we removed it, we
decided to use the mastermind/semver convention of "if a version constraint includes a prerelease, then we will match against releases", i.e. 1.0.0-0 would allow prereleases, but we missed updating the conversion logic to explicitly set AllowPrerelease in that situation.

I've updated our testdata to work with the new logic and verified that we are now properly setting AllowPrerelease again.

What issue does it fix

This is a fix/follow-up to #2117

Notes for the reviewer

Put any questions or notes for the reviewer here.

Checklist

  • Did you write tests?
  • Did you write documentation? This fixed the code to match the schema/docs
  • Did you change porter.yaml or a storage document record? Update the corresponding schema file.
  • If this is your first pull request, please add your name to the bottom of our Contributors list. Thank you for making Porter better! 🙇‍♀️

Reviewer Checklist

  • Comment with /azp run test-porter-release if a magefile or build script was modified
  • Comment with /azp run porter-integration if it's a non-trivial PR

There was a typo in the yaml tag for a dependency's version in
porter.yaml. It has always been version, and we intended to just move
reference and version underneath a new bundle field. It was accidentally
set to versions, but none of the other code, tests or examples were
updated to that value (yay!)

This reverts the yaml tag back to version (singular). I'm not bumping
the schema version since this actually matches what the schema has
always been, it's just fixing a bug where version completely didn't work
for a bit.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
When we are converting a porter.yaml to a bundle.json and populating the
v1 dependencies extension metadata, we accidentally stopped populating
AllowPrerelease (which was in use previously). Before we updated the
dependency schema in preparation for a v2 of the dependency extension
this value was set explicitly in the porter.yaml. When we removed it, we
decided to use the mastermind/semver convention of "if a version
constraint includes a prerelease, then we will match against releases",
i.e. 1.0.0-0 would allow prereleases, but we missed updating the
conversion logic to explicitly set AllowPrerelease in that situation.

I've updated our testdata to work with the new logic and verified that
we are now properly setting AllowPrerelease again.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
@carolynvs carolynvs marked this pull request as ready for review July 8, 2022 15:39
@@ -401,10 +406,9 @@ func (c *ManifestConverter) generateBundleImages() map[string]bundle.Image {
return images
}

func (c *ManifestConverter) generateDependencies() *cnab.Dependencies {

func (c *ManifestConverter) generateDependencies() (*cnab.Dependencies, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm missing something, I can't find where this function is returning an error?

Copy link
Member Author

@carolynvs carolynvs Jul 11, 2022

Choose a reason for hiding this comment

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

Sorry the I was chopping up #2099 into refactorings and while that larger PR needs to return an error this exact change here doesn't use it yet. Are you okay with me keeping that in place here so that I don't need to redo both PRs to shuffle when we introduce that change? I promise we will be returning errors by the time I finish splitting up that big PR. 😀

@@ -421,12 +425,18 @@ func (c *ManifestConverter) generateDependencies() *cnab.Dependencies {
dependencyRef.Version = &cnab.DependencyVersion{
Ranges: []string{dep.Bundle.Version},
}

// If we can detect that prereleases are used in the version, then set AllowPrereleases to true
v, err := semver.NewVersion(dep.Bundle.Version)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we return the error here if it's not nil?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, because we are just parsing the value to see if we can detect the use of a prerelease value. If they are using a semver constrain, the value isn't parsable as a singular version.

If we want to validate values from the porter.yaml, it should be in the Manifest.Validate function. In general though we aren't going to do that for deps since not all tags are semver values.

@carolynvs carolynvs merged commit 9541f38 into getporter:release/v1 Jul 11, 2022
Porter and Mixins automation moved this from In Progress to Done Jul 11, 2022
@carolynvs carolynvs deleted the fix-deps-test branch July 11, 2022 17:13
@carolynvs carolynvs added the pep003-advanced-dependencies Implementation of the Advanced Dependencies proposal label Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pep003-advanced-dependencies Implementation of the Advanced Dependencies proposal
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants