Skip to content

Commit

Permalink
Merge branch 'main' into dsinghvi/model-fern-definition-in-fern
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Oct 20, 2024
2 parents 3cc01ff + a381d5f commit 15de56f
Showing 19 changed files with 98 additions and 59 deletions.
30 changes: 22 additions & 8 deletions .github/workflows/publish-cli.yml
Original file line number Diff line number Diff line change
@@ -30,16 +30,20 @@ jobs:
- name: Install
uses: ./.github/actions/install

- name: Build Seed
run: |
pnpm seed:build
- name: Print version
run: |
git_version="$(./scripts/git-version.sh)"
echo Publishing version: "${git_version}"
- name: Add version to dev package.json's
- name: Publish Dev CLI
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
git_version="$(./scripts/git-version.sh)"
pnpm seed:local publish cli --ver ${git_version} --dev --log-level debug
pnpm seed publish cli --ver ${git_version} --dev --log-level debug
# Test prod and try to publish, the publish command will handle if there's no diff
live-test:
@@ -84,6 +88,10 @@ jobs:
- name: Install
uses: ./.github/actions/install

- name: Build Seed
run: |
pnpm seed:build
- name: Publish + Register CLI
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
@@ -93,13 +101,14 @@ jobs:
previous_commit="$(git rev-parse --short HEAD~1)"
echo "Preview of the previous file ${previous_commit}"
head tmp_cli_previous_versions.yml
current_commit="$(git rev-parse --short HEAD)"
echo "Preview of the current file ${current_commit}"
head packages/cli/cli/versions.yml
pnpm seed:local publish cli --changelog packages/cli/cli/versions.yml --previous-changelog tmp_cli_previous_versions.yml --log-level debug
pnpm seed:local register cli
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
pnpm seed publish cli --changelog packages/cli/cli/versions.yml --previous-changelog tmp_cli_previous_versions.yml --log-level debug
pnpm seed register cli
publish-manually:
runs-on: ubuntu-latest
@@ -118,9 +127,14 @@ jobs:
- name: Install
uses: ./.github/actions/install

- name: Build Seed
run: |
pnpm seed:build
- name: Publish + Register CLI
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
run: |
pnpm seed:local publish cli --ver ${{ inputs.version }} --log-level debug
pnpm seed:local register cli
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
pnpm seed publish cli --ver ${{ inputs.version }} --log-level debug
pnpm seed register cli
9 changes: 5 additions & 4 deletions .github/workflows/validate-changelog.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Validate Changelogs
name: Validate Changelog

on:
push:
@@ -13,7 +13,8 @@ concurrency:
cancel-in-progress: true

jobs:
cli-validate:
validate-fern-cli:
name: Fern CLI
runs-on: ubuntu-latest
steps:
- name: Checkout repo at current ref
@@ -28,7 +29,7 @@ jobs:
run: |
pnpm seed:local validate cli --log-level debug
generator-validate:
validate-generators:
strategy:
matrix:
generator: [
@@ -48,7 +49,7 @@ jobs:
php-sdk,
php-model
]

