name: Translate on: schedule: - cron: "0 5 1,15 * *" # Run at 05:00 on the 1st and 15th of every month workflow_dispatch: inputs: debug_enabled: description: Run with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate) required: false default: "false" command: description: Command to run type: choice options: - translate-page - translate-lang - update-outdated - add-missing - update-and-add - remove-removable language: description: Language to translate to as a letter code (e.g. "es" for Spanish) type: string required: false default: "" en_path: description: File path in English to translate (e.g. docs/en/docs/index.md) type: string required: false default: "" commit_in_place: description: Commit changes directly instead of making a PR type: boolean required: false default: false max: description: Maximum number of items to translate (e.g. 10) type: number required: false default: 10 permissions: {} jobs: langs: runs-on: ubuntu-latest outputs: langs: ${{ steps.show-langs.outputs.langs }} commands: ${{ steps.show-langs.outputs.commands }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false - name: Set up Python uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version-file: ".python-version" - name: Setup uv uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0 with: version: "0.11.4" cache-dependency-glob: | pyproject.toml uv.lock - name: Install Dependencies run: uv sync --locked --no-dev --group github-actions --group translations - name: Export Language Codes id: show-langs run: | echo "langs=$(uv run ./scripts/translate.py llm-translatable-json)" >> $GITHUB_OUTPUT echo "commands=$(uv run ./scripts/translate.py commands-json)" >> $GITHUB_OUTPUT env: LANGUAGE: ${{ github.event.inputs.language }} COMMAND: ${{ github.event.inputs.command }} translate: if: github.repository_owner == 'fastapi' needs: langs runs-on: ubuntu-latest strategy: matrix: lang: ${{ fromJson(needs.langs.outputs.langs) }} command: ${{ fromJson(needs.langs.outputs.commands) }} steps: - name: Dump GitHub context env: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: fetch-depth: 0 persist-credentials: false - name: Set up Python uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version-file: ".python-version" - name: Setup uv uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0 with: version: "0.11.4" cache-dependency-glob: | pyproject.toml uv.lock - name: Install Dependencies run: uv sync --locked --no-dev --group github-actions --group translations # Allow debugging with tmate - name: Setup tmate session uses: mxschmitt/action-tmate@c0afd6f790e3a5564914980036ebf83216678101 # v3.23 if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true' }} with: limit-access-to-actor: true env: GITHUB_TOKEN: ${{ secrets.FASTAPI_TRANSLATIONS }} # zizmor: ignore[secrets-outside-env] OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} # zizmor: ignore[secrets-outside-env] - name: FastAPI Translate run: | uv run ./scripts/translate.py "$COMMAND" uv run ./scripts/translate.py make-pr env: GITHUB_TOKEN: ${{ secrets.FASTAPI_TRANSLATIONS }} # zizmor: ignore[secrets-outside-env] OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} # zizmor: ignore[secrets-outside-env] LANGUAGE: ${{ matrix.lang }} EN_PATH: ${{ github.event.inputs.en_path }} COMMAND: ${{ matrix.command }} COMMIT_IN_PLACE: ${{ github.event.inputs.commit_in_place == 'true' && 'true' || '' }} MAX: ${{ github.event.inputs.max }}