Skip to content

Commit d7c7c06

Browse files
committed
Added global env variables for GitHub events
1 parent de285bf commit d7c7c06

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

.github/workflows/build-sphinx.yml

+15-18
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ on:
77
types: [opened, synchronize, reopened, closed]
88

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

1417
defaults:
@@ -130,26 +133,22 @@ jobs:
130133
run: cp -r dpnp/backend/doc/html ${{ env.PUBLISH_DIR }}/backend_doc
131134

132135
# https://github.com/marketplace/actions/github-pages-action
133-
# The step is only used to build docs while pushing PR to "master"
136+
# The step is only used to build docs while pushing a PR to "master"
134137
- name: Deploy docs
135-
if: |
136-
github.ref == 'refs/heads/master' && github.event_name == 'push' &&
137-
github.event.ref == 'refs/heads/master' && github.event.repository && !github.event.repository.fork
138+
if: env.GH_EVENT_PUSH_UPSTREAM
138139
uses: peaceiris/[email protected]
139140
with:
140141
github_token: ${{ secrets.GITHUB_TOKEN }}
141142
publish_dir: ${{ env.PUBLISH_DIR }}
142143
keep_files: true
143144
commit_message: ${{ github.event.head_commit.message }}
144145
publish_branch: gh-pages
145-
user_name: ${{ env.GITHUB_BOT_NAME }}
146-
user_email: ${{ env.GITHUB_BOT_EMAIL }}
146+
user_name: ${{ env.GH_BOT_NAME }}
147+
user_email: ${{ env.GH_BOT_EMAIL }}
147148

148149
# The step is only used to build docs while pushing to PR branch
149150
- name: Publish pull-request docs
150-
if: |
151-
github.event_name == 'pull_request' && github.event.action != 'closed' &&
152-
github.event.pull_request && !github.event.pull_request.head.repo.fork
151+
if: env.GH_EVENT_PR_UPSTREAM && github.event.action != 'closed'
153152
uses: peaceiris/[email protected]
154153
with:
155154
github_token: ${{ secrets.GITHUB_TOKEN }}
@@ -159,8 +158,8 @@ jobs:
159158
keep_files: true
160159
commit_message: ${{ github.event.pull_request.title }}
161160
publish_branch: gh-pages
162-
user_name: ${{ env.GITHUB_BOT_NAME }}
163-
user_email: ${{ env.GITHUB_BOT_EMAIL }}
161+
user_name: ${{ env.GH_BOT_NAME }}
162+
user_email: ${{ env.GH_BOT_EMAIL }}
164163

165164
# The step is only used to build docs while pushing to PR branch
166165
- name: Comment with URL to published pull-request docs
@@ -177,9 +176,7 @@ jobs:
177176

178177
# The job is only used to build docs when PR is closed (action from PR branch)
179178
clean:
180-
if: |
181-
github.event_name == 'pull_request' && github.event.action == 'closed' &&
182-
github.event.pull_request && !github.event.pull_request.head.repo.fork
179+
if: env.GH_EVENT_PR_UPSTREAM && github.event.action == 'closed'
183180

184181
needs: build-and-deploy
185182

@@ -199,8 +196,8 @@ jobs:
199196
git checkout --track tokened_docs/gh-pages
200197
echo `pwd`
201198
[ -d pull/${PR_NUM} ] && git rm -rf pull/${PR_NUM}
202-
git config --global user.name ${{ env.GITHUB_BOT_NAME }}
203-
git config --global user.email ${{ env.GITHUB_BOT_EMAIL }}
199+
git config --global user.name ${{ env.GH_BOT_NAME }}
200+
git config --global user.email ${{ env.GH_BOT_EMAIL }}
204201
git commit -m "Removing docs for closed pull request ${PR_NUM}"
205202
git push tokened_docs gh-pages
206203

0 commit comments

Comments
 (0)