Skip to content

Commit

Permalink
improvement(fern-bot): the bot stops using docker to upgrade generato…
Browse files Browse the repository at this point in the history
…rs (#1330)
  • Loading branch information
armandobelardo authored Sep 4, 2024
1 parent 229967e commit c637fde
Show file tree
Hide file tree
Showing 25 changed files with 985 additions and 255 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/deploy-fern-bot-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ env:
GITHUB_APP_CLIENT_SECRET: ${{ secrets.FERN_BOT_DEV_GITHUB_APP_CLIENT_SECRET }}
GITHUB_APP_WEBHOOK_SECRET: ${{ secrets.FERN_BOT_DEV_GITHUB_APP_WEBHOOK_SECRET }}
DEFAULT_VENUS_ORIGIN: "https://venus-dev2.buildwithfern.com"
DEFAULT_FDR_ORIGIN: "https://registry-dev2.buildwithfern.com"
CO_API_KEY: ${{ secrets.DEV_CO_API_KEY }}

jobs:
Expand All @@ -37,4 +38,6 @@ jobs:
- name: 🚀 serverless deploy
env:
CI: false
run: pnpm --filter "@fern-platform/fern-bot" release --stage development
run: |
pnpm --filter "@fern-platform/fern-bot" install
pnpm --filter "@fern-platform/fern-bot" release --stage development
3 changes: 3 additions & 0 deletions .github/workflows/deploy-fern-bot-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
GITHUB_APP_CLIENT_SECRET: ${{ secrets.FERN_BOT_PROD_GITHUB_APP_CLIENT_SECRET }}
GITHUB_APP_WEBHOOK_SECRET: ${{ secrets.FERN_BOT_PROD_GITHUB_APP_WEBHOOK_SECRET }}
DEFAULT_VENUS_ORIGIN: "https://venus.buildwithfern.com"
DEFAULT_FDR_ORIGIN: "https://registry.buildwithfern.com"
CO_API_KEY: ${{ secrets.PROD_CO_API_KEY }}

jobs:
Expand All @@ -35,5 +36,7 @@ jobs:
env:
CI: false
run: |
# Run compile to generate the dist folder for the Github dep
pnpm compile
pnpm --filter "@fern-platform/fern-bot" install
pnpm --filter "@fern-platform/fern-bot" release --stage production
2 changes: 2 additions & 0 deletions .github/workflows/invoke-fern-bot-update-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
GITHUB_APP_CLIENT_SECRET: ${{ secrets.FERN_BOT_DEV_GITHUB_APP_CLIENT_SECRET }}
GITHUB_APP_WEBHOOK_SECRET: ${{ secrets.FERN_BOT_DEV_GITHUB_APP_WEBHOOK_SECRET }}
DEFAULT_VENUS_ORIGIN: "https://venus-dev2.buildwithfern.com"
DEFAULT_FDR_ORIGIN: "https://registry-dev2.buildwithfern.com"
CO_API_KEY: ${{ secrets.DEV_CO_API_KEY }}
REPO_TO_RUN_ON: ${{ github.event.inputs.repo }}
CI: false
Expand Down Expand Up @@ -57,6 +58,7 @@ jobs:
GITHUB_APP_CLIENT_SECRET: ${{ secrets.FERN_BOT_PROD_GITHUB_APP_CLIENT_SECRET }}
GITHUB_APP_WEBHOOK_SECRET: ${{ secrets.FERN_BOT_PROD_GITHUB_APP_WEBHOOK_SECRET }}
DEFAULT_VENUS_ORIGIN: "https://venus.buildwithfern.com"
DEFAULT_FDR_ORIGIN: "https://registry.buildwithfern.com"
CO_API_KEY: ${{ secrets.PROD_CO_API_KEY }}
REPO_TO_RUN_ON: ${{ github.event.inputs.repo }}
CI: false
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/invoke-fern-bot-upgrade-generators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
GITHUB_APP_CLIENT_SECRET: ${{ secrets.FERN_BOT_DEV_GITHUB_APP_CLIENT_SECRET }}
GITHUB_APP_WEBHOOK_SECRET: ${{ secrets.FERN_BOT_DEV_GITHUB_APP_WEBHOOK_SECRET }}
DEFAULT_VENUS_ORIGIN: "https://venus-dev2.buildwithfern.com"
DEFAULT_FDR_ORIGIN: "https://registry-dev2.buildwithfern.com"
CO_API_KEY: ${{ secrets.DEV_CO_API_KEY }}
REPO_TO_RUN_ON: ${{ github.event.inputs.repo }}
steps:
Expand Down Expand Up @@ -56,6 +57,7 @@ jobs:
GITHUB_APP_CLIENT_SECRET: ${{ secrets.FERN_BOT_PROD_GITHUB_APP_CLIENT_SECRET }}
GITHUB_APP_WEBHOOK_SECRET: ${{ secrets.FERN_BOT_PROD_GITHUB_APP_WEBHOOK_SECRET }}
DEFAULT_VENUS_ORIGIN: "https://venus.buildwithfern.com"
DEFAULT_FDR_ORIGIN: "https://registry.buildwithfern.com"
CO_API_KEY: ${{ secrets.PROD_CO_API_KEY }}
REPO_TO_RUN_ON: ${{ github.event.inputs.repo }}
steps:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test-fern-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ env:
GITHUB_APP_CLIENT_SECRET: ${{ secrets.FERN_BOT_DEV_GITHUB_APP_CLIENT_SECRET }}
GITHUB_APP_WEBHOOK_SECRET: ${{ secrets.FERN_BOT_DEV_GITHUB_APP_WEBHOOK_SECRET }}
DEFAULT_VENUS_ORIGIN: "https://venus-dev2.buildwithfern.com"
DEFAULT_FDR_ORIGIN: "https://registry-dev2.buildwithfern.com"
CO_API_KEY: ${{ secrets.DEV_CO_API_KEY }}

jobs:
Expand Down Expand Up @@ -50,3 +51,8 @@ jobs:
pnpm --filter "@fern-platform/fern-bot" invoke local --function updateRepoDataset --stage development
pnpm --filter "@fern-platform/fern-bot" invoke local --function updateOpenApiSpec --stage development
pnpm --filter "@fern-platform/fern-bot" invoke local --function updateOpenApiSpecs --stage development
- name: 🧪 Test
env:
CI: false
run: pnpm --filter "@fern-platform/fern-bot" test:ete
20 changes: 20 additions & 0 deletions packages/commons/github/src/deleteBranch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable no-console */
import { SimpleGit } from "simple-git";
import { DEFAULT_REMOTE_NAME } from "./constants";

export async function deleteBranch(git: SimpleGit, branchToDeleteName: string): Promise<void> {
await git.fetch(DEFAULT_REMOTE_NAME, branchToDeleteName);
const deleteResult = await git.branch(["-D", branchToDeleteName]);
// For some reason the API is not typed to return this, but the documentation
// says that it can return a BranchSingleDeleteResult, which is an interface, so we
// cannot do an instance check:
// https://www.npmjs.com/package/simple-git#git-branch
if ("success" in deleteResult) {
console.log(`Deleted branch ${branchToDeleteName}`);
if (deleteResult.success !== true) {
throw new Error("Failed to delete branch, received a failure response: " + JSON.stringify(deleteResult));
}
} else {
throw new Error("Failed to delete branch, received an unexpected response: " + JSON.stringify(deleteResult));
}
}
4 changes: 2 additions & 2 deletions packages/commons/github/src/getOrUpdateBranch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function getOrUpdateBranch(
try {
// If you can fetch the branch, checkout the branch
await git.fetch(DEFAULT_REMOTE_NAME, branchToCheckoutName);
console.log("Branch exists, checking out");
console.log(`Branch (${branchToCheckoutName}) exists, checking out`);
await git.checkout(branchToCheckoutName);
// Merge the default branch into this branch to update it
// prefer the default branch changes
Expand All @@ -20,7 +20,7 @@ export async function getOrUpdateBranch(
// to the same branch that are not OpenAPI related, that we'd lose if we deleted and reupdated the spec.
await git.merge(["-X", "theirs", defaultBranchName]);
} catch (e) {
console.log("Branch does not exist, create and checkout");
console.log(`Branch (${branchToCheckoutName}) does not exist, create and checkout`);
await git.checkoutBranch(branchToCheckoutName, defaultBranchName);
}
}
1 change: 1 addition & 0 deletions packages/commons/github/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { cloneRepository } from "./cloneRepository";
export { createOrUpdatePullRequest } from "./createOrUpdatePullRequest";
export { deleteBranch } from "./deleteBranch";
export { getLatestTag } from "./getLatestTag";
export { getOrUpdateBranch } from "./getOrUpdateBranch";
export { parseRepository } from "./parseRepository";
Loading

0 comments on commit c637fde

Please sign in to comment.