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

feat: support pre-release versions in self-update command #4022

Merged
merged 25 commits into from
Mar 31, 2023

Conversation

vvagaytsev
Copy link
Collaborator

@vvagaytsev vvagaytsev commented Mar 29, 2023

What this PR does / why we need it:
To be able to update to the 0.13 pre-releases from 0.12.x using garden self-update command.
This PR also contains some refactoring.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:
The commits will be squashed before the merge. See individual commits for details.

This improves performance by avoiding unnecessary target version search when the version is specified explicitly.
Also, this removes unnecessary local variable `targetVersion` which has been semantically equal to `desiredVersion`.
Just placed `VersionScope` type definition and relevant utility function next to each other.
The new method `findReleaseVersion` contains machinery to traverse GitHub releases in a pagination mode and get the first one matching a given predicate.
To reduce semantic load of the `SelfUpdateCommand` class. Those helpers are generic and not tightly related to the semantics of the `self-update` command.
That method was tightly connected to the logic of the caller, and was used by the only caller.
To isolate the artifacts details collection and return the details as a structured object.
The artifacts details can differ depending on the `desiredVersion` type (edge/pre-release/release).
This change will be used to support pre-prelease versions in `self-update` command.
@vvagaytsev vvagaytsev requested review from Walther and Orzelius March 29, 2023 10:52
@vvagaytsev vvagaytsev marked this pull request as draft March 29, 2023 10:54
@vvagaytsev vvagaytsev marked this pull request as ready for review March 29, 2023 10:57
Copy link
Contributor

@Walther Walther left a comment

Choose a reason for hiding this comment

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

I think this looks good but I'll let Albert double-check as well.
Thanks for the refactor and fix!

Empty message on the `error` level gets rendered as `✖ undefined`. That might be confusing.
Copy link
Contributor

@Orzelius Orzelius left a comment

Choose a reason for hiding this comment

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

a few comments

@@ -351,35 +351,52 @@ export class SelfUpdateCommand extends Command<SelfUpdateArgs, SelfUpdateOpts> {
)
}

const targetRelease = await this.findRelease((release) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this deserves a unit test or two

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point! Actually, we need to test the predicate here. The machinery around it is quite trivial.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added tests in 5fef833

@vvagaytsev vvagaytsev force-pushed the feat/self-update-to-prerelease branch from c062f8b to 29bc18b Compare March 29, 2023 13:18
@vvagaytsev vvagaytsev requested review from Walther and Orzelius March 30, 2023 10:04
Comment on lines 404 to 414
it("should skip an older pre-release version", () => {
expectSkipped({ tag_name: "test", draft: true, prerelease: false }, semver.parse("0.13.0")!, "patch")
})

it("should skip the same pre-release version", () => {
expectSkipped({ tag_name: "test", draft: true, prerelease: false }, semver.parse("0.13.0")!, "patch")
})

it("should skip a newer pre-release version", () => {
expectSkipped({ tag_name: "test", draft: true, prerelease: false }, semver.parse("0.13.0")!, "patch")
})
Copy link
Contributor

@Walther Walther Mar 31, 2023

Choose a reason for hiding this comment

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

possible copy-paste issue - these test cases look identical

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! Fixed that in 144cfee

@vvagaytsev vvagaytsev requested a review from Walther March 31, 2023 09:31
Copy link
Contributor

@Walther Walther left a comment

Choose a reason for hiding this comment

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

thanks for the good work! looks good to me 🚀

@vvagaytsev vvagaytsev merged commit 06e9e56 into main Mar 31, 2023
@vvagaytsev vvagaytsev deleted the feat/self-update-to-prerelease branch March 31, 2023 10:07
vvagaytsev added a commit that referenced this pull request Mar 31, 2023
* perf: got rid of unnecessary HTTP requests

This improves performance by avoiding unnecessary target version searches when the version is specified explicitly.
Also, this removes the unnecessary local variable `targetVersion` which has been semantically equal to `desiredVersion`.

* refactor: utility function to find a release by a predicate

The new method `findReleaseVersion` contains machinery to traverse GitHub releases in a pagination mode and get the first one matching a given predicate.

* refactor: move GH helpers to a dedicated namespace

To reduce the semantic load of the `SelfUpdateCommand` class. Those helpers are generic and not tightly related to the semantics of the `self-update` command.

* refactor: inline `targetVersionMatches` method

That method was tightly connected to the caller's logic, and was used by the only caller.

* refactor: helper function to get release artifact details

To isolate the artifacts details collection and return the details as a structured object.
The artifacts details can differ depending on the `desiredVersion` type (edge/pre-release/release).
This change will support pre-prelease versions in `self-update` command.

* refactor: helper function to identify pre-release versions

* feat: support pre-release versions in `self-update` command

* chore: remove unnecessary log line

An empty message on the `error` level gets rendered as `✖ undefined`. That might be not very clear.

* fix: fix version comparing logic

To correctly handle `0.x` -> `0.y` updates as major ones.

---------

Co-authored-by: Orzelius <[email protected]>
vvagaytsev added a commit that referenced this pull request Mar 31, 2023
* perf: got rid of unnecessary HTTP requests

This improves performance by avoiding unnecessary target version searches when the version is specified explicitly.
Also, this removes the unnecessary local variable `targetVersion` which has been semantically equal to `desiredVersion`.

* refactor: utility function to find a release by a predicate

The new method `findReleaseVersion` contains machinery to traverse GitHub releases in a pagination mode and get the first one matching a given predicate.

* refactor: move GH helpers to a dedicated namespace

To reduce the semantic load of the `SelfUpdateCommand` class. Those helpers are generic and not tightly related to the semantics of the `self-update` command.

* refactor: inline `targetVersionMatches` method

That method was tightly connected to the caller's logic, and was used by the only caller.

* refactor: helper function to get release artifact details

To isolate the artifacts details collection and return the details as a structured object.
The artifacts details can differ depending on the `desiredVersion` type (edge/pre-release/release).
This change will support pre-prelease versions in `self-update` command.

* refactor: helper function to identify pre-release versions

* feat: support pre-release versions in `self-update` command

* chore: remove unnecessary log line

An empty message on the `error` level gets rendered as `✖ undefined`. That might be not very clear.

* fix: fix version comparing logic

To correctly handle `0.x` -> `0.y` updates as major ones.

---------

Co-authored-by: Orzelius <[email protected]>
This was referenced May 11, 2023
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