Skip to content

Commit

Permalink
feat(seed): introduce scripts to generators so fern bot can build the…
Browse files Browse the repository at this point in the history
… SDKs (#4788)
  • Loading branch information
armandobelardo authored Oct 4, 2024
1 parent e46a4f7 commit d35196a
Show file tree
Hide file tree
Showing 33 changed files with 264 additions and 342 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/validate-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ jobs:
generator-validate:
strategy:
matrix:
generator:
[
generator: [
fastapi,
pydantic,
python-sdk,
Expand All @@ -44,6 +43,8 @@ jobs:
java-model,
java-spring,
ts-express,
csharp-sdk,
csharp-model
php-sdk,
php-model
]
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@fern-api/fern-definition-formatter": "workspace:*",
"@fern-api/cli-migrations": "workspace:*",
"@fern-api/fern-definition-schema": "workspace:*",
"@fern-fern/generators-sdk": "0.109.0-21be2e5be",
"@fern-fern/generators-sdk": "0.114.0-5745f9e74",
"@fern-fern/fiddle-sdk": "0.0.584",
"@types/get-port": "^4.2.0",
"ansi-escapes": "^5.0.0",
Expand Down Expand Up @@ -115,4 +115,4 @@
"prettier": "^2.7.1",
"typescript": "4.6.4"
}
}
}
4 changes: 2 additions & 2 deletions packages/cli/configuration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@fern-api/fern-definition-schema": "workspace:*",
"@fern-fern/fdr-cjs-sdk": "0.108.0-dcb0f740c",
"@fern-fern/fiddle-sdk": "0.0.584",
"@fern-fern/generators-sdk": "0.109.0-21be2e5be",
"@fern-fern/generators-sdk": "0.114.0-5745f9e74",
"find-up": "^6.3.0",
"js-yaml": "^4.1.0",
"lodash-es": "^4.17.21",
Expand All @@ -57,4 +57,4 @@
"typescript": "4.6.4",
"vitest": "^2.0.5"
}
}
}
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@fern-fern/fdr-cjs-sdk": "0.108.0-dcb0f740c",
"@fern-fern/generators-sdk": "0.107.0-00fe26566",
"@fern-fern/generators-sdk": "0.114.0-5745f9e74",
"@fern-api/venus-api-sdk": "0.0.38",
"@fern-fern/fdr-test-sdk": "^0.0.5297",
"@fern-fern/fiddle-sdk": "0.0.584"
Expand All @@ -44,4 +44,4 @@
"prettier": "^2.7.1",
"typescript": "4.6.4"
}
}
}
86 changes: 50 additions & 36 deletions packages/seed/fern/definition/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ types:
publishGa: PublishCommand
publishRc: PublishCommand
publishDev: PublishCommand
changelogLocation:
changelogLocation:
type: optional<string>
docs: |
docs: |
The location of the changelog file, the schema of which must follow FDR's `GeneratorReleaseRequest` object.
SeedWorkspaceConfiguration:
Expand All @@ -18,30 +18,32 @@ types:
irVersion: string
test: TestConfiguration
publish: PublishConfiguration
changelogLocation:
changelogLocation:
type: optional<string>
docs: |
docs: |
The location of the changelog file, the schema of which must follow FDR's `GeneratorReleaseRequest` object.
language: optional<Language>
defaultCustomConfig: optional<map<string, unknown>>
defaultOutputMode: OutputMode
generatorType: GeneratorType

customFixtureConfig:
buildScripts: optional<BuildScripts>

customFixtureConfig:
type: optional<FixtureConfigurations>
docs: |
Configuration that will be used for any custom fixture specified by --custom-fixture
fixtures:
type: optional<map<string, list<FixtureConfigurations>>>
scripts: optional<list<ScriptConfig>>
allowedFailures:
scripts: optional<list<DockerScriptConfig>>
allowedFailures:
type: optional<list<string>>
docs: |
List any fixtures that are okay to fail. For normal fixtures
docs: |
List any fixtures that are okay to fail. For normal fixtures
just list the fixture name. For configured fixture list {fixture}:{outputFolder}.
features: optional<features.GeneratorFeatures>

PublishDockerConfiguration:
properties:
context: string
Expand All @@ -63,18 +65,18 @@ types:
Commands can be multi-line, we'll run them all!
properties:
workingDirectory: optional<string>
versionSubstitution:
versionSubstitution:
type: optional<string>
docs: |
docs: |
The string to substitute for the version in the command. ex. `"$VERSION"`
command: DockerCommand

PublishConfiguration:
discriminated: false
union:
union:
- PublishDocker
- PublishCommand

TestDockerConfiguration:
properties:
image: string
Expand All @@ -85,38 +87,50 @@ types:
docker: TestDockerConfiguration
local: optional<LocalBuildInfo>

LocalBuildInfo:
properties:
workingDirectory:
LocalBuildInfo:
properties:
workingDirectory:
type: string
docs: |
The working directory for the generator.
buildCommand:
docs: |
The working directory for the generator.
buildCommand:
type: list<string>
docs: |
The command to build the generator locally.
`yarn workspace @fern-api/openapi-generator build` for example.
docs: |
The command to build the generator locally.
`yarn workspace @fern-api/openapi-generator build` for example.
runCommand:
type: string
docs: |
The command to run the generator locally.
docs: |
The command to run the generator locally.
`node generators/openapi/dist/cli.cjs` for example.
env:
env:
type: optional<map<string, string>>
docs: |
docs: |
Environment variables to set when running the generator locally.
DockerCommand:
BuildScripts:
docs: Scripts pertaining to the artifact produced by this generator and how to build them (e.g. yarn install && yarn build for the TS SDK)
properties:
preInstallScript: optional<Script>
installScript: optional<Script>
compileScript: optional<Script>
testScript: optional<Script>

