diff --git a/.github/workflows/build-sphinx.yml b/.github/workflows/build-sphinx.yml index 9d67c9c66c9..9048ce7af05 100644 --- a/.github/workflows/build-sphinx.yml +++ b/.github/workflows/build-sphinx.yml @@ -11,10 +11,9 @@ 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 }} + GH_EVENT_PR_OPEN: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }} PUBLISH_DIR: doc/_build/html/ defaults: @@ -191,6 +190,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: env.GH_EVENT_PR_OPEN == 'true' && steps.check_fork.outputs.is_fork == 'true' + 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' @@ -206,7 +225,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: env.GH_EVENT_PR_OPEN == 'true' && steps.check_fork.outputs.is_fork == 'false' uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} @@ -220,8 +239,10 @@ jobs: user_email: ${{ env.GH_BOT_EMAIL }} # The step is only used to build docs while pushing to PR branch + # Note: Fork PRs have read-only GITHUB_TOKEN and cannot post comments + # See: https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflows-in-forked-repositories - name: Comment with URL to published pull-request docs - if: env.GH_EVENT_OPEN_PR_UPSTREAM == 'true' + if: env.GH_EVENT_PR_OPEN == 'true' && steps.check_fork.outputs.is_fork == 'false' env: PR_NUM: ${{ github.event.number }} uses: mshick/add-pr-comment@8e4927817251f1ff60c001f04568532b38e0b4a0 # v3.11.0.8.3.11.0 @@ -235,7 +256,7 @@ jobs: 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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 752bf2ad4b3..72518bf65f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fixed incorrect in-place advanced indexing for 4D arrays when using `range` or `list` as index keys [#2872](https://github.com/IntelPython/dpnp/pull/2872) * Fixed `conda build` command syntax in GitHub workflows and documentation to use `conda-build` [#2888](https://github.com/IntelPython/dpnp/pull/2888) +* Fixed fork PR documentation workflow failures by implementing conditional publishing strategy: upstream PRs publish to GitHub Pages with comment, fork PRs upload artifacts [#2910](https://github.com/IntelPython/dpnp/pull/2910) ### Security