mirror of
https://github.com/langgenius/dify.git
synced 2026-03-14 03:18:36 +08:00
115 lines
4.3 KiB
YAML
115 lines
4.3 KiB
YAML
name: autofix.ci
|
|
on:
|
|
pull_request:
|
|
branches: ["main"]
|
|
push:
|
|
branches: ["main"]
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
autofix:
|
|
if: github.repository == 'langgenius/dify'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
|
|
- name: Check Docker Compose inputs
|
|
id: docker-compose-changes
|
|
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
|
|
with:
|
|
files: |
|
|
docker/generate_docker_compose
|
|
docker/.env.example
|
|
docker/docker-compose-template.yaml
|
|
docker/docker-compose.yaml
|
|
- name: Check web inputs
|
|
id: web-changes
|
|
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
|
|
with:
|
|
files: |
|
|
web/**
|
|
- name: Check api inputs
|
|
id: api-changes
|
|
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
|
|
with:
|
|
files: |
|
|
api/**
|
|
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
|
with:
|
|
python-version: "3.11"
|
|
|
|
- uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
|
|
|
|
- name: Generate Docker Compose
|
|
if: steps.docker-compose-changes.outputs.any_changed == 'true'
|
|
run: |
|
|
cd docker
|
|
./generate_docker_compose
|
|
|
|
- if: steps.api-changes.outputs.any_changed == 'true'
|
|
run: |
|
|
cd api
|
|
uv sync --dev
|
|
# fmt first to avoid line too long
|
|
uv run ruff format ..
|
|
# Fix lint errors
|
|
uv run ruff check --fix .
|
|
# Format code
|
|
uv run ruff format ..
|
|
|
|
- name: count migration progress
|
|
if: steps.api-changes.outputs.any_changed == 'true'
|
|
run: |
|
|
cd api
|
|
./cnt_base.sh
|
|
|
|
- name: ast-grep
|
|
if: steps.api-changes.outputs.any_changed == 'true'
|
|
run: |
|
|
# ast-grep exits 1 if no matches are found; allow idempotent runs.
|
|
uvx --from ast-grep-cli ast-grep --pattern 'db.session.query($WHATEVER).filter($HERE)' --rewrite 'db.session.query($WHATEVER).where($HERE)' -l py --update-all || true
|
|
uvx --from ast-grep-cli ast-grep --pattern 'session.query($WHATEVER).filter($HERE)' --rewrite 'session.query($WHATEVER).where($HERE)' -l py --update-all || true
|
|
uvx --from ast-grep-cli ast-grep -p '$A = db.Column($$$B)' -r '$A = mapped_column($$$B)' -l py --update-all || true
|
|
uvx --from ast-grep-cli ast-grep -p '$A : $T = db.Column($$$B)' -r '$A : $T = mapped_column($$$B)' -l py --update-all || true
|
|
# Convert Optional[T] to T | None (ignoring quoted types)
|
|
cat > /tmp/optional-rule.yml << 'EOF'
|
|
id: convert-optional-to-union
|
|
language: python
|
|
rule:
|
|
kind: generic_type
|
|
all:
|
|
- has:
|
|
kind: identifier
|
|
pattern: Optional
|
|
- has:
|
|
kind: type_parameter
|
|
has:
|
|
kind: type
|
|
pattern: $T
|
|
fix: $T | None
|
|
EOF
|
|
uvx --from ast-grep-cli ast-grep scan . --inline-rules "$(cat /tmp/optional-rule.yml)" --update-all
|
|
# Fix forward references that were incorrectly converted (Python doesn't support "Type" | None syntax)
|
|
find . -name "*.py" -type f -exec sed -i.bak -E 's/"([^"]+)" \| None/Optional["\1"]/g; s/'"'"'([^'"'"']+)'"'"' \| None/Optional['"'"'\1'"'"']/g' {} \;
|
|
find . -name "*.py.bak" -type f -delete
|
|
|
|
# mdformat breaks YAML front matter in markdown files. Add --exclude for directories containing YAML front matter.
|
|
- name: mdformat
|
|
run: |
|
|
uvx --python 3.13 mdformat . --exclude ".agents/skills/**"
|
|
|
|
- name: Setup web environment
|
|
if: steps.web-changes.outputs.any_changed == 'true'
|
|
uses: ./.github/actions/setup-web
|
|
with:
|
|
node-version: "24"
|
|
|
|
- name: ESLint autofix
|
|
if: steps.web-changes.outputs.any_changed == 'true'
|
|
run: |
|
|
cd web
|
|
pnpm eslint --concurrency=2 --prune-suppressions --quiet || true
|
|
|
|
- uses: autofix-ci/action@7a166d7532b277f34e16238930461bf77f9d7ed8 # v1.3.3
|