opencode/.github/workflows/generate.yml
2025-12-18 15:23:23 -06:00

55 lines
1.8 KiB
YAML

name: generate
on:
push:
branches-ignore:
- production
pull_request:
branches-ignore:
- production
workflow_dispatch:
jobs:
generate:
runs-on: blacksmith-4vcpu-ubuntu-2404
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
- name: Setup Bun
uses: ./.github/actions/setup-bun
- name: Generate
run: ./script/generate.ts
- name: Commit and push
id: push
run: |
if [ -z "$(git status --porcelain)" ]; then
echo "No changes to commit"
exit 0
fi
git config --local user.email "action@github.com"
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: 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 }} --repo ${{ github.repository }} --body "$MESSAGE"
else
gh api repos/${{ github.repository }}/commits/${{ github.sha }}/comments -f body="$MESSAGE"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}