Skip to content

Commit 8d11df1

Browse files
committed
ci: handle case where generate.yml fails better
1 parent ecc5050 commit 8d11df1

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

.github/workflows/generate.yml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
runs-on: blacksmith-4vcpu-ubuntu-2404
1515
permissions:
1616
contents: write
17+
pull-requests: write
1718
steps:
1819
- name: Checkout repository
1920
uses: actions/checkout@v4
@@ -25,14 +26,30 @@ jobs:
2526
- name: Setup Bun
2627
uses: ./.github/actions/setup-bun
2728

28-
- name: Generate SDK
29+
- name: Generate
30+
run: ./script/generate.ts
31+
32+
- name: Commit and push
33+
id: push
2934
run: |
30-
bun ./packages/sdk/js/script/build.ts
31-
(cd packages/opencode && bun dev generate > ../sdk/openapi.json)
32-
bun x prettier --write packages/sdk/openapi.json
35+
if [ -z "$(git status --porcelain)" ]; then
36+
echo "No changes to commit"
37+
exit 0
38+
fi
39+
git config --local user.email "action@github.com"
40+
git config --local user.name "GitHub Action"
41+
git add -A
42+
git commit -m "chore: generate"
43+
git push origin HEAD:${{ github.event.pull_request.head.ref || github.ref_name }} --no-verify
3344
34-
- name: Format
35-
run: ./script/format.ts
45+
- name: Comment on failure
46+
if: failure()
47+
run: |
48+
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```'
49+
if [ -n "${{ github.event.pull_request.number }}" ]; then
50+
gh pr comment ${{ github.event.pull_request.number }} --body "$MESSAGE"
51+
else
52+
gh api repos/${{ github.repository }}/commits/${{ github.sha }}/comments -f body="$MESSAGE"
53+
fi
3654
env:
37-
CI: true
38-
PUSH_BRANCH: ${{ github.event.pull_request.head.ref || github.ref_name }}
55+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

script/format.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,3 @@
33
import { $ } from "bun"
44

55
await $`bun run prettier --ignore-unknown --write .`
6-
7-
if (process.env["CI"] && (await $`git status --porcelain`.text())) {
8-
await $`git config --local user.email "action@github.com"`
9-
await $`git config --local user.name "GitHub Action"`
10-
await $`git add -A`
11-
await $`git commit -m "chore: format code"`
12-
const branch = process.env["PUSH_BRANCH"]
13-
await $`git push origin HEAD:${branch} --no-verify`
14-
}

script/generate.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bun
2+
3+
import { $ } from "bun"
4+
5+
// Build SDK
6+
await $`bun ./packages/sdk/js/script/build.ts`
7+
8+
// Generate openapi.json
9+
await $`bun dev generate > ../sdk/openapi.json`.cwd("packages/opencode")
10+
11+
// Format
12+
await $`./script/format.ts`

0 commit comments

Comments
 (0)