name: ${{ matrix.generator }}
runs-on: ubuntu-latest
steps:
- name: Checkout repo at current ref
1 change: 0 additions & 1 deletion generators/csharp/model/package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"sideEffects": false,
"bin": "./dist/cli.cjs",
"scripts": {
"clean": "rm -rf ./lib && tsc --build --clean",
"compile": "tsc --build",
1 change: 0 additions & 1 deletion generators/php/model/package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"sideEffects": false,
"bin": "./dist/cli.cjs",
"scripts": {
"clean": "rm -rf ./lib && tsc --build --clean",
"compile": "tsc --build",
1 change: 0 additions & 1 deletion generators/php/sdk/package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"sideEffects": false,
"bin": "./dist/cli.cjs",
"scripts": {
"clean": "rm -rf ./lib && tsc --build --clean",
"compile": "tsc --build",
12 changes: 6 additions & 6 deletions generators/python-v2/codegen/src/ast/Reference.ts
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ export declare namespace Reference {
/* The alias of the reference */
alias?: string;
/* The path to the attribute of the reference */
attrPath?: AttrPath;
attribute?: AttrPath;
}
}

@@ -27,15 +27,15 @@ export class Reference extends AstNode {
private modulePath: ModulePath;
private genericTypes: Type[];
private alias: string | undefined;
private attrPath: AttrPath;
private attribute: AttrPath;

constructor({ name, modulePath, genericTypes, alias, attrPath }: Reference.Args) {
constructor({ name, modulePath, genericTypes, alias, attribute }: Reference.Args) {
super();
this.name = name;
this.modulePath = modulePath ?? [];
this.genericTypes = genericTypes ?? [];
this.alias = alias;
this.attrPath = attrPath ?? [];
this.attribute = attribute ?? [];
}

public write(writer: Writer): void {
@@ -52,9 +52,9 @@ export class Reference extends AstNode {
writer.write("]");
}

if (this.attrPath.length > 0) {
if (this.attribute.length > 0) {
writer.write(".");
this.attrPath.forEach((attr, index) => {
this.attribute.forEach((attr, index) => {
if (index > 0) {
writer.write(".");
}
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ describe("PythonFile", () => {
const importedRef = python.reference({
modulePath: ["external_module"],
name: "ImportedClass",
attrPath: ["nested", "attribute"]
attribute: ["nested", "attribute"]
});

const field = python.field({
Original file line number Diff line number Diff line change
@@ -146,7 +146,7 @@ describe("Reference", () => {
const reference = python.reference({
name: "AttrPathClass",
modulePath: ["module"],
attrPath: ["attr1", "attr2"]
attribute: ["attr1", "attr2"]
});
reference.write(writer);
expect(await writer.toStringFormatted()).toMatchSnapshot();
2 changes: 1 addition & 1 deletion generators/python-v2/codegen/src/ast/__test__/Type.test.ts
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ describe("Type", () => {
python.reference({
name: "MyClass",
modulePath: ["module"],
attrPath: ["attr1", "attr2"]
attribute: ["attr1", "attr2"]
})
);
referenceType.write(writer);
1 change: 0 additions & 1 deletion generators/ruby/model/package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"sideEffects": false,
"bin": "./dist/cli.cjs",
"scripts": {
"clean": "rm -rf ./lib && tsc --build --clean",
"compile": "tsc --build",
1 change: 0 additions & 1 deletion generators/ruby/sdk/package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"sideEffects": false,
"bin": "./dist/cli.cjs",
"scripts": {
"clean": "rm -rf ./lib && tsc --build --clean",
"compile": "tsc --build",
10 changes: 5 additions & 5 deletions packages/cli/cli/build.dev.cjs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ async function main() {
DOCS_DOMAIN_SUFFIX: "dev.docs.buildwithfern.com",
DOCS_PREVIEW_BUCKET: 'https://dev2-local-preview-bundle2.s3.amazonaws.com/',
CLI_NAME: "fern-dev",
CLI_VERSION: packageJson.version,
CLI_VERSION: process.argv[2] || packageJson.version,
CLI_PACKAGE_NAME: "@fern-api/fern-api-dev",
},
});
@@ -35,11 +35,11 @@ async function main() {
"package.json",
JSON.stringify(
{
name: "fern-api",
version: packageJson.version,
name: "@fern-api/fern-api-dev",
version: process.argv[2] || packageJson.version,
repository: packageJson.repository,
files: ["bundle.cjs", "cli.cjs"],
bin: { fern: "cli.cjs" }
files: ["cli.cjs"],
bin: { "fern-dev": "cli.cjs" }
},
undefined,
2
6 changes: 3 additions & 3 deletions packages/cli/cli/build.local.cjs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ async function main() {
DOCS_DOMAIN_SUFFIX: "dev.docs.buildwithfern.com",
DOCS_PREVIEW_BUCKET: 'https://dev2-local-preview-bundle2.s3.amazonaws.com/',
CLI_NAME: "fern-local",
CLI_VERSION: packageJson.version,
CLI_VERSION: process.argv[2] || packageJson.version,
CLI_PACKAGE_NAME: "fern-api",
},
});
@@ -36,9 +36,9 @@ async function main() {
JSON.stringify(
{
name: "fern-api",
version: packageJson.version,
version: process.argv[2] || packageJson.version,
repository: packageJson.repository,
files: ["bundle.cjs", "cli.cjs"],
files: ["cli.cjs"],
bin: { fern: "cli.cjs" }
},
undefined,
6 changes: 3 additions & 3 deletions packages/cli/cli/build.prod.cjs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ async function main() {
DOCS_DOMAIN_SUFFIX: "docs.buildwithfern.com",
DOCS_PREVIEW_BUCKET: 'https://prod-local-preview-bundle2.s3.amazonaws.com/',
CLI_NAME: "fern",
CLI_VERSION: packageJson.version,
CLI_VERSION: process.argv[2] || packageJson.version,
CLI_PACKAGE_NAME: "fern-api",
},
});
@@ -36,9 +36,9 @@ async function main() {
JSON.stringify(
{
name: "fern-api",
version: packageJson.version,
version: process.argv[2] || packageJson.version,
repository: packageJson.repository,
files: ["bundle.cjs", "cli.cjs"],
files: ["cli.cjs"],
bin: { fern: "cli.cjs" }
},
undefined,
4 changes: 2 additions & 2 deletions packages/cli/cli/package.json
Original file line number Diff line number Diff line change
@@ -34,8 +34,8 @@
"dist:cli:dev": "pnpm compile && node build.dev.cjs",
"dist:cli:local": "pnpm compile && node build.local.cjs",
"dist:cli:prod": "pnpm compile && node build.prod.cjs",
"publish:cli:dev": "pnpm dist:cli:dev && cd dist/dev && npm publish",
"publish:cli:prod": "pnpm dist:cli:prod && cd dist/prod && npm publish"
"publish:cli:dev": "cd dist/dev && npm publish",
"publish:cli:prod": "cd dist/prod && npm publish"
},
"devDependencies": {
"@fern-api/api-workspace-commons": "workspace:*",
2 changes: 2 additions & 0 deletions packages/cli/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

import {
fernConfigJson,
generatorsYml,
21 changes: 21 additions & 0 deletions packages/cli/cli/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
- 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: |
Stop minifying the CLI to prevent javascript runtime errors.
type: internal
irVersion: 53
version: 0.45.0-rc7

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

- changelogEntry:
- summary: |
Introduce a new command `fern jsonschema <output-file> --type <type-name>`
29 changes: 23 additions & 6 deletions packages/seed/src/utils/publishUtilities.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loggingExeca } from "@fern-api/logging-execa";
import { TaskContext } from "@fern-api/task-context";
import { runScript } from "../runScript";

@@ -8,10 +9,26 @@ export function subVersion(command: string, version: string, versionSubsitution?
}

export async function runCommands(commands: string[], context: TaskContext, cwd: string) {
await runScript({
commands,
doNotPipeOutput: false,
logger: context.logger,
workingDir: cwd
});
for (const command of commands) {
const splitCommand = command.split(" ");
if (splitCommand[0] == null) {
throw new Error(`Failed to run ${command}`);
}
const { exitCode, stdout, stderr } = await loggingExeca(
context.logger,
splitCommand[0],
splitCommand.slice(1),
{
doNotPipeOutput: true,
env: {
...process.env
},
cwd
}
);
if (exitCode !== 0) {
context.logger.error(`Failed to run ${command}\n${stdout}\n${stderr}`);
throw new Error(`Failed to run ${command}`);
}
}
}
17 changes: 3 additions & 14 deletions seed/fern-cli/seed.yml
Original file line number Diff line number Diff line change
@@ -3,35 +3,24 @@ publishGa:
workingDirectory: packages/cli/cli
versionSubstitution: $VERSION
command:
- mv package.json package.json.tmp
- version_replace="s/0.0.0/$VERSION/"
- cat package.json.tmp| sed "${version_replace}" > package.json
- echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- pnpm install
- pnpm --filter @fern-api/cli compile
- pnpm --filter @fern-api/cli dist:cli:prod $VERSION
- pnpm --filter @fern-api/cli publish:cli:prod --tag latest
- mv package.json.tmp package.json
publishRc:
workingDirectory: packages/cli/cli
versionSubstitution: $VERSION
command:
- mv package.json package.json.tmp
- version_replace="s/0.0.0/$VERSION/"
- cat package.json.tmp| sed "${version_replace}" > package.json
- echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- pnpm install
- pnpm --filter @fern-api/cli compile
- pnpm --filter @fern-api/cli dist:cli:prod $VERSION
- pnpm --filter @fern-api/cli publish:cli:prod --tag prerelease
- mv package.json.tmp package.json
publishDev:
workingDirectory: packages/cli/cli
versionSubstitution: $VERSION
command:
- mv package.json package.json.tmp
- version_replace="s/0.0.0/$VERSION/"
- cat package.json.tmp| sed "${version_replace}" > package.json
- echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- pnpm install
- pnpm --filter @fern-api/cli compile
- pnpm --filter @fern-api/cli dist:cli:dev $VERSION
- pnpm --filter @fern-api/cli publish:cli:dev --access restricted
- mv package.json.tmp package.json

0 comments on commit 15de56f

Please sign in to comment.