Skip to content

Commit

Permalink
[skip ci] ci: Add workflow to serve documentation preview in PRs from…
Browse files Browse the repository at this point in the history
… fork
  • Loading branch information
thomass-dev committed Dec 27, 2024
1 parent 469d1e5 commit ab20a4a
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/pr-serve-documentation-preview.yml
Original file line number Diff line number Diff line change
@@ -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 }}

0 comments on commit ab20a4a

Please sign in to comment.