You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

autofix.yml 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. name: autofix.ci
  2. on:
  3. pull_request:
  4. branches: ["main"]
  5. permissions:
  6. contents: read
  7. jobs:
  8. autofix:
  9. if: github.repository == 'langgenius/dify'
  10. runs-on: ubuntu-latest
  11. steps:
  12. - uses: actions/checkout@v4
  13. # Use uv to ensure we have the same ruff version in CI and locally.
  14. - uses: astral-sh/setup-uv@v6
  15. with:
  16. python-version: "3.11"
  17. - run: |
  18. cd api
  19. uv sync --dev
  20. # fmt first to avoid line too long
  21. uv run ruff format ..
  22. # Fix lint errors
  23. uv run ruff check --fix .
  24. # Format code
  25. uv run ruff format ..
  26. - name: ast-grep
  27. run: |
  28. uvx --from ast-grep-cli sg --pattern 'db.session.query($WHATEVER).filter($HERE)' --rewrite 'db.session.query($WHATEVER).where($HERE)' -l py --update-all
  29. uvx --from ast-grep-cli sg --pattern 'session.query($WHATEVER).filter($HERE)' --rewrite 'session.query($WHATEVER).where($HERE)' -l py --update-all
  30. # Convert Optional[T] to T | None (ignoring quoted types)
  31. cat > /tmp/optional-rule.yml << 'EOF'
  32. id: convert-optional-to-union
  33. language: python
  34. rule:
  35. kind: generic_type
  36. all:
  37. - has:
  38. kind: identifier
  39. pattern: Optional
  40. - has:
  41. kind: type_parameter
  42. has:
  43. kind: type
  44. pattern: $T
  45. fix: $T | None
  46. EOF
  47. uvx --from ast-grep-cli sg scan --inline-rules "$(cat /tmp/optional-rule.yml)" --update-all
  48. # Fix forward references that were incorrectly converted (Python doesn't support "Type" | None syntax)
  49. find . -name "*.py" -type f -exec sed -i.bak -E 's/"([^"]+)" \| None/Optional["\1"]/g; s/'"'"'([^'"'"']+)'"'"' \| None/Optional['"'"'\1'"'"']/g' {} \;
  50. find . -name "*.py.bak" -type f -delete
  51. - name: mdformat
  52. run: |
  53. uvx mdformat .
  54. - name: Install pnpm
  55. uses: pnpm/action-setup@v4
  56. with:
  57. package_json_file: web/package.json
  58. run_install: false
  59. - name: Setup NodeJS
  60. uses: actions/setup-node@v4
  61. with:
  62. node-version: 22
  63. cache: pnpm
  64. cache-dependency-path: ./web/package.json
  65. - name: Web dependencies
  66. working-directory: ./web
  67. run: pnpm install --frozen-lockfile
  68. - name: oxlint
  69. working-directory: ./web
  70. run: |
  71. pnpx oxlint --fix
  72. - uses: autofix-ci/action@635ffb0c9798bd160680f18fd73371e355b85f27