Skip to content

Commit c99b129

Browse files
committed
ci: Add workflow to serve documentation preview in PRs (#1027)
1 parent b76feb9 commit c99b129

File tree

6 files changed

+161
-8
lines changed

6 files changed

+161
-8
lines changed

.github/actions/sphinx/deploy/action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ inputs:
1414
required: false
1515
default: scaleway
1616
BUCKET:
17-
required: false
18-
default: prod-probabl-skore
17+
required: true
1918
SOURCE:
2019
required: true
2120
DESTINATION:

.github/workflows/backend.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
python -m pytest -n auto --junitxml=coverage/coverage.xml --cov=skore src/ tests/ | tee coverage/coverage.txt
9191
9292
- name: Upload coverage reports
93-
if: ${{ matrix.coverage }}
93+
if: ${{ matrix.coverage && (github.event_name == 'pull_request') }}
9494
uses: actions/upload-artifact@v4
9595
with:
9696
name: backend-coverage

.github/workflows/frontend.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
npm run test:unit:coverage
6464
6565
- name: Upload coverage reports
66+
if: ${{ github.event_name == 'pull_request' }}
6667
uses: actions/upload-artifact@v4
6768
with:
6869
name: frontend-coverage

.github/workflows/pr-cleanup.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: cleanup PR
2+
3+
on:
4+
pull_request_target:
5+
types: [closed]
6+
7+
permissions: {}
8+
9+
defaults:
10+
run:
11+
shell: "bash"
12+
13+
jobs:
14+
clean-artifacts:
15+
if: always()
16+
runs-on: ubuntu-latest
17+
permissions:
18+
actions: write
19+
steps:
20+
- name: Clean artifacts
21+
run: |
22+
set -u
23+
24+
ARTIFACTS=$( \
25+
gh api \
26+
--paginate \
27+
-H "Accept: application/vnd.github+json" \
28+
-H "X-GitHub-Api-Version: 2022-11-28" \
29+
/repos/probabl-ai/skore/actions/artifacts \
30+
| \
31+
jq -c " \
32+
.artifacts[] \
33+
| select((.workflow_run.head_branch == \"${HEAD_BRANCH}\") and (.workflow_run.head_repository_id == ${HEAD_REPOSITORY_ID})) \
34+
| {id: .id, name: .name} \
35+
" \
36+
)
37+
38+
for ARTIFACT in $ARTIFACTS; do
39+
ID=$(echo "${ARTIFACT}" | jq -r '.id')
40+
NAME=$(echo "${ARTIFACT}" | jq -r '.name')
41+
42+
echo "Deleting artifact (NAME: \"${NAME}\", ID: \"${ID}\")"
43+
44+
gh api \
45+
--method DELETE \
46+
--silent \
47+
-H "Accept: application/vnd.github+json" \
48+
-H "X-GitHub-Api-Version: 2022-11-28" \
49+
/repos/${REPOSITORY_OWNER}/${REPOSITORY_NAME}/actions/artifacts/${ID}
50+
done
51+
env:
52+
GH_TOKEN: ${{ github.token }}
53+
REPOSITORY_OWNER: ${{ github.repository_owner }}
54+
REPOSITORY_NAME: ${{ github.event.repository.name }}
55+
HEAD_REPOSITORY_ID: ${{ github.event.pull_request.head.repo.id }}
56+
HEAD_BRANCH: ${{ github.head_ref }}
57+
58+
clean-documentation-preview:
59+
if: always()
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: Install `rclone`
63+
shell: bash
64+
run: |
65+
sudo apt-get update
66+
sudo apt-get install -y rclone
67+
68+
- name: Copy configuration
69+
shell: bash
70+
run: echo "${CONFIGURATION}" > rclone.configuration
71+
env:
72+
CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOC_PREVIEW }}
73+
74+
- name: Clean documentation preview
75+
run: rclone --config rclone.configuration purge "${PROVIDER}:${BUCKET}/${PULL_REQUEST_NUMBER}"
76+
env:
77+
PROVIDER: scaleway
78+
BUCKET: ${{ vars.DOCUMENTATION_PREVIEW_BUCKET }}
79+
PULL_REQUEST_NUMBER: ${{ github.event.number }}
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.acquire-pr-context.outputs.headsha }}
21+
permissions:
22+
contents: read
23+
steps:
24+
- id: acquire-pr-context
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-context.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-context.outputs.PR_NUMBER }}
68+
header: documentation-preview
69+
message: >-
70+
[Documentation preview](${{ vars.DOCUMENTATION_PREVIEW_URL }}/${{ needs.acquire-pr-context.outputs.PR_NUMBER }})
71+
@ ${{ needs.acquire-pr-context.outputs.PR_HEADSHA }}

.github/workflows/sphinx.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ jobs:
116116
path: sphinx/build/html/
117117

118118
sphinx-deploy-html:
119-
runs-on: ubuntu-latest
120119
if: ${{ (github.event_name == 'release') || (github.event_name == 'push' && github.ref == 'refs/heads/main') }}
120+
runs-on: ubuntu-latest
121121
needs: [sphinx-version, sphinx-build]
122122
steps:
123123
- uses: actions/checkout@v4
@@ -128,12 +128,13 @@ jobs:
128128
- uses: ./.github/actions/sphinx/deploy
129129
with:
130130
CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOCS }}
131+
BUCKET: ${{ vars.DOCUMENTATION_BUCKET }}
131132
SOURCE: html/
132133
DESTINATION: ${{ needs.sphinx-version.outputs.SPHINX_VERSION }}/
133134

134135
sphinx-deploy-root-files:
135-
runs-on: ubuntu-latest
136136
if: ${{ github.event_name == 'release' }}
137+
runs-on: ubuntu-latest
137138
needs: [sphinx-version, sphinx-build, sphinx-deploy-html]
138139
steps:
139140
- uses: actions/checkout@v4
@@ -144,7 +145,7 @@ jobs:
144145
import operator
145146
import json
146147
147-
url = "https://skore.probabl.ai"
148+
url = os.environ["URL"]
148149
current = os.environ["CURRENT"]
149150
150151
response = requests.get(f"{url}/versions.json")
@@ -177,17 +178,19 @@ jobs:
177178
"""
178179
)
179180
env:
181+
URL: ${{ vars.DOCUMENTATION_URL }}
180182
CURRENT: ${{ needs.sphinx-version.outputs.SPHINX_VERSION }}
181183
- uses: ./.github/actions/sphinx/deploy
182184
with:
183185
CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOCS }}
186+
BUCKET: ${{ vars.DOCUMENTATION_BUCKET }}
184187
ACTION: copy
185188
SOURCE: artifacts/
186189
DESTINATION:
187190

188-
sphinx-clean:
191+
sphinx-clean-artifacts:
189192
runs-on: ubuntu-latest
190-
if: always()
193+
if: ${{ always() && (github.event_name != 'pull_request') }}
191194
needs: [sphinx-version, sphinx-build, sphinx-deploy-html, sphinx-deploy-root-files]
192195
steps:
193196
- uses: geekyeggo/delete-artifact@v5

0 commit comments

Comments
 (0)