Skip to content

Commit 80be35e

Browse files
added preview workflow (#83)
1 parent f830089 commit 80be35e

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

.github/workflows/preview.yml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: PR Preview Workflow
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, synchronize, closed]
6+
7+
jobs:
8+
build-and-preview:
9+
if: github.event.action == 'opened' || github.event.action == 'synchronize'
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Quarto
16+
uses: quarto-dev/quarto-actions/setup@v2
17+
18+
- run: quarto --version
19+
20+
- name: Render Quarto site
21+
run: quarto render
22+
23+
- name: Deploy to GitHub Pages
24+
uses: JamesIves/github-pages-deploy-action@v4
25+
with:
26+
branch: gh-pages
27+
folder: _site
28+
target-folder: pr-previews/${{ github.event.pull_request.number }}
29+
clean: false
30+
commit-message: Deploy preview for PR ${{ github.event.pull_request.number }}
31+
token: ${{ secrets.GITHUB_TOKEN }}
32+
33+
comment-preview-url:
34+
needs: build-and-preview
35+
if: needs.build-and-preview.result == 'success'
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Comment Preview URL
39+
uses: thollander/actions-comment-pull-request@v2
40+
with:
41+
message: |
42+
<!-- preview-url-comment -->
43+
Preview the changes: https://turinglang.org/pr-previews/${{ github.event.pull_request.number }}
44+
Please avoid using the search feature and navigation bar in PR previews!
45+
comment_tag: preview-url-comment
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
49+
delete-preview-directory:
50+
if: github.event.action == 'closed' || github.event.pull_request.merged == true
51+
runs-on: ubuntu-latest
52+
steps:
53+
- name: Checkout gh-pages branch
54+
uses: actions/checkout@v4
55+
with:
56+
ref: gh-pages
57+
58+
- name: Remove PR Preview Directory
59+
run: |
60+
PR_NUMBER=${{ github.event.pull_request.number }}
61+
PREVIEW_DIR="pr-previews/${PR_NUMBER}"
62+
git config --global user.name "github-actions[bot]"
63+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
64+
git pull origin gh-pages
65+
rm -rf ${PREVIEW_DIR}
66+
git add .
67+
git commit -m "Remove preview for merged PR #${PR_NUMBER}"
68+
git push
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)