Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 69 additions & 10 deletions .github/workflows/build-sphinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ permissions: read-all
env:
GH_BOT_NAME: 'github-actions[bot]'
GH_BOT_EMAIL: 'github-actions[bot]@users.noreply.github.com'
GH_EVENT_OPEN_PR_UPSTREAM: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' &&
github.event.pull_request && !github.event.pull_request.base.repo.fork }}
GH_EVENT_PUSH_UPSTREAM: ${{ github.ref == 'refs/heads/master' && github.event_name == 'push' &&
github.event.ref == 'refs/heads/master' && github.event.repository && !github.event.repository.fork }}
PUBLISH_DIR: doc/_build/html/
Expand Down Expand Up @@ -191,6 +189,26 @@ jobs:
- name: Copy backend docs
run: cp -r dpnp/backend/doc/html ${{ env.PUBLISH_DIR }}/backend_doc

# Detect if this is a fork PR
- name: Check if fork PR
id: check_fork
run: |
IS_FORK="false"
if [ "${{ github.event_name }}" == "pull_request" ] && [ "${{ github.event.pull_request.head.repo.fork }}" == "true" ]; then
IS_FORK="true"
fi
echo "is_fork=$IS_FORK" >> "$GITHUB_OUTPUT"
echo "Is fork PR: $IS_FORK"

# Upload artifact for fork PRs
- name: Upload docs artifact (Fork PRs)
if: steps.check_fork.outputs.is_fork == 'true' && github.event.action != 'closed'
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: pr-${{ github.event.number }}-docs
path: ${{ env.PUBLISH_DIR }}
retention-days: 30

# The step is only used to build docs while pushing a PR to "master"
- name: Deploy docs
if: env.GH_EVENT_PUSH_UPSTREAM == 'true'
Expand All @@ -206,7 +224,7 @@ jobs:

# The step is only used to build docs while pushing to PR branch
- name: Publish pull-request docs
if: env.GH_EVENT_OPEN_PR_UPSTREAM == 'true'
if: github.event_name == 'pull_request' && github.event.action != 'closed' && steps.check_fork.outputs.is_fork == 'false'
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -219,23 +237,64 @@ jobs:
user_name: ${{ env.GH_BOT_NAME }}
user_email: ${{ env.GH_BOT_EMAIL }}

# The step is only used to build docs while pushing to PR branch
- name: Comment with URL to published pull-request docs
if: env.GH_EVENT_OPEN_PR_UPSTREAM == 'true'
# Prepare documentation preview comment based on PR type
- name: Prepare docs preview comment
if: github.event_name == 'pull_request' && github.event.action != 'closed'
id: docs_comment
env:
PR_NUM: ${{ github.event.number }}
IS_FORK: ${{ steps.check_fork.outputs.is_fork }}
run: |
if [ "$IS_FORK" == "true" ]; then
# Fork PR - provide artifact download instructions
cat << 'EOF' >> "$GITHUB_OUTPUT"
message<<COMMENT_EOF
📚 **Documentation Preview (Fork PR)**

Your docs have been built successfully! For security reasons, fork PRs cannot automatically publish to GitHub Pages.

**To view your docs:**
```bash
gh run download ${{ github.run_id }} -R ${{ github.repository }} -n pr-${{ env.PR_NUM }}-docs
cd pr-${{ env.PR_NUM }}-docs
python -m http.server 8000
# Open http://localhost:8000 in your browser
```

**Alternative: Manual download**
1. Download artifact `pr-${{ env.PR_NUM }}-docs` from [this workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) (scroll to "Artifacts" section)
2. Extract the ZIP file and open `index.html` in your browser

<details>
<summary>Why can't fork PRs publish automatically?</summary>

Fork PRs run with restricted permissions to prevent malicious code from modifying the repository or accessing secrets. This is a GitHub security feature to protect open source projects.
</details>
COMMENT_EOF
EOF
else
# Upstream PR - provide direct URL
cat << 'EOF' >> "$GITHUB_OUTPUT"
message<<COMMENT_EOF
View rendered docs @ https://intelpython.github.io/dpnp/pull/${{ env.PR_NUM }}/index.html
COMMENT_EOF
EOF
fi

# Comment on PR with docs preview
- name: Comment with docs preview
if: github.event_name == 'pull_request' && github.event.action != 'closed'
uses: mshick/add-pr-comment@8e4927817251f1ff60c001f04568532b38e0b4a0 # v3.11.0.8.3.11.0
with:
message-id: url_to_docs
message: |
View rendered docs @ https://intelpython.github.io/dpnp/pull/${{ env.PR_NUM }}/index.html
message-id: docs_preview
message: ${{ steps.docs_comment.outputs.message }}
allow-repeats: false

# The job is only used to build docs when PR is closed (action from PR branch)
clean:
if: |
github.event_name == 'pull_request' && github.event.action == 'closed' &&
github.event.pull_request && !github.event.pull_request.base.repo.fork
github.event.pull_request.head.repo && !github.event.pull_request.head.repo.fork

needs: build-and-deploy

Expand Down
Loading