-
Notifications
You must be signed in to change notification settings - Fork 274
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
Conversation
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.
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 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.
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.
a few comments
core/src/commands/self-update.ts
Outdated
@@ -351,35 +351,52 @@ export class SelfUpdateCommand extends Command<SelfUpdateArgs, SelfUpdateOpts> { | |||
) | |||
} | |||
|
|||
const targetRelease = await this.findRelease((release) => { |
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 deserves a unit test or two
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.
Good point! Actually, we need to test the predicate here. The machinery around it is quite trivial.
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 tests in 5fef833
Co-authored-by: Orzelius <[email protected]>
c062f8b
to
29bc18b
Compare
To correctly handle `0.x` -> `0.y` updates as major ones.
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") | ||
}) |
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.
possible copy-paste issue - these test cases look identical
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.
Thanks! Fixed that in 144cfee
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.
thanks for the good work! looks good to me 🚀
* 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]>
* 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]>
What this PR does / why we need it:
To be able to update to the
0.13
pre-releases from0.12.x
usinggarden 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.