Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.12"
  17. - run: |
  18. cd api
  19. uv sync --dev
  20. # Fix lint errors
  21. uv run ruff check --fix .
  22. # Format code
  23. uv run ruff format .
  24. - name: ast-grep
  25. run: |
  26. uvx --from ast-grep-cli sg --pattern 'db.session.query($WHATEVER).filter($HERE)' --rewrite 'db.session.query($WHATEVER).where($HERE)' -l py --update-all
  27. uvx --from ast-grep-cli sg --pattern 'session.query($WHATEVER).filter($HERE)' --rewrite 'session.query($WHATEVER).where($HERE)' -l py --update-all
  28. # Convert Optional[T] to T | None (ignoring quoted types)
  29. cat > /tmp/optional-rule.yml << 'EOF'
  30. id: convert-optional-to-union
  31. language: python
  32. rule:
  33. kind: generic_type
  34. all:
  35. - has:
  36. kind: identifier
  37. pattern: Optional
  38. - has:
  39. kind: type_parameter
  40. has:
  41. kind: type
  42. pattern: $T
  43. fix: $T | None
  44. EOF
  45. uvx --from ast-grep-cli sg scan --inline-rules "$(cat /tmp/optional-rule.yml)" --update-all
  46. # Fix forward references that were incorrectly converted (Python doesn't support "Type" | None syntax)
  47. find . -name "*.py" -type f -exec sed -i.bak -E 's/"([^"]+)" \| None/Optional["\1"]/g; s/'"'"'([^'"'"']+)'"'"' \| None/Optional['"'"'\1'"'"']/g' {} \;
  48. find . -name "*.py.bak" -type f -delete
  49. - name: mdformat
  50. run: |
  51. uvx mdformat .
  52. - name: Install pnpm
  53. uses: pnpm/action-setup@v4
  54. with:
  55. package_json_file: web/package.json
  56. run_install: false
  57. - name: Setup NodeJS
  58. uses: actions/setup-node@v4
  59. with:
  60. node-version: 22
  61. cache: pnpm
  62. cache-dependency-path: ./web/package.json
  63. - name: Web dependencies
  64. working-directory: ./web
  65. run: pnpm install --frozen-lockfile
  66. - name: oxlint
  67. working-directory: ./web
  68. run: |
  69. pnpx oxlint --fix
  70. - uses: autofix-ci/action@635ffb0c9798bd160680f18fd73371e355b85f27