Skip to content

Commit fa2d4b5

Browse files
committed
chore: update generate-client workflow for improved commit handling
- Modified the workflow to trigger on closed pull requests and pushes to the main branch. - Added a new job for auto-committing changes with a timestamped message, enhancing clarity in generated client updates. - Configured Git user settings for the auto-commit step to ensure proper authentication during pushes.
1 parent bf29bdd commit fa2d4b5

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

.github/workflows/generate-client.yml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
name: Generate Client
33

44
on:
5-
pull_request:
6-
types: [opened, synchronize]
75
push:
86
branches: [main]
7+
pull_request:
8+
types: [closed]
99

1010
permissions:
1111
contents: write
1212

1313
jobs:
1414
generate-client:
15+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
1516
runs-on: ubuntu-latest
1617

1718
steps:
@@ -73,34 +74,32 @@ jobs:
7374
POSTHOG_HOST: ""
7475
VIRTUAL_ENV: .venv
7576

76-
- name: Configure Git User
77-
run: |
78-
git config --global user.email "[email protected]"
79-
git config --global user.name "GitHub Actions"
80-
8177
- name: Stage Generated Files
8278
run: |
8379
git add frontend/app/openapi-client
8480
git add admin/src/client
8581
86-
# 7. Handle Changes for Same-Repo Events (Push/PR from same repo)
87-
- name: Commit and Push Changes (Same Repo)
88-
# Run only if it's NOT a PR from a fork
89-
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
82+
auto-commit-push:
83+
needs: generate-client
84+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
85+
runs-on: ubuntu-latest
86+
steps:
87+
- name: Checkout Code
88+
uses: actions/checkout@v4
89+
90+
- name: Setup Git User
9091
run: |
91-
if ! git diff --staged --quiet; then
92-
echo "✅ Changes detected in generated client. Committing and pushing..."
93-
git pull --rebase origin ${{ github.head_ref || github.ref_name }}
94-
if ! git diff --quiet || ! git diff --staged --quiet; then
95-
git commit -a -m "ci: ✨ Autogenerate frontend client"
96-
git push origin HEAD:${{ github.head_ref || github.ref_name }}
97-
else
98-
echo "✅ No changes to commit after rebase."
99-
git push origin HEAD:${{ github.head_ref || github.ref_name }}
100-
else
101-
echo "✅ No changes detected in generated client."
92+
git config --local user.email "[email protected]"
93+
git config --local user.name "kubbot"
94+
git remote set-url origin https://${{ secrets.BOT_GITHUB_TOKEN }}@github.com/${{ github.repository }}
95+
96+
- name: Commit and Push Changes (Auto Green)
97+
run: |
98+
git pull --rebase
99+
local_time=$(date -u -d "$(date -u)" "+%Y-%m-%d %H:%M:%S" -d "8 hours")
100+
git commit --allow-empty -a -s -m "ci: ✨ Autogenerate frontend client ($local_time)"
101+
git push
102102
env:
103-
# GITHUB_TOKEN has write permissions for same-repo events by default
104103
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
105104

106105
# 8. Handle Changes for Fork PRs (Warn, Don't Fail)

0 commit comments

Comments
 (0)