|
| 1 | +name: serve documentation preview in PR |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: [sphinx] |
| 6 | + types: [completed] |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +permissions: {} |
| 13 | + |
| 14 | +jobs: |
| 15 | + acquire-pr-context: |
| 16 | + if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + PR_NUMBER: ${{ steps.acquire-pr-context.outputs.number }} |
| 20 | + PR_HEADSHA: ${{ steps.set-pr-context.outputs.headsha }} |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + steps: |
| 24 | + - id: acquire-pr-number |
| 25 | + run: gh pr view --repo "${REPOSITORY}" "${BRANCH}" --json 'number,headRefOid' --jq '"number=\(.number)\nheadsha=\(.headRefOid)"' >> "${GITHUB_OUTPUT}" |
| 26 | + env: |
| 27 | + GH_TOKEN: ${{ github.token }} |
| 28 | + REPOSITORY: ${{ github.repository }} |
| 29 | + BRANCH: |- |
| 30 | + ${{ |
| 31 | + (github.event.workflow_run.head_repository.fork == true) |
| 32 | + && format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch) |
| 33 | + || github.event.workflow_run.head_branch |
| 34 | + }} |
| 35 | +
|
| 36 | + serve-documentation-preview: |
| 37 | + if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} |
| 38 | + runs-on: ubuntu-latest |
| 39 | + needs: [acquire-pr-context] |
| 40 | + permissions: |
| 41 | + actions: read |
| 42 | + contents: read |
| 43 | + pull-requests: write |
| 44 | + steps: |
| 45 | + - name: Checkout code |
| 46 | + uses: actions/checkout@v4 |
| 47 | + |
| 48 | + - name: Download HTML artifacts |
| 49 | + uses: actions/download-artifact@v4 |
| 50 | + with: |
| 51 | + name: sphinx-html-artifact |
| 52 | + path: html/ |
| 53 | + github-token: ${{ github.token }} |
| 54 | + run-id: ${{ github.event.workflow_run.id }} |
| 55 | + |
| 56 | + - name: Serve documentation preview |
| 57 | + uses: ./.github/actions/sphinx/deploy |
| 58 | + with: |
| 59 | + CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOC_PREVIEW }} |
| 60 | + BUCKET: ${{ vars.DOCUMENTATION_PREVIEW_BUCKET }} |
| 61 | + SOURCE: html/ |
| 62 | + DESTINATION: ${{ needs.acquire-pr-number.outputs.PR_NUMBER }}/ |
| 63 | + |
| 64 | + - name: Comment with documentation preview link |
| 65 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 66 | + with: |
| 67 | + number: ${{ needs.acquire-pr-number.outputs.PR_NUMBER }} |
| 68 | + header: documentation-preview |
| 69 | + message: >- |
| 70 | + [Documentation preview](${{ vars.DOCUMENTATION_PREVIEW_URL }}/${{ needs.acquire-pr-number.outputs.PR_NUMBER }}) |
| 71 | + @ ${{ needs.acquire-pr-number.outputs.PR_HEADSHA }} |
0 commit comments