generate.yml 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. name: generate
  2. on:
  3. push:
  4. branches-ignore:
  5. - production
  6. pull_request:
  7. branches-ignore:
  8. - production
  9. workflow_dispatch:
  10. jobs:
  11. generate:
  12. runs-on: blacksmith-4vcpu-ubuntu-2404
  13. permissions:
  14. contents: write
  15. pull-requests: write
  16. steps:
  17. - name: Checkout repository
  18. uses: actions/checkout@v4
  19. with:
  20. token: ${{ secrets.GITHUB_TOKEN }}
  21. repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
  22. ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
  23. - name: Setup Bun
  24. uses: ./.github/actions/setup-bun
  25. - name: Generate
  26. run: ./script/generate.ts
  27. - name: Commit and push
  28. id: push
  29. run: |
  30. if [ -z "$(git status --porcelain)" ]; then
  31. echo "No changes to commit"
  32. exit 0
  33. fi
  34. git config --local user.email "action@github.com"
  35. git config --local user.name "GitHub Action"
  36. git add -A
  37. git commit -m "chore: generate"
  38. git push origin HEAD:${{ github.event.pull_request.head.ref || github.ref_name }} --no-verify
  39. - name: Comment on failure
  40. if: failure()
  41. run: |
  42. 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```'
  43. if [ -n "${{ github.event.pull_request.number }}" ]; then
  44. gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --body "$MESSAGE"
  45. else
  46. gh api repos/${{ github.repository }}/commits/${{ github.sha }}/comments -f body="$MESSAGE"
  47. fi
  48. env:
  49. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}