From ab20a4aa5305666be8bace94539f7e678c46ff51 Mon Sep 17 00:00:00 2001 From: Thomas S Date: Fri, 27 Dec 2024 18:07:48 +0100 Subject: [PATCH] [skip ci] ci: Add workflow to serve documentation preview in PRs from fork --- .../pr-serve-documentation-preview.yml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/pr-serve-documentation-preview.yml diff --git a/.github/workflows/pr-serve-documentation-preview.yml b/.github/workflows/pr-serve-documentation-preview.yml new file mode 100644 index 000000000..4362d3ec1 --- /dev/null +++ b/.github/workflows/pr-serve-documentation-preview.yml @@ -0,0 +1,71 @@ +name: serve documentation preview in PR + +on: + workflow_run: + workflows: [sphinx] + types: [completed] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: {} + +jobs: + acquire-pr-context: + if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + outputs: + PR_NUMBER: ${{ steps.acquire-pr-context.outputs.number }} + PR_HEADSHA: ${{ steps.acquire-pr-context.outputs.headsha }} + permissions: + contents: read + steps: + - id: acquire-pr-context + run: gh pr view --repo "${REPOSITORY}" "${BRANCH}" --json 'number,headRefOid' --jq '"number=\(.number)\nheadsha=\(.headRefOid)"' >> "${GITHUB_OUTPUT}" + env: + GH_TOKEN: ${{ github.token }} + REPOSITORY: ${{ github.repository }} + BRANCH: |- + ${{ + (github.event.workflow_run.head_repository.fork == true) + && format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch) + || github.event.workflow_run.head_branch + }} + + serve-documentation-preview: + if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + needs: [acquire-pr-context] + permissions: + actions: read + contents: read + pull-requests: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download HTML artifacts + uses: actions/download-artifact@v4 + with: + name: sphinx-html-artifact + path: html/ + github-token: ${{ github.token }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Serve documentation preview + uses: ./.github/actions/sphinx/deploy + with: + CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOC_PREVIEW }} + BUCKET: ${{ vars.DOCUMENTATION_PREVIEW_BUCKET }} + SOURCE: html/ + DESTINATION: ${{ needs.acquire-pr-context.outputs.PR_NUMBER }}/ + + - name: Comment with documentation preview link + uses: marocchino/sticky-pull-request-comment@v2 + with: + number: ${{ needs.acquire-pr-context.outputs.PR_NUMBER }} + header: documentation-preview + message: >- + [Documentation preview](${{ vars.DOCUMENTATION_PREVIEW_URL }}/${{ needs.acquire-pr-context.outputs.PR_NUMBER }}) + @ ${{ needs.acquire-pr-context.outputs.PR_HEADSHA }}