Skip to content

Commit

Permalink
Added global env variables for GitHub events
Browse files Browse the repository at this point in the history
  • Loading branch information
antonwolfy committed Nov 28, 2023
1 parent de285bf commit addad90
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions .github/workflows/build-sphinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ on:
types: [opened, synchronize, reopened, closed]

env:
GITHUB_BOT_NAME: 'github-actions[bot]'
GITHUB_BOT_EMAIL: 'github-actions[bot]@users.noreply.github.com'
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:
Expand Down Expand Up @@ -130,26 +134,22 @@ jobs:
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 PR to "master"
# The step is only used to build docs while pushing a PR to "master"
- name: Deploy docs
if: |
github.ref == 'refs/heads/master' && github.event_name == 'push' &&
github.event.ref == 'refs/heads/master' && github.event.repository && !github.event.repository.fork
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.GITHUB_BOT_NAME }}
user_email: ${{ env.GITHUB_BOT_EMAIL }}
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_name == 'pull_request' && github.event.action != 'closed' &&
github.event.pull_request && !github.event.pull_request.head.repo.fork
if: env.GH_EVENT_OPEN_PR_UPSTREAM
uses: peaceiris/actions-gh-pages@v3.9.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -159,14 +159,12 @@ jobs:
keep_files: true
commit_message: ${{ github.event.pull_request.title }}
publish_branch: gh-pages
user_name: ${{ env.GITHUB_BOT_NAME }}
user_email: ${{ env.GITHUB_BOT_EMAIL }}
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_name == 'pull_request' && github.event.action != 'closed' &&
github.event.pull_request && !github.event.pull_request.head.repo.fork
if: env.GH_EVENT_OPEN_PR_UPSTREAM
env:
PR_NUM: ${{ github.event.number }}
uses: mshick/add-pr-comment@v2.8.1
Expand Down Expand Up @@ -199,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 ${{ env.GITHUB_BOT_NAME }}
git config --global user.email ${{ env.GITHUB_BOT_EMAIL }}
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
Expand Down

0 comments on commit addad90

Please sign in to comment.