|
| 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 |
0 commit comments