Skip to content

Commit 31354e9

Browse files
committed
Build preview for pull requests from same repository
1 parent 8eb57ed commit 31354e9

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

.github/workflows/Deploy.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,49 @@ on:
44
push:
55
branches:
66
- main
7+
pull_request:
8+
9+
concurrency:
10+
# Skip intermediate builds: always.
11+
# Cancel intermediate builds: always.
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
714

815
jobs:
16+
preview:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
preview: ${{ steps.set-preview.outputs.preview }}
20+
steps:
21+
- name: Set Preview
22+
id: set-preview
23+
run: |
24+
if [[ ${{ github.event_name }} == "pull_request" ]]; then
25+
PREVIEW="previews/PR${PRNUM}"
26+
else
27+
PREVIEW=""
28+
fi
29+
echo "preview=${PREVIEW}"
30+
echo "preview=${PREVIEW}" >> "${GITHUB_OUTPUT}"
31+
env:
32+
PRNUM: ${{ github.event.number }}
33+
934
deploy:
35+
needs: preview
1036
runs-on: ubuntu-latest
1137
permissions: write-all
1238
steps:
13-
- uses: actions/checkout@v2
39+
- uses: actions/checkout@v3
40+
- uses: julia-actions/cache@v1
1441
- uses: tlienart/[email protected]
42+
if: github.event_name != 'pull_request' || github.repository == github.event.pull_request.head.repo.full_name # if this build is NOT a PR build, OR if this build is a PR build and the PR is NOT from a fork
1543
with:
1644
# NOTE: this is the Xranklin branch the site is built with
1745
BRANCH: "dev"
1846
# NOTE: this is the base URL prefix (landing page at /$BASE_URL_PREFIX/)
1947
BASE_URL_PREFIX: ""
48+
# Directory where to deploy the website.
49+
PREVIEW: ${{ needs.preview.outputs.preview }}
2050

2151
# ===================================================================
2252
# DON'T CHANGE THE FOLLOWING UNLESS YOU HAVE GOOD REASONS TO

.github/workflows/PreviewCleanup.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Doc Preview Cleanup
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
doc-preview-cleanup:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout gh-pages branch
12+
uses: actions/checkout@v3
13+
with:
14+
ref: gh-pages
15+
- name: Delete preview and history + push changes
16+
run: |
17+
if [ -d "previews/PR$PRNUM" ]; then
18+
git config user.name "JuliaParallel"
19+
git config user.email "[email protected]"
20+
git rm -rf "previews/PR$PRNUM"
21+
git commit -m "delete preview"
22+
git branch gh-pages-new $(echo "delete history" | git commit-tree HEAD^{tree})
23+
git push --force origin gh-pages-new:gh-pages
24+
fi
25+
env:
26+
PRNUM: ${{ github.event.number }}

0 commit comments

Comments
 (0)