diff --git a/.github/workflows/build-sphinx.yml b/.github/workflows/build-sphinx.yml index 90efdc044c9e..702d4e325cd5 100644 --- a/.github/workflows/build-sphinx.yml +++ b/.github/workflows/build-sphinx.yml @@ -7,6 +7,12 @@ on: types: [opened, synchronize, reopened, closed] 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.head.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/ defaults: @@ -125,21 +131,25 @@ jobs: working-directory: 'dpnp/backend/doc' - name: Copy backend docs - run: cp -r dpnp/backend/doc/html doc/_build/html/backend_doc + run: cp -r dpnp/backend/doc/html ${{ env.PUBLISH_DIR }}/backend_doc # https://github.com/marketplace/actions/github-pages-action + # The step is only used to build docs while pushing a PR to "master" - name: Deploy docs - if: | - github.event.pull_request && !github.event.pull_request.head.repo.fork && - (github.ref == 'refs/heads/master' || (startsWith(github.ref, 'refs/heads/release') == true) || github.event_name == 'push' && contains(github.ref, 'refs/tags/')) + if: env.GH_EVENT_PUSH_UPSTREAM uses: peaceiris/actions-gh-pages@v3.9.3 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ${{ env.PUBLISH_DIR }} + keep_files: true + commit_message: ${{ github.event.head_commit.message }} + publish_branch: gh-pages + 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: Publish pull-request docs - if: | - github.event.pull_request && !github.event.pull_request.head.repo.fork && github.event.action != 'closed' + if: env.GH_EVENT_OPEN_PR_UPSTREAM uses: peaceiris/actions-gh-pages@v3.9.3 with: github_token: ${{ secrets.GITHUB_TOKEN }} @@ -147,14 +157,14 @@ jobs: destination_dir: ./pull/${{ github.event.number }} allow_empty_commit : true keep_files: true - commit_message: ${{ github.event.head_commit.message }} + commit_message: ${{ github.event.pull_request.title }} publish_branch: gh-pages - user_name: 'github-actions[bot]' - user_email: 'github-actions[bot]@users.noreply.github.com' + 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: | - github.event.pull_request && !github.event.pull_request.head.repo.fork && github.event.action != 'closed' + if: env.GH_EVENT_OPEN_PR_UPSTREAM env: PR_NUM: ${{ github.event.number }} uses: mshick/add-pr-comment@v2.8.1 @@ -163,9 +173,11 @@ jobs: View rendered docs @ https://intelpython.github.io/dpnp/pull/${{ env.PR_NUM }}/index.html allow-repeats: false + # The job is only used to build docs when PR is closed (action from PR branch) clean: if: | - github.event.pull_request && !github.event.pull_request.head.repo.fork && github.event.action == 'closed' + github.event_name == 'pull_request' && github.event.action == 'closed' && + github.event.pull_request && !github.event.pull_request.head.repo.fork needs: build-and-deploy @@ -185,8 +197,8 @@ jobs: git checkout --track tokened_docs/gh-pages echo `pwd` [ -d pull/${PR_NUM} ] && git rm -rf pull/${PR_NUM} - git config --global user.name 'github-actions[bot]' - git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git config --global user.name ${{ env.GH_BOT_NAME }} + git config --global user.email ${{ env.GH_BOT_EMAIL }} git commit -m "Removing docs for closed pull request ${PR_NUM}" git push tokened_docs gh-pages