|
| 1 | +name: "Translate Documentation Action" |
| 2 | +description: "Translates documentation files automatically using AI" |
| 3 | + |
| 4 | +inputs: |
| 5 | + custom_arguments: |
| 6 | + description: "Custom arguments to pass to the translation package command" |
| 7 | + required: false |
| 8 | + default: "" |
| 9 | + github_token: |
| 10 | + description: "GitHub token for creating PRs" |
| 11 | + required: false |
| 12 | + default: ${{ github.token }} |
| 13 | + api_key: |
| 14 | + description: "API key for translation service (e.g., OPENAI_API_KEY)" |
| 15 | + required: true |
| 16 | + translation_command: |
| 17 | + description: "command to use for translation" |
| 18 | + required: false |
| 19 | + default: "pnpm run translate" |
| 20 | + base_branch: |
| 21 | + description: "Base branch to create PR against" |
| 22 | + required: false |
| 23 | + default: "main" |
| 24 | + pr_branch: |
| 25 | + description: "Branch name for the PR" |
| 26 | + required: false |
| 27 | + default: "docs/update-translations" |
| 28 | + pr_title: |
| 29 | + description: "Title for the PR" |
| 30 | + required: false |
| 31 | + default: "Update translations" |
| 32 | + pr_body: |
| 33 | + description: "Body text for the PR" |
| 34 | + required: false |
| 35 | + default: | |
| 36 | + This PR updates the documentation translations automatically. |
| 37 | +
|
| 38 | + Generated by the translate workflow. |
| 39 | + commit_message: |
| 40 | + description: "Commit message for the translation changes" |
| 41 | + required: false |
| 42 | + default: "docs: update documentation translations" |
| 43 | + schedule_cron: |
| 44 | + description: "Cron schedule for automatic translation (used in workflow template)" |
| 45 | + required: false |
| 46 | + default: "0 20 * * *" |
| 47 | + add_paths: |
| 48 | + description: "A comma or newline-separated list of file paths to commit. Paths should follow git's pathspec syntax." |
| 49 | + required: false |
| 50 | + default: "apps/docs/content/**" |
| 51 | + enable_formatting: |
| 52 | + description: "Whether to run code formatting before creating the PR" |
| 53 | + required: false |
| 54 | + default: "true" |
| 55 | + format_command: |
| 56 | + description: "The command to run for formatting code" |
| 57 | + required: false |
| 58 | + default: "pnpm prettier:write" |
| 59 | + |
| 60 | +runs: |
| 61 | + using: "composite" |
| 62 | + steps: |
| 63 | + - name: Checkout code |
| 64 | + uses: actions/checkout@v3 |
| 65 | + with: |
| 66 | + fetch-depth: 0 # Fetch all history for proper timestamp lookup |
| 67 | + |
| 68 | + - name: Check if PR branch already exists |
| 69 | + id: check_branch |
| 70 | + shell: bash |
| 71 | + run: | |
| 72 | + if git ls-remote --heads origin ${{ inputs.pr_branch }} | grep -q ${{ inputs.pr_branch }}; then |
| 73 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 74 | + else |
| 75 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 76 | + fi |
| 77 | + - name: Setup Tools |
| 78 | + if: steps.check_branch.outputs.exists == 'false' |
| 79 | + uses: ./.github/actions/setup |
| 80 | + |
| 81 | + - name: Run translation |
| 82 | + if: steps.check_branch.outputs.exists == 'false' |
| 83 | + shell: bash |
| 84 | + run: | |
| 85 | + echo "Running translation with custom arguments: ${{ inputs.custom_arguments }}" |
| 86 | + ${{ inputs.translation_command }} ${{ inputs.custom_arguments }} |
| 87 | + env: |
| 88 | + OPENAI_API_KEY: ${{ inputs.api_key }} |
| 89 | + |
| 90 | + - name: Check for modifications |
| 91 | + if: steps.check_branch.outputs.exists == 'false' |
| 92 | + id: check-changes |
| 93 | + shell: bash |
| 94 | + run: | |
| 95 | + if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then |
| 96 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 97 | + echo "Changes detected. Will proceed with formatting and commit." |
| 98 | + else |
| 99 | + echo "has_changes=false" >> $GITHUB_OUTPUT |
| 100 | + echo "No changes detected after translation. Exiting workflow." |
| 101 | + fi |
| 102 | +
|
| 103 | + - name: Fix formatting |
| 104 | + if: steps.check_branch.outputs.exists == 'false' && steps.check-changes.outputs.has_changes == 'true' && inputs.enable_formatting == 'true' |
| 105 | + shell: bash |
| 106 | + run: ${{ inputs.format_command }} |
| 107 | + |
| 108 | + - name: Create Pull Request |
| 109 | + if: steps.check_branch.outputs.exists == 'false' && steps.check-changes.outputs.has_changes == 'true' |
| 110 | + uses: peter-evans/create-pull-request@v5 |
| 111 | + with: |
| 112 | + token: ${{ inputs.github_token }} |
| 113 | + commit-message: ${{ inputs.commit_message }} |
| 114 | + title: ${{ inputs.pr_title }} |
| 115 | + body: ${{ inputs.pr_body }} |
| 116 | + branch: ${{ inputs.pr_branch }} |
| 117 | + delete-branch: true |
| 118 | + base: ${{ inputs.base_branch }} |
| 119 | + add-paths: ${{ inputs.add_paths }} |
| 120 | + |
| 121 | +branding: |
| 122 | + icon: "globe" |
| 123 | + color: "blue" |
0 commit comments