DockerCommand:
discriminated: false
union:
union:
- string
- list<string>

ScriptConfig:
Script:
properties:
docker: string
commands: list<string>

DockerScriptConfig:
extends: Script
properties:
docker: string

Language:
enum:
- python
Expand Down Expand Up @@ -144,7 +158,7 @@ types:
audiences: optional<list<string>>
outputFolder: string
outputVersion: optional<string>
outputMode:
outputMode:
type: optional<OutputMode>
docs: Overrides the default output mode

Expand All @@ -157,7 +171,7 @@ types:

ReadmeEndpoint:
discriminated: false
union:
union:
- string
- ReadmeEndpointObject

Expand All @@ -166,9 +180,9 @@ types:
method: string
path: string
stream: optional<boolean>
OutputMode:
enum:

OutputMode:
enum:
- github
- local_files
- publish
4 changes: 2 additions & 2 deletions packages/seed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@fern-api/workspace-loader": "workspace:*",
"@fern-fern/fiddle-sdk": "0.0.584",
"@fern-fern/generator-exec-sdk": "^0.0.898",
"@fern-fern/generators-sdk": "0.109.0-21be2e5be",
"@fern-fern/generators-sdk": "0.114.0-5745f9e74",
"@types/pretty-ms": "^5.0.1",
"chalk": "^5.3.0",
"console-table-printer": "^2.12.0",
Expand Down Expand Up @@ -79,4 +79,4 @@
"typescript": "4.6.4",
"vitest": "^2.0.5"
}
}
}
24 changes: 23 additions & 1 deletion packages/seed/src/commands/register/registerGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,29 @@ export async function registerGenerator({
displayName: generatorConfig.displayName,
generatorType: convertGeneratorType(generatorConfig.generatorType),
generatorLanguage: generatorConfig.language,
dockerImage: generatorConfig.image
dockerImage: generatorConfig.image,
scripts: {
preInstallScript: generatorConfig.buildScripts?.preInstallScript
? {
steps: generatorConfig.buildScripts.preInstallScript.commands
}
: undefined,
installScript: generatorConfig.buildScripts?.installScript
? {
steps: generatorConfig.buildScripts.installScript.commands
}
: undefined,
compileScript: generatorConfig.buildScripts?.compileScript
? {
steps: generatorConfig.buildScripts.compileScript.commands
}
: undefined,
testScript: generatorConfig.buildScripts?.testScript
? {
steps: generatorConfig.buildScripts.testScript.commands
}
: undefined
}
});

// Register generator versions
Expand Down
6 changes: 3 additions & 3 deletions packages/seed/src/commands/test/ScriptRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { loggingExeca } from "@fern-api/logging-execa";
import { TaskContext } from "@fern-api/task-context";
import { writeFile } from "fs/promises";
import tmp from "tmp-promise";
import { ScriptConfig } from "../../config/api";
import { DockerScriptConfig } from "../../config/api";
import { GeneratorWorkspace } from "../../loadGeneratorWorkspaces";
import { Semaphore } from "../../Semaphore";

Expand All @@ -26,7 +26,7 @@ export declare namespace ScriptRunner {
}
}

interface RunningScriptConfig extends ScriptConfig {
interface RunningScriptConfig extends DockerScriptConfig {
containerId: string;
}

Expand Down Expand Up @@ -78,7 +78,7 @@ export class ScriptRunner {
outputDir: AbsoluteFilePath;
taskContext: TaskContext;
containerId: string;
script: ScriptConfig;
script: DockerScriptConfig;
}): Promise<ScriptRunner.RunResponse> {
taskContext.logger.info(`Running script ${script.commands[0] ?? ""} on ${id}`);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as FernSeedConfig from "../../..";

/**
* Scripts pertaining to the artifact produced by this generator and how to build them (e.g. yarn install && yarn build for the TS SDK)
*/
export interface BuildScripts {
preInstallScript?: FernSeedConfig.Script;
installScript?: FernSeedConfig.Script;
compileScript?: FernSeedConfig.Script;
testScript?: FernSeedConfig.Script;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as FernSeedConfig from "../../..";

export interface DockerScriptConfig extends FernSeedConfig.Script {
docker: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* This file was auto-generated by Fern from our API Definition.
*/

export interface ScriptConfig {
docker: string;
export interface Script {
commands: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export interface SeedWorkspaceConfiguration {
defaultCustomConfig?: Record<string, unknown>;
defaultOutputMode: FernSeedConfig.OutputMode;
generatorType: FernSeedConfig.GeneratorType;
buildScripts?: FernSeedConfig.BuildScripts;
/** Configuration that will be used for any custom fixture specified by --custom-fixture */
customFixtureConfig?: FernSeedConfig.FixtureConfigurations;
fixtures?: Record<string, FernSeedConfig.FixtureConfigurations[]>;
scripts?: FernSeedConfig.ScriptConfig[];
scripts?: FernSeedConfig.DockerScriptConfig[];
/**
* List any fixtures that are okay to fail. For normal fixtures
* just list the fixture name. For configured fixture list {fixture}:{outputFolder}.
Expand Down
4 changes: 3 additions & 1 deletion packages/seed/src/config/api/resources/config/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ export * from "./PublishConfiguration";
export * from "./TestDockerConfiguration";
export * from "./TestConfiguration";
export * from "./LocalBuildInfo";
export * from "./BuildScripts";
export * from "./DockerCommand";
export * from "./ScriptConfig";
export * from "./Script";
export * from "./DockerScriptConfig";
export * from "./Language";
export * from "./GeneratorType";
export * from "./FixtureConfigurations";
Expand Down
Loading

0 comments on commit d35196a

Please sign in to comment.