Skip to content

Commit 912bb77

Browse files
authored
Update deploy step of a job with building docs (#1631)
* Update deploy step of a job with building docs * Added global env variables for GitHub events
1 parent 780d686 commit 912bb77

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

.github/workflows/build-sphinx.yml

+26-14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ on:
77
types: [opened, synchronize, reopened, closed]
88

99
env:
10+
GH_BOT_NAME: 'github-actions[bot]'
11+
GH_BOT_EMAIL: 'github-actions[bot]@users.noreply.github.com'
12+
GH_EVENT_OPEN_PR_UPSTREAM: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' &&
13+
github.event.pull_request && !github.event.pull_request.head.repo.fork }}
14+
GH_EVENT_PUSH_UPSTREAM: ${{ github.ref == 'refs/heads/master' && github.event_name == 'push' &&
15+
github.event.ref == 'refs/heads/master' && github.event.repository && !github.event.repository.fork }}
1016
PUBLISH_DIR: doc/_build/html/
1117

1218
defaults:
@@ -125,36 +131,40 @@ jobs:
125131
working-directory: 'dpnp/backend/doc'
126132

127133
- name: Copy backend docs
128-
run: cp -r dpnp/backend/doc/html doc/_build/html/backend_doc
134+
run: cp -r dpnp/backend/doc/html ${{ env.PUBLISH_DIR }}/backend_doc
129135

130136
# https://github.com/marketplace/actions/github-pages-action
137+
# The step is only used to build docs while pushing a PR to "master"
131138
- name: Deploy docs
132-
if: |
133-
github.event.pull_request && !github.event.pull_request.head.repo.fork &&
134-
(github.ref == 'refs/heads/master' || (startsWith(github.ref, 'refs/heads/release') == true) || github.event_name == 'push' && contains(github.ref, 'refs/tags/'))
139+
if: env.GH_EVENT_PUSH_UPSTREAM
135140
uses: peaceiris/[email protected]
136141
with:
137142
github_token: ${{ secrets.GITHUB_TOKEN }}
138143
publish_dir: ${{ env.PUBLISH_DIR }}
144+
keep_files: true
145+
commit_message: ${{ github.event.head_commit.message }}
146+
publish_branch: gh-pages
147+
user_name: ${{ env.GH_BOT_NAME }}
148+
user_email: ${{ env.GH_BOT_EMAIL }}
139149

150+
# The step is only used to build docs while pushing to PR branch
140151
- name: Publish pull-request docs
141-
if: |
142-
github.event.pull_request && !github.event.pull_request.head.repo.fork && github.event.action != 'closed'
152+
if: env.GH_EVENT_OPEN_PR_UPSTREAM
143153
uses: peaceiris/[email protected]
144154
with:
145155
github_token: ${{ secrets.GITHUB_TOKEN }}
146156
publish_dir: ${{ env.PUBLISH_DIR }}
147157
destination_dir: ./pull/${{ github.event.number }}
148158
allow_empty_commit : true
149159
keep_files: true
150-
commit_message: ${{ github.event.head_commit.message }}
160+
commit_message: ${{ github.event.pull_request.title }}
151161
publish_branch: gh-pages
152-
user_name: 'github-actions[bot]'
153-
user_email: 'github-actions[bot]@users.noreply.github.com'
162+
user_name: ${{ env.GH_BOT_NAME }}
163+
user_email: ${{ env.GH_BOT_EMAIL }}
154164

165+
# The step is only used to build docs while pushing to PR branch
155166
- name: Comment with URL to published pull-request docs
156-
if: |
157-
github.event.pull_request && !github.event.pull_request.head.repo.fork && github.event.action != 'closed'
167+
if: env.GH_EVENT_OPEN_PR_UPSTREAM
158168
env:
159169
PR_NUM: ${{ github.event.number }}
160170
uses: mshick/[email protected]
@@ -163,9 +173,11 @@ jobs:
163173
View rendered docs @ https://intelpython.github.io/dpnp/pull/${{ env.PR_NUM }}/index.html
164174
allow-repeats: false
165175

176+
# The job is only used to build docs when PR is closed (action from PR branch)
166177
clean:
167178
if: |
168-
github.event.pull_request && !github.event.pull_request.head.repo.fork && github.event.action == 'closed'
179+
github.event_name == 'pull_request' && github.event.action == 'closed' &&
180+
github.event.pull_request && !github.event.pull_request.head.repo.fork
169181
170182
needs: build-and-deploy
171183

@@ -185,8 +197,8 @@ jobs:
185197
git checkout --track tokened_docs/gh-pages
186198
echo `pwd`
187199
[ -d pull/${PR_NUM} ] && git rm -rf pull/${PR_NUM}
188-
git config --global user.name 'github-actions[bot]'
189-
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
200+
git config --global user.name ${{ env.GH_BOT_NAME }}
201+
git config --global user.email ${{ env.GH_BOT_EMAIL }}
190202
git commit -m "Removing docs for closed pull request ${PR_NUM}"
191203
git push tokened_docs gh-pages
192204

0 commit comments

Comments
 (0)