Skip to content

Commit

Permalink
feat(cli): Support parsing alpha and beta version numbers of Fern gen…
Browse files Browse the repository at this point in the history
…erators (#5133)

Update semver parsing to support dots, alphas, and betas
  • Loading branch information
Swimburger authored Nov 8, 2024
1 parent 3ad58f4 commit 09a4edf
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 73 deletions.
83 changes: 44 additions & 39 deletions packages/cli/cli/versions.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
- changelogEntry:
- summary: Support parsing alpha and beta version numbers of Fern generators
type: internal
irVersion: 53
version: 0.45.0-rc37
- changelogEntry:
- summary: |
The OpenAPI importer now supports importing deep object query parameters. To do this, you will
The OpenAPI importer now supports importing deep object query parameters. To do this, you will
need to configure a setting in your `generators.yml`
```yml
api:
specs:
api:
specs:
- openapi: ./path/to/openapi.yml
settings:
settings:
object-query-paramaters: true
```
type: fix
Expand All @@ -26,11 +31,11 @@
The Fern CLI now supports roles and viewers in your docs configuration, if you are on the enteprise plan for docs:
```yml docs.ym
roles:
roles:
- internal
- beta-users
- enterprise-users
navigation:
- section: Internal Section
viewers:
Expand Down Expand Up @@ -80,21 +85,21 @@

- changelogEntry:
- summary: |
The Conjure importer now brings in endpoint level descriptions.
The Conjure importer now brings in endpoint level descriptions.
type: feat
irVersion: 53
version: 0.45.0-rc27

- changelogEntry:
- summary: |
`fern check` handles validating unions that contain base properties.
`fern check` handles validating unions that contain base properties.
type: feat
irVersion: 53
version: 0.45.0-rc26

- changelogEntry:
- summary: |
The Fern CLI temporarily does not support RBAC/Audiences (they will be added in again shortly).
The Fern CLI temporarily does not support RBAC/Audiences (they will be added in again shortly).
type: internal
irVersion: 53
version: 0.45.0-rc25
Expand Down Expand Up @@ -126,14 +131,14 @@
type: feat
- summary: |
The RBAC config model is now renamed to `roles` and `viewers`:
```yml docs.yml
roles:
- internal
navigation:
- section: Internal Section
viewers:
viewers:
- internal
contents:
- page: Internal Page
Expand All @@ -152,7 +157,7 @@
# all audiences must be declared at the top level
audiences:
- internal
navigation:
- section: Internal Section
audience: internal # audience is optional
Expand All @@ -179,7 +184,7 @@
version: 0.45.0-rc18

- changelogEntry:
- summary: |
- summary: |
- Improved union example generation by increasing depth for better handling of recursive structures.
- Updated Conjure importer to represent binary types as bytes for requests and file for responses in Fern.
- Added detailed error messages when 'fern docs dev' fails, accessible with --log-level debug.
Expand All @@ -189,7 +194,7 @@

- changelogEntry:
- summary: |
The Conjure importer now correctly keys the union subvariant by the property of the discriminant.
The Conjure importer now correctly keys the union subvariant by the property of the discriminant.
```conjure
union:
Expand All @@ -205,10 +210,10 @@
union:
discriminant: type
types:
square:
square:
type: Square
key: square
circle:
circle:
type: Circle
key: circle
```
Expand Down Expand Up @@ -262,38 +267,38 @@
irVersion: 53
version: 0.45.0-rc10

- changelogEntry:
- summary: |
- changelogEntry:
- summary: |
Improved JSON Schema generation for object extensions and const values:
- Object extensions are now properly represented using `allOf` in the JSON Schema
- Literal values (string and boolean) are now correctly represented using `const` in the JSON Schema
type: fix
irVersion: 53
version: 0.45.0-rc9

- changelogEntry:
- summary: |
- changelogEntry:
- summary: |
Add `#!/usr/bin/env node` to the CLI to prevent runtime errors.
type: internal
irVersion: 53
version: 0.45.0-rc8

- changelogEntry:
- summary: |
- changelogEntry:
- summary: |
Stop minifying the CLI to prevent javascript runtime errors.
type: internal
irVersion: 53
version: 0.45.0-rc7

- changelogEntry:
- summary: |
- changelogEntry:
- summary: |
Update the CLI package.json to include the correct files.
type: fix
irVersion: 53
version: 0.45.0-rc6

- changelogEntry:
- summary: |
- changelogEntry:
- summary: |
Introduce a new command `fern jsonschema <output-file> --type <type-name>`
that outputs the JSON Schema for a given type in your Fern Definition.
Expand All @@ -304,43 +309,43 @@
irVersion: 53
version: 0.45.0-rc5

- changelogEntry:
- summary: |
SCIM has been added as a common initialism.
- changelogEntry:
- summary: |
SCIM has been added as a common initialism.
type: chore
irVersion: 53
version: 0.45.0-rc4

- changelogEntry:
- summary: |
Numerous fixes to the Conjure API Importer such as reading in request bodies and query parameters.
- summary: |
Numerous fixes to the Conjure API Importer such as reading in request bodies and query parameters.
type: fix
irVersion: 53
version: 0.45.0-rc3

- changelogEntry:
- summary: |
The CLI now generates endpoint examples for undiscriminated unions that are recusive.
- summary: |
The CLI now generates endpoint examples for undiscriminated unions that are recusive.
type: fix
irVersion: 53
version: 0.45.0-rc2

- changelogEntry:
- summary: |
The OpenAPI importer now generates streaming examples based on OpenAPI examples.
- summary: |
The OpenAPI importer now generates streaming examples based on OpenAPI examples.
type: fix
irVersion: 53
version: 0.45.0-rc1

- changelogEntry:
- summary: |
The Docs now support rendering `additionalProperties` in the API Playground so that users can send out arbitrary key,value pairs.
- summary: |
The Docs now support rendering `additionalProperties` in the API Playground so that users can send out arbitrary key,value pairs.
type: fix
irVersion: 53
version: 0.45.0-rc0

- changelogEntry:
- summary: Several improvements to the conjure importer.
- summary: Several improvements to the conjure importer.
type: fix
irVersion: 53
version: 0.44.11
Expand Down
64 changes: 41 additions & 23 deletions packages/cli/semver-utils/src/__test__/isVersionAhead.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,47 @@ import { isVersionAhead } from "../isVersionAhead";

describe("isVersionAhead", () => {
it.each`
a | b | expected
${"0.0.191"} | ${"0.0.190"} | ${true}
${"0.0.191"} | ${"0.0.191"} | ${false}
${"0.0.191"} | ${"0.0.192"} | ${false}
${"0.0.191"} | ${"0.0.191-4-abc"} | ${false}
${"0.0.191-4-abc"} | ${"0.0.191"} | ${true}
${"0.0.191-2-abc"} | ${"0.0.191-1-abc"} | ${true}
${"0.0.191-11-abc"} | ${"0.0.191-2-abc"} | ${true}
${"0.0.191-rc0"} | ${"0.0.190"} | ${true}
${"0.0.191-rc0"} | ${"0.0.191"} | ${false}
${"0.0.191-rc0"} | ${"0.0.192"} | ${false}
${"0.0.191-rc0"} | ${"0.0.191-4-abc"} | ${false}
${"0.0.191-rc2"} | ${"0.0.191-rc1"} | ${true}
${"0.0.191-rc2"} | ${"0.0.191-rc11"} | ${false}
${"0.1.3-rc9-2-g23dc3c70"} | ${"0.1.3-rc8-1-g23dc3c70"} | ${true}
${"0.1.3-rc9-2-g23dc3c70"} | ${"0.1.3-rc8-3-g23dc3c70"} | ${true}
${"0.1.3-rc9-2-g23dc3c70"} | ${"0.1.3-rc9-1-g23dc3c70"} | ${true}
${"0.1.3-rc9-2-g23dc3c70"} | ${"0.1.3-rc9-3-g23dc3c70"} | ${false}
${"0.1.3-rc9-1-g23dc3c70"} | ${"0.1.3-rc8"} | ${true}
${"0.1.3-rc9-1-g23dc3c70"} | ${"0.1.3-rc9"} | ${true}
${"0.1.3-rc9-1-g23dc3c70"} | ${"0.1.3-rc10"} | ${false}
${"0.1.3-rc9-1-g23dc3c70"} | ${"0.1.2"} | ${true}
${"0.1.3-rc9-1-g23dc3c70"} | ${"0.1.3"} | ${false}
a | b | expected
${"0.0.191"} | ${"0.0.190"} | ${true}
${"0.0.191"} | ${"0.0.191"} | ${false}
${"0.0.191"} | ${"0.0.192"} | ${false}
${"0.0.191"} | ${"0.0.191-4-abc"} | ${false}
${"0.0.191"} | ${"0.0.191-beta0"} | ${true}
${"0.0.191"} | ${"0.0.191-alpha0"} | ${true}
${"0.0.191"} | ${"0.0.191-beta.0"} | ${true}
${"0.0.191"} | ${"0.0.191-alpha.0"} | ${true}
${"0.0.191-4-abc"} | ${"0.0.191"} | ${true}
${"0.0.191-2-abc"} | ${"0.0.191-1-abc"} | ${true}
${"0.0.191-11-abc"} | ${"0.0.191-2-abc"} | ${true}
${"0.0.191-rc0"} | ${"0.0.190"} | ${true}
${"0.0.191-rc0"} | ${"0.0.191"} | ${false}
${"0.0.191-rc0"} | ${"0.0.192"} | ${false}
${"0.0.191-rc0"} | ${"0.0.191-4-abc"} | ${false}
${"0.0.191-rc2"} | ${"0.0.191-rc1"} | ${true}
${"0.0.191-rc2"} | ${"0.0.191-rc11"} | ${false}
${"0.0.191-rc.2"} | ${"0.0.191-rc.1"} | ${true}
${"0.0.191-rc.2"} | ${"0.0.191-rc.11"} | ${false}
${"0.0.191-rc-2"} | ${"0.0.191-rc-1"} | ${true}
${"0.0.191-rc-2"} | ${"0.0.191-rc-11"} | ${false}
${"0.1.3-rc9-2-g23dc3c70"} | ${"0.1.3-rc8-1-g23dc3c70"} | ${true}
${"0.1.3-rc9-2-g23dc3c70"} | ${"0.1.3-rc8-3-g23dc3c70"} | ${true}
${"0.1.3-rc9-2-g23dc3c70"} | ${"0.1.3-rc9-1-g23dc3c70"} | ${true}
${"0.1.3-rc9-2-g23dc3c70"} | ${"0.1.3-rc9-3-g23dc3c70"} | ${false}
${"0.1.3-rc.9-2-g23dc3c70"} | ${"0.1.3-rc.9-1-g23dc3c70"} | ${true}
${"0.1.3-rc.9-2-g23dc3c70"} | ${"0.1.3-rc.9-3-g23dc3c70"} | ${false}
${"0.1.3-rc9-1-g23dc3c70"} | ${"0.1.3-rc8"} | ${true}
${"0.1.3-rc9-1-g23dc3c70"} | ${"0.1.3-rc9"} | ${true}
${"0.1.3-rc9-1-g23dc3c70"} | ${"0.1.3-rc10"} | ${false}
${"0.1.3-rc9-1-g23dc3c70"} | ${"0.1.2"} | ${true}
${"0.1.3-rc9-1-g23dc3c70"} | ${"0.1.3"} | ${false}
${"0.0.191-rc0"} | ${"0.0.190-beta.0"} | ${true}
${"0.0.191-rc0"} | ${"0.0.190-alpha.0"} | ${true}
${"0.1.3-rc9-2-g23dc3c70"} | ${"0.0.190-beta.0"} | ${true}
${"0.1.3-rc9-2-g23dc3c70"} | ${"0.0.190-alpha.0"} | ${true}
${"0.0.190-beta.0"} | ${"0.0.190-beta.1"} | ${false}
${"0.0.190-beta.1"} | ${"0.0.190-beta.0"} | ${true}
${"0.0.190-beta.0"} | ${"0.0.190-alpha.0"} | ${true}
${"0.0.190-alpha.0"} | ${"0.0.190-beta.0"} | ${false}
`("$a vs. $b", ({ a, b, expected }) => {
expect(isVersionAhead(a, b)).toBe(expected);
});
Expand Down
48 changes: 44 additions & 4 deletions packages/cli/semver-utils/src/isVersionAhead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export function isVersionAhead(a: string, b: string): boolean {
case "release":
case "post-release-commit":
return false;
case "alpha":
case "beta":
return true;
}

return (
Expand All @@ -38,11 +41,48 @@ export function isVersionAhead(a: string, b: string): boolean {
);
}

if (bVersion.type === "post-rc-commit") {
if (aVersion.releaseCandidateIndex !== bVersion.releaseCandidateIndex) {
return aVersion.releaseCandidateIndex > bVersion.releaseCandidateIndex;
if (aVersion.type === "post-rc-commit") {
switch (bVersion.type) {
case "release":
case "post-release-commit":
return false;
case "alpha":
case "beta":
return true;
}

if (bVersion.type === "post-rc-commit") {
if (aVersion.releaseCandidateIndex !== bVersion.releaseCandidateIndex) {
return aVersion.releaseCandidateIndex > bVersion.releaseCandidateIndex;
}
return aVersion.commitIndex > bVersion.commitIndex;
}
}

if (aVersion.type === "beta") {
switch (bVersion.type) {
case "release":
case "post-release-commit":
case "rc":
case "post-rc-commit":
return false;
case "alpha":
return true;
}
return aVersion.commitIndex > bVersion.commitIndex;

return aVersion.index > bVersion.index;
}

if (aVersion.type === "alpha") {
switch (bVersion.type) {
case "release":
case "post-release-commit":
case "rc":
case "post-rc-commit":
return false;
}

return aVersion.index > bVersion.index;
}

// if here, 'a' is a post-rc-commit and 'b' is not, so just recursively run
Expand Down
Loading

0 comments on commit 09a4edf

Please sign in to comment.