1+ name : Main CI Pipeline
2+
3+ on :
4+ pull_request :
5+ branches : [ "main" ]
6+
7+ permissions :
8+ contents : write
9+ pull-requests : write
10+ checks : write
11+
12+ concurrency :
13+ group : main-ci-${{ github.head_ref || github.run_id }}
14+ cancel-in-progress : true
15+
16+ jobs :
17+ # First, run autofix if needed
18+ autofix :
19+ name : Auto-fix code issues
20+ if : github.repository == 'langgenius/dify'
21+ runs-on : ubuntu-latest
22+ outputs :
23+ changes-made : ${{ steps.check-changes.outputs.changes }}
24+ steps :
25+ - uses : actions/checkout@v4
26+ with :
27+ token : ${{ secrets.GITHUB_TOKEN }}
28+ ref : ${{ github.event.pull_request.head.ref }}
29+
30+ - uses : astral-sh/setup-uv@v6
31+ with :
32+ python-version : " 3.12"
33+
34+ - name : Run Python fixes
35+ run : |
36+ cd api
37+ uv sync --dev
38+ # Fix lint errors
39+ uv run ruff check --fix-only .
40+ # Format code
41+ uv run ruff format .
42+
43+ - name : Run ast-grep
44+ run : |
45+ uvx --from ast-grep-cli sg --pattern 'db.session.query($WHATEVER).filter($HERE)' --rewrite 'db.session.query($WHATEVER).where($HERE)' -l py --update-all
46+
47+ - name : Run mdformat
48+ run : |
49+ uvx mdformat .
50+
51+ - name : Check for changes
52+ id : check-changes
53+ run : |
54+ if [ -n "$(git diff --name-only)" ]; then
55+ echo "changes=true" >> $GITHUB_OUTPUT
56+ else
57+ echo "changes=false" >> $GITHUB_OUTPUT
58+ fi
59+
60+ - name : Commit and push changes
61+ if : steps.check-changes.outputs.changes == 'true'
62+ run : |
63+ git config --local user.email "action@github.com"
64+ git config --local user.name "GitHub Action"
65+ git add -A
66+ git commit -m "Auto-fix: Apply code formatting and linting fixes"
67+ git push
68+
69+ # Check which paths were changed to determine which tests to run
70+ check-changes :
71+ name : Check Changed Files
72+ runs-on : ubuntu-latest
73+ outputs :
74+ api-changed : ${{ steps.changes.outputs.api }}
75+ web-changed : ${{ steps.changes.outputs.web }}
76+ vdb-changed : ${{ steps.changes.outputs.vdb }}
77+ migration-changed : ${{ steps.changes.outputs.migration }}
78+ steps :
79+ - uses : actions/checkout@v4
80+ - uses : dorny/paths-filter@v3
81+ id : changes
82+ with :
83+ filters : |
84+ api:
85+ - 'api/**'
86+ - 'docker/**'
87+ - '.github/workflows/api-tests.yml'
88+ web:
89+ - 'web/**'
90+ vdb:
91+ - 'api/core/rag/datasource/**'
92+ - 'docker/**'
93+ - '.github/workflows/vdb-tests.yml'
94+ - 'api/uv.lock'
95+ - 'api/pyproject.toml'
96+ migration:
97+ - 'api/migrations/**'
98+ - '.github/workflows/db-migration-test.yml'
99+
100+ # After autofix completes (or if no changes needed), run tests in parallel
101+ api-tests :
102+ name : API Tests
103+ needs : [autofix, check-changes]
104+ if : always() && !cancelled() && needs.check-changes.outputs.api-changed == 'true'
105+ uses : ./.github/workflows/api-tests.yml
106+
107+ web-tests :
108+ name : Web Tests
109+ needs : [autofix, check-changes]
110+ if : always() && !cancelled() && needs.check-changes.outputs.web-changed == 'true'
111+ uses : ./.github/workflows/web-tests.yml
112+
113+ style-check :
114+ name : Style Check
115+ needs : autofix
116+ if : always() && !cancelled()
117+ uses : ./.github/workflows/style.yml
118+
119+ vdb-tests :
120+ name : VDB Tests
121+ needs : [autofix, check-changes]
122+ if : always() && !cancelled() && needs.check-changes.outputs.vdb-changed == 'true'
123+ uses : ./.github/workflows/vdb-tests.yml
124+
125+ db-migration-test :
126+ name : DB Migration Test
127+ needs : [autofix, check-changes]
128+ if : always() && !cancelled() && needs.check-changes.outputs.migration-changed == 'true'
129+ uses : ./.github/workflows/db-migration-test.yml
0 commit comments