Skip to content

Commit 518fc23

Browse files
committed
Add PR preview
1 parent 56fa6f6 commit 518fc23

2 files changed

Lines changed: 88 additions & 2 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@ on:
44
push:
55
branches:
66
- main
7+
workflow_dispatch:
8+
pull_request:
79

810
jobs:
9-
deploy:
11+
deploy-main:
1012
runs-on: ubuntu-latest
1113
permissions:
1214
contents: write
1315
concurrency:
1416
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
if: ${{ github.ref == 'refs/heads/main' }}
19+
1520
steps:
1621
- uses: actions/checkout@v4
1722

18-
# Build documentation repo
1923
- uses: actions/setup-node@v4
2024
with:
2125
node-version: lts/*
@@ -35,3 +39,54 @@ jobs:
3539
github_token: ${{ secrets.GITHUB_TOKEN }}
3640
publish_dir: ./build
3741
cname: revisit.dev
42+
keep_files: true
43+
44+
deploy-preview:
45+
runs-on: ubuntu-latest
46+
permissions:
47+
contents: write
48+
pull-requests: write
49+
concurrency:
50+
group: ${{ github.workflow }}-${{ github.ref }}
51+
cancel-in-progress: true
52+
if: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/dev' }}
53+
54+
steps:
55+
- name: Comment on PR
56+
uses: hasura/comment-progress@v2.2.0
57+
with:
58+
github-token: ${{ secrets.GITHUB_TOKEN }}
59+
repository: ${{ github.repository }}
60+
number: ${{ github.event.number }}
61+
id: deploy-preview
62+
message: "Starting deployment of preview ⏳..."
63+
64+
- uses: actions/checkout@v4
65+
66+
- uses: actions/setup-node@v4
67+
with:
68+
node-version: lts/*
69+
cache: 'yarn'
70+
71+
- run: yarn install --immutable
72+
73+
- name: Build with PR base path
74+
run: yarn build
75+
env:
76+
DOCUSAURUS_BASE_URL: "/PR${{ github.event.number }}/"
77+
78+
- name: Push PR deploy preview
79+
uses: peaceiris/actions-gh-pages@v3
80+
with:
81+
github_token: ${{ secrets.GITHUB_TOKEN }}
82+
publish_dir: ./build
83+
destination_dir: "PR${{ github.event.number }}"
84+
85+
- name: Update comment
86+
uses: hasura/comment-progress@v2.2.0
87+
with:
88+
github-token: ${{ secrets.GITHUB_TOKEN }}
89+
repository: ${{ github.repository }}
90+
number: ${{ github.event.number }}
91+
id: deploy-preview
92+
message: "A preview of ${{ github.event.after }} is uploaded and can be seen here:\n\n ✨ https://revisit.dev/PR${{ github.event.number }} ✨\n\nChanges may take a few minutes to propagate."

.github/workflows/pr_close.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: delete preview on PR close
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
delete_preview:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
steps:
14+
- name: make empty dir
15+
run: mkdir public
16+
17+
- name: delete folder
18+
uses: peaceiris/actions-gh-pages@v3
19+
with:
20+
github_token: ${{ secrets.GITHUB_TOKEN }}
21+
publish_dir: ./public
22+
destination_dir: "PR${{ github.event.number }}"
23+
24+
- name: Comment on PR
25+
uses: hasura/comment-progress@v2.2.0
26+
with:
27+
github-token: ${{ secrets.GITHUB_TOKEN }}
28+
repository: ${{ github.repository }}
29+
number: ${{ github.event.number }}
30+
id: deploy-preview
31+
message: "🪓 PR closed, deleted preview."

0 commit comments

Comments
 (0)