diff --git a/.github/workflows/build-docusaurus.yml b/.github/workflows/build-docusaurus.yml index 6ea5fed8c..81b23192d 100644 --- a/.github/workflows/build-docusaurus.yml +++ b/.github/workflows/build-docusaurus.yml @@ -1,6 +1,6 @@ name: Build Docusaurus Documentation on: - pull_request: + pull_request_target: types: [labeled] push: branches: ["master", "main"] @@ -19,6 +19,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: + ref: ${{ github.event.pull_request.head.sha || github.sha }} fetch-depth: 0 - name: Setup Node.js @@ -54,13 +55,17 @@ jobs: retention-days: 90 - name: Remove label - if: always() && github.event_name == 'pull_request' + if: always() && github.event_name == 'pull_request_target' uses: actions/github-script@v7 with: script: | - github.rest.issues.removeLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - name: 'BUILD DOCUSAURUS' - }) \ No newline at end of file + try { + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + name: 'BUILD DOCUSAURUS' + }); + } catch (error) { + core.warning(`Could not remove label: ${error.message}`); + } diff --git a/.github/workflows/translate-docusaurus.yml b/.github/workflows/translate-docusaurus.yml index 1b36e240f..ee7a30362 100644 --- a/.github/workflows/translate-docusaurus.yml +++ b/.github/workflows/translate-docusaurus.yml @@ -1,11 +1,10 @@ name: Translate Docusaurus Documentation on: - pull_request: + pull_request_target: types: [labeled] permissions: - checks: write contents: write pull-requests: write @@ -15,10 +14,10 @@ jobs: timeout-minutes: 1440 runs-on: self-hosted steps: - - name: Checkout PR branch + - name: Checkout PR code uses: actions/checkout@v4 with: - ref: ${{ github.head_ref }} + ref: ${{ github.event.pull_request.head.sha }} fetch-depth: 0 - name: Setup Node.js @@ -42,25 +41,80 @@ jobs: run: node translate.js - name: Commit translations + id: commit run: | git config --local user.name "github-actions" git config --local user.email "github-actions@github.com" git add -A i18n/ if ! git diff --cached --quiet; then git commit -m "Auto-translate docs" - git push origin HEAD:${{ github.head_ref }} + echo "has_changes=true" >> "$GITHUB_OUTPUT" else echo "No translation changes to commit" + echo "has_changes=false" >> "$GITHUB_OUTPUT" fi - - name: Remove label - if: always() + - name: Push to PR branch (same-repo) + if: steps.commit.outputs.has_changes == 'true' && github.event.pull_request.head.repo.full_name == github.repository + run: git push origin HEAD:refs/heads/${{ github.head_ref }} + + - name: Push translation branch (fork PR) + if: steps.commit.outputs.has_changes == 'true' && github.event.pull_request.head.repo.full_name != github.repository + run: git push origin HEAD:refs/heads/translations/pr-${{ github.event.pull_request.number }} --force + + - name: Create or update translation PR (fork PR) + if: steps.commit.outputs.has_changes == 'true' && github.event.pull_request.head.repo.full_name != github.repository uses: actions/github-script@v7 with: script: | - github.rest.issues.removeLabel({ + const prNumber = context.payload.pull_request.number; + const branch = `translations/pr-${prNumber}`; + const baseBranch = context.payload.pull_request.base.ref; + + const { data: existingPRs } = await github.rest.pulls.list({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: context.issue.number, - name: 'TRANSLATE DOCUSAURUS' - }) \ No newline at end of file + head: `${context.repo.owner}:${branch}`, + state: 'open' + }); + + if (existingPRs.length === 0) { + const { data: newPR } = await github.rest.pulls.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: `Auto-translate: PR #${prNumber}`, + body: `Automated translations for #${prNumber}.\n\nMerge this PR **after** #${prNumber} has been merged.`, + head: branch, + base: baseBranch + }); + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: `Translations have been generated and are available in #${newPR.number}.\nPlease merge the translation PR after this PR is merged.` + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: `Translations have been updated in #${existingPRs[0].number}.` + }); + } + + - name: Remove label + if: always() + uses: actions/github-script@v7 + with: + script: | + try { + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + name: 'TRANSLATE DOCUSAURUS' + }); + } catch (error) { + core.warning(`Could not remove label: ${error.message}`); + } diff --git a/docs/7d2d-commands.md b/docs/7d2d-commands.md index 98a9edc6d..971d3e4c0 100644 --- a/docs/7d2d-commands.md +++ b/docs/7d2d-commands.md @@ -9,6 +9,10 @@ services: import InlineVoucher from '@site/src/components/InlineVoucher'; + + +This is a test change + ## The Console