Skip to content

Commit

Permalink
Handle comments correctly for preview PR docs (#94)
Browse files Browse the repository at this point in the history
Signed-off-by: Tao He <[email protected]>
  • Loading branch information
sighingnow authored Feb 14, 2023
1 parent 5ae1e7c commit c31a88b
Showing 1 changed file with 57 additions and 10 deletions.
67 changes: 57 additions & 10 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ on:
push:
branches:
- main
pull_request:
pull_request_target:
branches:
- main
- docs
- dev/docs

jobs:
build:
Expand All @@ -29,10 +31,29 @@ jobs:
matrix:
os: [ubuntu-20.04]
steps:
- uses: actions/setup-node@v3
with:
node-version: 16

- uses: actions/checkout@v2
with:
submodules: true

- name: Leave the comment on pull request when started
if: ${{ github.event_name == 'pull_request_target' }}
uses: actions-cool/maintain-one-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
⚡️ Deploying PR Preview ${{ github.event.pull_request.head.sha }} to [surge.sh](https://alibaba-graphar-build-pr-${{ github.event.number }}.surge.sh) ... [Build logs](https://github.com/alibaba/GraphAr/runs/${{ github.run_id }})
<a href="https://github.com/alibaba/GraphAr/actions/runs/${{ github.run_id }}">
<img width="300" src="https://user-images.githubusercontent.com/507615/90240294-8d2abd00-de5b-11ea-8140-4840a0b2d571.gif">
</a>
<sub>🤖 By [surge-preview](https://surge.sh/)</sub>
body-include: '<!-- Sticky Pull Request Comment: Surge Preview build -->'

- name: Install dependencies
run: |
sudo apt-get update -y
Expand All @@ -47,17 +68,43 @@ jobs:
make doc
popd
- name: preview
uses: afc163/surge-preview@v1
id: preview_step
- name: Preview using surge
if: ${{ github.event_name == 'pull_request_target' && github.repository == 'alibaba/GraphAr' }}
run: |
npm install -g surge
surge ./docs/_build/html \
alibaba-graphar-build-pr-${{ github.event.number }}.surge.sh \
--token ${{ secrets.SURGE_TOKEN }}
- name: Leave the comment on pull request when succeed
if: ${{ github.event_name == 'pull_request_target' }}
uses: actions-cool/maintain-one-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
🎊 PR Preview ${{ github.event.pull_request.head.sha }} has been successfully built and deployed to https://alibaba-graphar-build-pr-${{ github.event.number }}.surge.sh
<a href="https://github.com/alibaba/GraphAr/actions/runs/${{ github.run_id }}">
<img width="300" src="https://user-images.githubusercontent.com/507615/90250366-88233900-de6e-11ea-95a5-84f0762ffd39.png">
</a>
<sub>🤖 By [surge-preview](https://surge.sh/)</sub>
body-include: '<!-- Sticky Pull Request Comment: Surge Preview build -->'

- name: Leave the comment on pull request when failed
if: ${{ failure() && github.event_name == 'pull_request_target' }}
uses: actions-cool/maintain-one-comment@v3
with:
surge_token: ${{ secrets.SURGE_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
dist: docs/_build/html
build: echo "done"
token: ${{ secrets.GITHUB_TOKEN }}
body: |
😭 Deploy PR Preview ${{ github.event.pull_request.head.sha }} failed. [Build logs](https://github.com/alibaba/GraphAr/runs/${{ github.run_id }})
<a href="https://github.com/alibaba/GraphAr/actions/runs/${{ github.run_id }}">
<img width="300" src="https://user-images.githubusercontent.com/507615/90250824-4e066700-de6f-11ea-8230-600ecc3d6a6b.png">
</a>
- name: Get the preview_url
run: echo "url => ${{ steps.preview_step.outputs.preview_url }}"
<sub>🤖 By [surge-preview](https://surge.sh/)</sub>
body-include: '<!-- Sticky Pull Request Comment: Surge Preview build -->'

- name: Commit Doc
if: ${{ github.ref == 'refs/heads/main' && github.repository == 'alibaba/GraphAr' }}
Expand Down

0 comments on commit c31a88b

Please sign in to comment.