@@ -3,37 +3,28 @@ name: Generate Client
3
3
4
4
on :
5
5
pull_request :
6
- types :
7
- - opened
8
- - synchronize
9
- push : # Also consider running on push to main/main to ensure consistency
10
- branches :
11
- - main # Or your default branch
6
+ types : [opened, synchronize]
7
+ push :
8
+ branches : [main]
12
9
13
10
permissions :
14
- contents : write # Needed for pushing commits on same-repo events
11
+ contents : write
15
12
16
13
jobs :
17
14
generate-client :
18
15
runs-on : ubuntu-latest
16
+
19
17
steps :
20
- # 1. Checkout Code - Single step handles both fork and same-repo PRs/pushes
21
18
- name : Checkout Code
22
19
uses : actions/checkout@v4
23
- # Fetch depth 0 is needed for accurate diff/commit history if required elsewhere
24
- # For pushing back, fetch the specific ref for same-repo PRs
25
20
with :
26
21
ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository && github.head_ref || '' }}
27
- # Use a PAT for same-repo events if you need to trigger other workflows
28
- # Standard GITHUB_TOKEN is often sufficient for basic pushes
29
- # token: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && secrets.YOUR_PAT_OR_GITHUB_TOKEN || '' }}
30
22
31
- # 2. Setup Environment
32
23
- name : Setup pnpm
33
24
uses : pnpm/action-setup@v3
34
25
with :
35
26
version : 9.9.0
36
-
27
+
37
28
- name : Setup Node.js
38
29
uses : actions/setup-node@v4
39
30
with :
@@ -46,34 +37,27 @@ jobs:
46
37
with :
47
38
python-version : " 3.10"
48
39
49
- - name : Install uv (Python Package Installer)
50
- uses : astral-sh/setup-uv@v1 # Use v1 for stable release
40
+ - name : Install uv
41
+ uses : astral-sh/setup-uv@v1
51
42
with :
52
- # version: "0.4.15" # Specifying version is optional, can use latest stable
53
43
enable-cache : true
54
44
55
- # 3. Install Dependencies
56
45
- name : Install Frontend Dependencies
57
46
run : pnpm install
58
47
working-directory : frontend
59
-
48
+
60
49
- name : Install Admin Dependencies
61
50
run : pnpm install
62
51
working-directory : admin
63
52
64
- # 安装所有后端依赖项
65
53
- name : Install Backend Dependencies
66
54
run : |
67
55
uv sync
68
56
source .venv/bin/activate
69
57
pip install .
70
58
working-directory : backend
71
59
72
- # 4. Run Generation Script with Error Handling
73
60
- name : Generate Client
74
- # Use `uv run` to execute within the backend context if needed,
75
- # or just run the script directly if VIRTUAL_ENV isn't strictly necessary
76
- # for the script itself (it might just need python)
77
61
run : |
78
62
make generate-client || {
79
63
echo "❌ Failed to run generate-client.sh script."
@@ -87,54 +71,39 @@ jobs:
87
71
SENTRY_DSN : " "
88
72
POSTHOG_API_KEY : " "
89
73
POSTHOG_HOST : " "
90
- # VIRTUAL_ENV might not be needed if uv sync --system is used
91
74
VIRTUAL_ENV : .venv
92
75
93
- # 5. Configure Git User
94
76
- name : Configure Git User
95
77
run : |
96
- git config --local user.email "github-actions[bot]@users.noreply. github.com"
97
- git config --local user.name "github-actions[bot] "
78
+ git config --global user.email "github-actions@ github.com"
79
+ git config --global user.name "GitHub Actions "
98
80
99
- # 6. Stage Generated Files
100
- - name : Stage Generated Client Files
81
+ - name : Stage Generated Files
101
82
run : |
102
83
git add frontend/app/openapi-client
103
84
git add admin/src/client
104
85
105
- # 7. Handle Changes for Same-Repo Events (Push/PR from same repo)
106
86
- name : Commit and Push Changes (Same Repo)
107
- # Run only if it's NOT a PR from a fork
108
87
if : github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
109
88
run : |
110
- # Check if there are staged changes
111
- if ! git diff --staged --quiet; then
89
+ BRANCH_NAME="${{ github.head_ref || github.ref_name }}"
90
+ if ! git diff --quiet || ! git diff -- staged --quiet; then
112
91
echo "✅ Changes detected in generated client. Committing and pushing..."
113
- # Pull before pushing to avoid conflicts
114
- git pull --rebase origin ${{ github.head_ref || github.ref_name }}
92
+ git add .
93
+ git pull --rebase origin "$BRANCH_NAME" || true
115
94
git commit -m "ci: ✨ Autogenerate frontend client"
116
- git push origin HEAD:${{ github.head_ref || github.ref_name }}
95
+ git push origin HEAD:"$BRANCH_NAME"
117
96
else
118
97
echo "✅ No changes detected in generated client."
119
98
fi
120
99
env :
121
- # GITHUB_TOKEN has write permissions for same-repo events by default
122
100
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
123
- # Use a PAT if you need to trigger subsequent workflows:
124
- # GITHUB_TOKEN: ${{ secrets.YOUR_PAT_WITH_WRITE_ACCESS }}
125
101
126
- # 8. Handle Changes for Fork PRs (Warn, Don't Fail)
127
102
- name : Check for Uncommitted Changes (Fork PRs)
128
- # Run only if it IS a PR from a fork
129
103
if : github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
130
104
run : |
131
- # Check if there are staged changes that were generated
132
105
if ! git diff --staged --quiet; then
133
- echo "⚠️ Changes detected in generated client."
134
- echo "➡️ Please run 'bash scripts/generate-client.sh' locally and commit the changes to this PR."
135
- # Optionally, use GitHub annotations for better visibility in the PR
136
106
echo "::warning title=Generated Client Changes Detected::Please run 'bash scripts/generate-client.sh' locally and commit the changes to this PR."
137
- # DO NOT exit 1 - Allow the workflow to continue
138
107
else
139
108
echo "✅ No changes detected in generated client."
140
- fi
109
+ fi
0 commit comments