The open source coding agent.
TypeScript
ci: handle case where generate.yml fails better
Aiden Cline8d11df1b3b9e
diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.ymlindex 326090f7a24..4836a78d6e5 100644--- a/.github/workflows/generate.yml+++ b/.github/workflows/generate.yml@@ -14,6 +14,7 @@ jobs:runs-on: blacksmith-4vcpu-ubuntu-2404permissions:contents: write+ pull-requests: writesteps:- name: Checkout repositoryuses: actions/checkout@v4@@ -25,14 +26,30 @@ jobs:- name: Setup Bunuses: ./.github/actions/setup-bun- - name: Generate SDK+ - name: Generate+ run: ./script/generate.ts++ - name: Commit and push+ id: pushrun: |- bun ./packages/sdk/js/script/build.ts- (cd packages/opencode && bun dev generate > ../sdk/openapi.json)- bun x prettier --write packages/sdk/openapi.json+ if [ -z "$(git status --porcelain)" ]; then+ echo "No changes to commit"+ exit 0+ fi+ git config --local user.email "[email protected]"+ git config --local user.name "GitHub Action"+ git add -A+ git commit -m "chore: generate"+ git push origin HEAD:${{ github.event.pull_request.head.ref || github.ref_name }} --no-verify- - name: Format- run: ./script/format.ts+ - name: Comment on failure+ if: failure()+ run: |+ MESSAGE=$'Failed to push generated code. Please run locally and push:\n```\n./script/generate.ts\ngit add -A && git commit -m "chore: generate" && git push\n```'+ if [ -n "${{ github.event.pull_request.number }}" ]; then+ gh pr comment ${{ github.event.pull_request.number }} --body "$MESSAGE"+ else+ gh api repos/${{ github.repository }}/commits/${{ github.sha }}/comments -f body="$MESSAGE"+ fienv:- CI: true- PUSH_BRANCH: ${{ github.event.pull_request.head.ref || github.ref_name }}+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}diff --git a/script/format.ts b/script/format.tsindex 2ae93f169cc..996de9ad04a 100755--- a/script/format.ts+++ b/script/format.ts@@ -3,12 +3,3 @@import { $ } from "bun"await $`bun run prettier --ignore-unknown --write .`--if (process.env["CI"] && (await $`git status --porcelain`.text())) {- await $`git config --local user.email "[email protected]"`- await $`git config --local user.name "GitHub Action"`- await $`git add -A`- await $`git commit -m "chore: format code"`- const branch = process.env["PUSH_BRANCH"]- await $`git push origin HEAD:${branch} --no-verify`-}diff --git a/script/generate.ts b/script/generate.tsnew file mode 100644index 00000000000..6a040e2e4ce--- /dev/null+++ b/script/generate.ts@@ -0,0 +1,12 @@+#!/usr/bin/env bun++import { $ } from "bun"++// Build SDK+await $`bun ./packages/sdk/js/script/build.ts`++// Generate openapi.json+await $`bun dev generate > ../sdk/openapi.json`.cwd("packages/opencode")++// Format+await $`./script/format.ts`