-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow upgrading to RCs with fern upgrade (#991)
- Loading branch information
1 parent
0608840
commit 5658f0b
Showing
18 changed files
with
157 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 8 additions & 2 deletions
10
packages/cli/cli/src/cli-context/upgrade-utils/getLatestVersionOfCli.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
import latestVersion from "latest-version"; | ||
import { CliEnvironment } from "../CliEnvironment"; | ||
|
||
export async function getLatestVersionOfCli(cliEnvironment: CliEnvironment): Promise<string> { | ||
export async function getLatestVersionOfCli({ | ||
cliEnvironment, | ||
includePreReleases = false, | ||
}: { | ||
cliEnvironment: CliEnvironment; | ||
includePreReleases?: boolean; | ||
}): Promise<string> { | ||
// when running a non-published version of the CLI (e.g. in ETE tests), | ||
// don't try to upgrade | ||
if (cliEnvironment.packageVersion === "0.0.0") { | ||
return cliEnvironment.packageVersion; | ||
} | ||
return latestVersion(cliEnvironment.packageName, { | ||
version: "latest", | ||
version: includePreReleases ? "prerelease" : "latest", | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,114 @@ | ||
import semverDiff from "semver-diff"; | ||
|
||
const COMMIT_VERSION_REGEX = /([0-9]+)\.([0-9]+)\.([0-9]+)-([0-9]+)-.+/; | ||
const RC_VERSION_REGEX = /([0-9]+)\.([0-9]+)\.([0-9]+)-rc([0-9]+)/; | ||
|
||
type Version = ReleaseCandidate | Release | PostReleaseCommit; | ||
|
||
interface ReleaseCandidate { | ||
type: "rc"; | ||
forVersion: string; | ||
releaseCandidateIndex: number; | ||
} | ||
|
||
interface Release { | ||
type: "release"; | ||
version: string; | ||
} | ||
|
||
interface PostReleaseCommit { | ||
type: "commit"; | ||
releasedVersion: string; | ||
commitIndex: number; | ||
} | ||
|
||
/** | ||
* returns whether version a came after version b | ||
*/ | ||
export function isVersionAhead(a: string, b: string): boolean { | ||
if (a === b) { | ||
return false; | ||
const aVersion = parseVersion(a); | ||
const bVersion = parseVersion(b); | ||
|
||
// if versions are different, then default to semverDiff | ||
const aVersionString = getVersionString(aVersion); | ||
const bVersionString = getVersionString(bVersion); | ||
if (aVersionString !== bVersionString) { | ||
return semverDiff(aVersionString, bVersionString) == null; | ||
} | ||
|
||
if (aVersion.type === "commit") { | ||
return bVersion.type !== "commit" || aVersion.commitIndex > bVersion.commitIndex; | ||
} | ||
|
||
const diff = semverDiff(a, b); | ||
|
||
// generally, diff == null implies that a >= b. | ||
if (diff == null) { | ||
// however, fern versions use git describe, which is not exactly | ||
// semver-compatible. | ||
// e.g. in git describe, 0.0.191-2-abc is ahead of 0.0.191. | ||
// in semver, 0.0.191-2-abc is a prerelease of (i.e. precedes) 0.0.191. | ||
// so if semverDiff thinks that b is a prerelease of a, then we know that b | ||
// actually came after a. | ||
if (semverDiff(b, a) === "prerelease") { | ||
return false; | ||
} else { | ||
return true; | ||
if (aVersion.type === "release") { | ||
switch (bVersion.type) { | ||
case "commit": | ||
case "release": | ||
return false; | ||
case "rc": | ||
return true; | ||
} | ||
} | ||
|
||
// same case here. generally, if diff is defined, then a < b. | ||
// but if semverDiff thinks that a is a prerelease of b, then we know that a | ||
// actually came after b. | ||
return diff === "prerelease"; | ||
return bVersion.type === "rc" && aVersion.releaseCandidateIndex > bVersion.releaseCandidateIndex; | ||
} | ||
|
||
function parseVersion(versionString: string): Version { | ||
const commitMatch = versionString.match(COMMIT_VERSION_REGEX); | ||
if (commitMatch != null) { | ||
const [_, major, minor, patch, commitIndex] = commitMatch; | ||
const parsedCommitIndex = Number(commitIndex); | ||
if ( | ||
major == null || | ||
minor == null || | ||
patch == null || | ||
commitIndex == null || | ||
commitIndex.length === 0 || | ||
isNaN(parsedCommitIndex) | ||
) { | ||
throw new Error("Cannot parse commit version: " + versionString); | ||
} | ||
return { | ||
type: "commit", | ||
releasedVersion: `${major}.${minor}.${patch}`, | ||
commitIndex: parsedCommitIndex, | ||
}; | ||
} | ||
|
||
const rcMatch = versionString.match(RC_VERSION_REGEX); | ||
if (rcMatch != null) { | ||
const [_, major, minor, patch, rcIndex] = rcMatch; | ||
const parsedRcIndex = Number(rcIndex); | ||
if ( | ||
major == null || | ||
minor == null || | ||
patch == null || | ||
rcIndex == null || | ||
rcIndex.length === 0 || | ||
isNaN(parsedRcIndex) | ||
) { | ||
throw new Error("Cannot parse RC version: " + versionString); | ||
} | ||
return { | ||
type: "rc", | ||
forVersion: `${major}.${minor}.${patch}`, | ||
releaseCandidateIndex: parsedRcIndex, | ||
}; | ||
} | ||
|
||
return { | ||
type: "release", | ||
version: versionString, | ||
}; | ||
} | ||
|
||
function getVersionString(version: Version): string { | ||
switch (version.type) { | ||
case "commit": | ||
return version.releasedVersion; | ||
case "rc": | ||
return version.forVersion; | ||
case "release": | ||
return version.version; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters