folder page make #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Translate new posts to English | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| permissions: | |
| contents: write | |
| jobs: | |
| translate: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout PR branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.head_ref }} | |
| - name: Get changed files from PR | |
| id: changes | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const pr = context.payload.pull_request; | |
| const { owner, repo } = context.repo; | |
| const pull_number = pr.number; | |
| const per_page = 100; | |
| let page = 1; | |
| const files = []; | |
| while (true) { | |
| const res = await github.rest.pulls.listFiles({ owner, repo, pull_number, per_page, page }); | |
| if (res.data.length === 0) break; | |
| for (const f of res.data) files.push(f.filename); | |
| if (res.data.length < per_page) break; | |
| page += 1; | |
| } | |
| const posts = files.filter(f => f.startsWith('_posts/') && f.endsWith('.md')); | |
| core.setOutput('posts', posts.join('\n')); | |
| - name: Set ONLY_FILES env | |
| if: steps.changes.outputs.posts != '' | |
| run: | | |
| echo 'ONLY_FILES<<EOF' >> $GITHUB_ENV | |
| echo '${{ steps.changes.outputs.posts }}' >> $GITHUB_ENV | |
| echo 'EOF' >> $GITHUB_ENV | |
| - name: Set up Python | |
| if: steps.changes.outputs.posts != '' | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| if: steps.changes.outputs.posts != '' | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install openai PyYAML python-frontmatter python-slugify | |
| - name: Generate English translations | |
| if: steps.changes.outputs.posts != '' | |
| env: | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| TRANSLATION_MODEL: ${{ vars.TRANSLATION_MODEL }} | |
| run: | | |
| python scripts/translate_to_en.py | |
| - name: Commit and push translations | |
| if: steps.changes.outputs.posts != '' | |
| uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| commit_message: "chore: add English translations for PR #${{ github.event.pull_request.number }}" | |
| file_pattern: _posts_en/*.md | |