diff --git a/.github/workflows/R.yml b/.github/workflows/R.yml index 284c93df..07e5eaf5 100644 --- a/.github/workflows/R.yml +++ b/.github/workflows/R.yml @@ -190,8 +190,9 @@ jobs: needs: R-CMD-check permissions: contents: write # github-pages-deploy-action + pull-requests: write # post PR preview comment concurrency: # Recommended if you intend to make multiple deployments in quick succession. - group: web-${{ github.workflow }}-${{ github.ref }} + group: web-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -233,6 +234,46 @@ jobs: single-commit: true clean: true + - name: Deploy PR preview šŸš€ + if: success() && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + uses: JamesIves/github-pages-deploy-action@v4 + with: + folder: r/docs + target-folder: previews/pr-${{ github.event.pull_request.number }}/r + single-commit: true + clean: true + + - name: Comment PR preview link + if: success() && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + uses: actions/github-script@v7 + with: + script: | + const marker = ''; + const prNumber = context.issue.number; + const url = `https://multi-objective.github.io/moocore/previews/pr-${prNumber}/r/`; + const body = `${marker}\nšŸ“š [**R docs preview** for this PR](${url})\n\n`; + const comments = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + }); + const existing = comments.data.find(c => c.body.includes(marker)); + if (existing) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + body, + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body, + }); + } + rchk: needs: pkgdown uses: multi-objective/moocore/.github/workflows/rchk.yml@main diff --git a/.github/workflows/docs-preview-cleanup.yml b/.github/workflows/docs-preview-cleanup.yml new file mode 100644 index 00000000..5ad60598 --- /dev/null +++ b/.github/workflows/docs-preview-cleanup.yml @@ -0,0 +1,34 @@ +name: Cleanup docs preview + +on: + pull_request: + types: [closed] + +permissions: + contents: write + +jobs: + cleanup: + name: Remove docs preview for closed PR + runs-on: ubuntu-latest + # Only run for same-repo PRs; fork PRs never get a preview deployed + if: github.event.pull_request.head.repo.full_name == github.repository + steps: + - uses: actions/checkout@v6 + with: + ref: gh-pages + + - name: Remove preview folder + run: | + PR_NUMBER="${{ github.event.pull_request.number }}" + PREVIEW_DIR="previews/pr-${PR_NUMBER}" + if [ -d "${PREVIEW_DIR}" ]; then + git rm -rf "${PREVIEW_DIR}" + git config user.email "actions@github.com" + git config user.name "GitHub Actions" + git commit -m "Remove docs preview for PR #${PR_NUMBER}" + git push + echo "Removed ${PREVIEW_DIR}" + else + echo "No preview directory found for PR #${PR_NUMBER}, nothing to clean up" + fi diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 603dcc65..940cfcd9 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -117,8 +117,9 @@ jobs: if: "! contains(github.event.head_commit.message, '[skip ci]')" permissions: contents: write + pull-requests: write # post PR preview comment concurrency: # Recommended if you intend to make multiple deployments in quick succession. - group: web-${{ github.workflow }}-${{ github.ref }} + group: web-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} timeout-minutes: 10 runs-on: ubuntu-latest steps: @@ -165,6 +166,46 @@ jobs: single-commit: true clean: true + - name: Deploy PR preview šŸš€ + if: success() && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + uses: JamesIves/github-pages-deploy-action@v4 + with: + folder: python/doc/_build/html/ + target-folder: previews/pr-${{ github.event.pull_request.number }}/python + single-commit: true + clean: true + + - name: Comment PR preview link + if: success() && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + uses: actions/github-script@v7 + with: + script: | + const marker = ''; + const prNumber = context.issue.number; + const url = `https://multi-objective.github.io/moocore/previews/pr-${prNumber}/python/`; + const body = `${marker}\nšŸ“š [**Python docs preview** for this PR](${url})\n\n`; + const comments = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + }); + const existing = comments.data.find(c => c.body.includes(marker)); + if (existing) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + body, + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body, + }); + } + coverage: timeout-minutes: 15 needs: build-doc