Skip to content

Commit 64ec47f

Browse files
Saransh-cppdarsnack
authored andcommitted
Get the infrastructure up
* Fix deployment script * Enable previews * Store previews in gh-pages * Update GH Action dependencies * Remove non-prod code
1 parent ac1bbe9 commit 64ec47f

File tree

4 files changed

+67
-8
lines changed

4 files changed

+67
-8
lines changed

.github/workflows/CleanPreview.yml

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

.github/workflows/Comment.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: PR Comment # Write a comment in the PR with a link to the preview of the given website
2+
on:
3+
pull_request:
4+
types: [opened, reopened]
5+
jobs:
6+
pr_comment:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Create PR comment
10+
if: github.event_name == 'pull_request' && github.repository == github.event.pull_request.head.repo.full_name # if this is a pull request build AND the pull request is NOT made from a fork
11+
uses: thollander/actions-comment-pull-request@71efef56b184328c7ef1f213577c3a90edaa4aff
12+
with:
13+
message: 'Once the build has completed, you can preview your PR at this URL: https://fluxml.ai/previews/PR${{ github.event.number }}/'
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
branches:
55
- master
66
- main
7+
pull_request:
8+
79
jobs:
810
build-and-deploy:
911
runs-on: ubuntu-latest
@@ -14,7 +16,7 @@ jobs:
1416
persist-credentials: false
1517
# NOTE: Python is necessary for the pre-rendering (minification) step
1618
- name: Install python
17-
uses: actions/setup-python@v2
19+
uses: actions/setup-python@v4
1820
with:
1921
python-version: '3.8'
2022
# NOTE: Here you can install dependencies such as matplotlib if you use
@@ -36,9 +38,25 @@ jobs:
3638
using Franklin;
3739
Pkg.activate("."); Pkg.instantiate();
3840
optimize()'
39-
- name: Build and Deploy
40-
uses: JamesIves/github-pages-deploy-action@releases/v3
41+
- name: Fix URLs for PR preview deployment (pull request previews)
42+
if: github.event_name == 'pull_request'
43+
run: |
44+
echo "PREVIEW_FRANKLIN_WEBSITE_URL=https://fluxml.ai/previews/PR${{ github.event.number }}/" >> $GITHUB_ENV
45+
echo "PREVIEW_FRANKLIN_PREPATH=previews/PR${{ github.event.number }}" >> $GITHUB_ENV
46+
- name: Deploy (preview)
47+
if: github.event_name == 'pull_request' && github.repository == github.event.pull_request.head.repo.full_name # if this build is a PR build and the PR is NOT from a fork
48+
uses: JamesIves/github-pages-deploy-action@releases/v4
4149
with:
42-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43-
BRANCH: gh-pages
44-
FOLDER: __site
50+
branch: gh-pages # The branch where the PRs previews are stored
51+
folder: __site
52+
token: ${{ secrets.GITHUB_TOKEN }}
53+
target-folder: "previews/PR${{ github.event.number }}" # The website preview is going to be stored in a subfolder
54+
- name: Deploy (main)
55+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
56+
uses: JamesIves/github-pages-deploy-action@releases/v4
57+
with:
58+
token: ${{ secrets.GITHUB_TOKEN }}
59+
branch: gh-pages # Replace here the branch where your website is deployed
60+
folder: __site
61+
clean-exclude: |
62+
previews/*

config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ website_twitter_url = "https://twitter.com/FluxML?ref_src=twsrc%5Etfw"
1414

1515
ignore = ["_old/", "CONTRIBUTING.md"]
1616

17-
# Adjust when moving to prod (note: if fluxml.ai, then no need for prepath)
18-
prepath = "fluxml-franklin"
17+
prepath = get(ENV, "PREVIEW_FRANKLIN_PREPATH", ".")
18+
website_url = get(ENV, "PREVIEW_FRANKLIN_WEBSITE_URL", "fluxml.ai")
1919
+++
2020

2121
\newcommand{\totop}{~~~<p><a href="#top">⇧ back to top</a></p>~~~}

0 commit comments

Comments
 (0)