Skip to content

Commit 013ec8e

Browse files
authored
feat: add pr build doc (#301)
* feat: add pr build doc * [style] remove docs from core CI * [style] correct syntax * [style] add workflow dispatch * [style] use github expression syntax * parse the output directly * [style] use github api * [style] update link * [style] a new version * [style] deploy docs on master
1 parent 2489ef2 commit 013ec8e

File tree

3 files changed

+116
-150
lines changed

3 files changed

+116
-150
lines changed

.github/workflows/docs.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: docs
2+
3+
on:
4+
workflow_dispatch:
5+
6+
push:
7+
branches: [ "master" ]
8+
# pull_request:
9+
# branches: [ "master" ]
10+
issue_comment:
11+
types: [created]
12+
13+
env:
14+
PYTHON_VERSION: "3.10"
15+
BART_VERSION: "0.8.00"
16+
ref_backend: "finufft"
17+
create_venv: "python -m venv $RUNNER_WORKSPACE/venv"
18+
activate_venv: "source $RUNNER_WORKSPACE/venv/bin/activate"
19+
setup_cuda: "export CUDA_BIN_PATH=/usr/local/cuda/;export PATH=/usr/local/cuda/bin/:${PATH};export LD_LIBRARY_PATH=/usr/local/cuda/lib64/:${LD_LIBRARY_PATH}"
20+
21+
jobs:
22+
build-docs:
23+
if: ${{ ( contains(github.event.comment.body, '/build-docs') && github.event.issue.pull_request ) || github.event_name == 'push' || github.event_name == 'workflow_dispatch'}}
24+
name: Build API Documentation
25+
runs-on: gpu
26+
permissions:
27+
actions: read
28+
pull-requests: write
29+
contents: read
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
34+
- name: Get history and tags for SCM versioning to work
35+
run: |
36+
git fetch --prune --unshallow
37+
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
38+
39+
- name: Set up Python
40+
uses: actions/setup-python@v5
41+
with:
42+
python-version: "3.10"
43+
44+
- name: Install dependencies
45+
shell: bash -l {0}
46+
run: |
47+
${{ env.setup_cuda }}
48+
${{ env.create_venv }}
49+
${{ env.activate_venv }}
50+
python -m pip install --upgrade pip
51+
python -m pip install .[doc,finufft,autodiff,gpunufft,cufinufft,sigpy,extra] fastmri
52+
53+
54+
- name: Build API documentation
55+
run: |
56+
${{ env.activate_venv }}
57+
export MRINUFFT_BACKEND=cufinufft
58+
python -m sphinx docs docs_build
59+
60+
- name: Upload artifact
61+
id: artifact-upload-step
62+
uses: actions/upload-artifact@v4
63+
with:
64+
# Upload the docs
65+
name: docs
66+
path: 'docs_build'
67+
retention-days: 5
68+
69+
- name: Get artifact ID
70+
id: get-artifact-id
71+
env:
72+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
run: |
74+
# Get the artifact ID for "docs"
75+
ARTIFACTS_JSON=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
76+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts")
77+
ARTIFACT_ID=$(echo "$ARTIFACTS_JSON" | jq -r '.artifacts[] | select(.name == "docs") | .id' | head -n1)
78+
echo "artifact-id=$ARTIFACT_ID"
79+
echo "artifact-id=$ARTIFACT_ID" >> $GITHUB_OUTPUT
80+
81+
- name: Comment with artifact web link
82+
if: contains(github.event.comment.body, '/build-docs') && github.event.issue.pull_request
83+
uses: peter-evans/create-or-update-comment@v3
84+
with:
85+
comment-id: ${{ github.event.comment.id }}
86+
body: |
87+
✅ Documentation built!
88+
[download the artifact](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.get-artifact-id.outputs.artifact-id }})
89+
edit-mode: replace
90+
91+
deploy-docs:
92+
name: Deploy API Documentation
93+
runs-on: ubuntu-latest
94+
needs: build-docs
95+
if: ${{ github.event_name == 'push' }}
96+
97+
steps:
98+
- name: Get the docs_build artifact
99+
uses: actions/download-artifact@v4
100+
with:
101+
name: docs
102+
path: docs_build
103+
run-id: ${{ github.event.workflow_run.id }}
104+
github-token: ${{ secrets.GITHUB_TOKEN }}
105+
106+
- name: Display structure of docs
107+
run: ls -R docs_build/
108+
109+
- name: Deploy to GitHub Pages
110+
uses: peaceiris/actions-gh-pages@v4
111+
with:
112+
github_token: ${{ secrets.GITHUB_TOKEN }}
113+
publish_dir: ./docs_build
114+
destination_dir: . # Ensure you deploy to the root of the gh-pages branch
115+
publish_branch: gh-pages
116+
keep_files: false

.github/workflows/master-cd.yml

Lines changed: 0 additions & 76 deletions
This file was deleted.

.github/workflows/test-ci.yml

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -314,77 +314,3 @@ jobs:
314314
name: coverage_badge
315315
path: coverage_badge.svg
316316

317-
BuildDocs:
318-
name: Build API Documentation
319-
runs-on: gpu
320-
needs: get-commit-message
321-
if: ${{ contains(needs.get-commit-message.outputs.message, '[docs]') || github.ref == 'refs/heads/master' }}
322-
steps:
323-
- name: Checkout
324-
uses: actions/checkout@v4
325-
326-
- name: Get history and tags for SCM versioning to work
327-
run: |
328-
git fetch --prune --unshallow
329-
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
330-
331-
- name: Set up Python
332-
uses: actions/setup-python@v5
333-
with:
334-
python-version: "3.10"
335-
336-
- name: Install dependencies
337-
shell: bash -l {0}
338-
run: |
339-
${{ env.setup_cuda }}
340-
${{ env.create_venv }}
341-
${{ env.activate_venv }}
342-
python -m pip install --upgrade pip
343-
python -m pip install .[doc,finufft,autodiff,gpunufft,cufinufft,sigpy,extra] fastmri
344-
345-
346-
- name: Build API documentation
347-
run: |
348-
${{ env.activate_venv }}
349-
export MRINUFFT_BACKEND=cufinufft
350-
python -m sphinx docs docs_build
351-
352-
- name: Display data
353-
run: ls -R
354-
working-directory: docs_build/_static
355-
356-
- name: Upload artifact
357-
id: artifact-upload-step
358-
uses: actions/upload-artifact@v4
359-
with:
360-
# Upload the docs
361-
name: docs
362-
path: 'docs_build'
363-
retention-days: 5
364-
365-
CompileDocs:
366-
name: Compile the coverage badge in docs
367-
runs-on: ubuntu-latest
368-
if: ${{ github.ref == 'refs/heads/master' }}
369-
needs: [BuildDocs, coverage]
370-
steps:
371-
- name: Get the docs_build artifact
372-
uses: actions/download-artifact@v4
373-
with:
374-
name: docs
375-
path: docs_build
376-
overwrite: true
377-
378-
- name: Get the badge from CI
379-
uses: actions/download-artifact@v4
380-
with:
381-
name: coverage_badge
382-
path: docs_build/_static
383-
github-token: ${{ secrets.GITHUB_TOKEN }}
384-
385-
- name: ReUpload artifacts
386-
uses: actions/upload-artifact@v4
387-
with:
388-
name: docs_final
389-
retention-days: 20
390-
path: docs_build

0 commit comments

Comments
 (0)