Skip to content

Commit 9df69c9

Browse files
Try to publish generated_docs from PR sources and comment on the PR (#673)
* Try to publish generated_docs from PR sources and comment on the PR * Added logic for tearing down pulls/prNum after PR is closed
1 parent 9d264fd commit 9df69c9

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

.github/workflows/generate-docs.yml

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ on:
33
push:
44
branches:
55
- master
6+
pull_request:
7+
types: [opened, synchronize, reopened, closed]
68

79
jobs:
810
build-and-deploy:
@@ -14,30 +16,37 @@ jobs:
1416
with:
1517
access_token: ${{ github.token }}
1618
- name: Add Intel repository
19+
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
1720
run: |
1821
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
1922
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
2023
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
2124
sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"
2225
sudo apt-get update
2326
- name: Install Intel OneAPI
27+
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
2428
run: |
2529
sudo apt-get install intel-oneapi-dpcpp-cpp-compiler
2630
- name: Install Lua
31+
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
2732
run: |
2833
sudo apt-get install liblua5.2-dev
2934
- name: Install Doxygen
35+
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
3036
run: |
3137
sudo apt-get install doxygen
3238
- name: Install CMake
39+
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
3340
run: |
3441
sudo apt-get install cmake
3542
- name: Setup Python
43+
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
3644
uses: actions/setup-python@v2
3745
with:
3846
python-version: '3.8'
3947
architecture: x64
4048
- name: Install sphinx dependencies
49+
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
4150
shell: bash -l {0}
4251
run: |
4352
pip install numpy cython setuptools sphinx sphinx_rtd_theme pydot graphviz
@@ -46,12 +55,14 @@ jobs:
4655
with:
4756
fetch-depth: 0
4857
- name: Build dpctl
58+
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
4959
shell: bash -l {0}
5060
run: |
5161
source /opt/intel/oneapi/setvars.sh
5262
python setup.py develop
5363
python -c "import dpctl; print(dpctl.__version__)"
5464
- name: Build docs
65+
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
5566
shell: bash -l {0}
5667
run: |
5768
# Ensure that SYCL libraries are on LD_LIBRARY_PATH
@@ -69,6 +80,7 @@ jobs:
6980
git clean -dfx
7081
cd ..
7182
- name: Publish docs
83+
if: ${{ github.ref == 'refs/heads/master' }}
7284
shell: bash -l {0}
7385
run: |
7486
git remote add tokened_docs https://IntelPython:${{ secrets.GITHUB_TOKEN }}@github.com/IntelPython/dpctl.git
@@ -80,6 +92,60 @@ jobs:
8092
mv ~/docs/* .
8193
git add .
8294
git config --global user.name 'github-actions[doc-deploy-bot]'
83-
git config --gloabl user.email 'github-actions[doc-deploy-bot]@users.noreply.github.com'
95+
git config --global user.email 'github-actions[doc-deploy-bot]@users.noreply.github.com'
8496
git commit -m "Latest docs."
8597
git push tokened_docs gh-pages
98+
- name: Publish pull-request docs
99+
if: ${{ github.event.pull_request && github.event.action != 'closed' }}
100+
env:
101+
PR_NUM: ${{ github.event.number }}
102+
shell: bash -l {0}
103+
run: |
104+
git remote add tokened_docs https://IntelPython:${{ secrets.GITHUB_TOKEN }}@github.com/IntelPython/dpctl.git
105+
git fetch tokened_docs
106+
git checkout --track tokened_docs/gh-pages
107+
echo `pwd`
108+
[ -d pulls/${PR_NUM} ] && git rm -rf pulls/${PR_NUM}
109+
mkdir -p pulls/${PR_NUM}
110+
cd pulls/${PR_NUM}
111+
mv ~/docs/* .
112+
git add .
113+
git config --global user.name 'github-actions[doc-deploy-bot]'
114+
git config --global user.email 'github-actions[doc-deploy-bot]@users.noreply.github.com'
115+
git commit -m "Docs for pull request ${PR_NUM}"
116+
git push tokened_docs gh-pages
117+
- name: Unpublished pull-request docs
118+
if: ${{ github.event.pull_request && github.event.action == 'closed' }}
119+
env:
120+
PR_NUM: ${{ github.event.number }}
121+
shell: bash -l {0}
122+
run: |
123+
git remote add tokened_docs https://IntelPython:${{ secrets.GITHUB_TOKEN }}@github.com/IntelPython/dpctl.git
124+
git fetch tokened_docs
125+
git checkout --track tokened_docs/gh-pages
126+
echo `pwd`
127+
[ -d pulls/${PR_NUM} ] && git rm -rf pulls/${PR_NUM}
128+
git config --global user.name 'github-actions[doc-deploy-bot]'
129+
git config --global user.email 'github-actions[doc-deploy-bot]@users.noreply.github.com'
130+
git commit -m "Removing docs for closed pull request ${PR_NUM}"
131+
git push tokened_docs gh-pages
132+
- name: Comment with URL to published pull-request docs
133+
if: ${{ github.event.pull_request && github.event.action != 'closed' }}
134+
env:
135+
PR_NUM: ${{ github.event.number }}
136+
uses: mshick/add-pr-comment@v1
137+
with:
138+
message: |
139+
View rendered docs @ https://intelpython.github.io/dpctl/pulls/${{ env.PR_NUM }}/index.html
140+
repo-token: ${{ secrets.GITHUB_TOKEN }}
141+
repo-token-user-login: 'github-actions[bot]'
142+
- name: Comment with URL about removal of PR docs
143+
if: ${{ github.event.pull_request && github.event.action == 'closed' }}
144+
env:
145+
PR_NUM: ${{ github.event.number }}
146+
uses: mshick/add-pr-comment@v1
147+
with:
148+
message: |
149+
Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. :crossed_fingers:
150+
repo-token: ${{ secrets.GITHUB_TOKEN }}
151+
repo-token-user-login: 'github-actions[bot]'

0 commit comments

Comments
 (0)