Skip to content

Commit 04391cf

Browse files
committed
Transform job to be fork compliant
1 parent 0431699 commit 04391cf

File tree

2 files changed

+72
-32
lines changed

2 files changed

+72
-32
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 }}

.github/workflows/sphinx.yml

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -115,37 +115,6 @@ jobs:
115115
name: sphinx-html-artifact
116116
path: sphinx/build/html/
117117

118-
sphinx-preview:
119-
if: ${{ github.event_name == 'pull_request' }}
120-
runs-on: ubuntu-latest
121-
needs: sphinx-build
122-
permissions:
123-
actions: read
124-
contents: read
125-
pull-requests: write
126-
steps:
127-
- uses: actions/checkout@v4
128-
129-
- uses: actions/download-artifact@v4
130-
with:
131-
name: sphinx-html-artifact
132-
path: html/
133-
134-
- uses: ./.github/actions/sphinx/deploy
135-
with:
136-
CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOC_PREVIEW }}
137-
BUCKET: ${{ vars.DOCUMENTATION_PREVIEW_BUCKET }}
138-
SOURCE: html/
139-
DESTINATION: ${{ github.event.number }}/
140-
141-
- uses: marocchino/sticky-pull-request-comment@v2
142-
with:
143-
number: ${{ github.event.number }}
144-
header: documentation-preview
145-
message: >-
146-
[Documentation preview](${{ vars.DOCUMENTATION_PREVIEW_URL }}/${{ github.event.number }})
147-
@ ${{ github.event.pull_request.head.sha }}
148-
149118
sphinx-deploy-html:
150119
if: ${{ (github.event_name == 'release') || (github.event_name == 'push' && github.ref == 'refs/heads/main') }}
151120
runs-on: ubuntu-latest
@@ -222,7 +191,7 @@ jobs:
222191
sphinx-clean:
223192
runs-on: ubuntu-latest
224193
if: always()
225-
needs: [sphinx-version, sphinx-build, sphinx-preview, sphinx-deploy-html, sphinx-deploy-root-files]
194+
needs: [sphinx-version, sphinx-build, sphinx-deploy-html, sphinx-deploy-root-files]
226195
steps:
227196
- uses: geekyeggo/delete-artifact@v5
228197
with:

0 commit comments

Comments
 (0)