Skip to content

Commit

Permalink
preview website on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
greimel committed Oct 4, 2024
1 parent 13c1636 commit 0b46ee7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/ExportNotebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,21 @@ jobs:
mv _site www/Fall23
mv extra_outputs/* www
- name: 🚀 Deploy to GitHub Pages
- name: 🚀 Deploy to GitHub Pages (main)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: output
FOLDER: www
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: output
FOLDER: www
CLEAN_EXCLUDE: |
previews/*
- name: Deploy PR preview
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
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: output
FOLDER: www
TARGET_FOLDER: "previews/PR${{ github.event.number }}" # The website preview is going to be stored in the previews subfolder
29 changes: 29 additions & 0 deletions .github/workflows/PRCleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# from https://github.com/CliMA/ClimaTimeSteppers.jl
# and https://github.com/JuliaPluto/computational-thinking-template

name: Site Preview Cleanup

on:
pull_request:
types: [closed]

jobs:
doc-preview-cleanup:
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages branch
uses: actions/checkout@v2
with:
ref: output
- name: Delete preview and history + push changes
run: |
if [ -d "previews/PR$PRNUM" ]; then
git config user.name "Documenter.jl"
git config user.email "[email protected]"
git rm -rf "previews/PR$PRNUM"
git commit -m "delete preview"
git branch output-new $(echo "delete history" | git commit-tree HEAD^{tree})
git push --force origin output-new:output
fi
env:
PRNUM: ${{ github.event.number }}
14 changes: 14 additions & 0 deletions .github/workflows/PRComment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: PR Comment # Write a comment in the PR with a link to the preview of the given website
on:
pull_request:
types: [opened, reopened]
jobs:
pr_comment:
runs-on: ubuntu-latest
steps:
- name: Create PR comment
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
uses: thollander/actions-comment-pull-request@71efef56b184328c7ef1f213577c3a90edaa4aff
with:
message: 'Once the build has completed, you can preview your PR at this URL: https://${{ github.event.pull_request.base.repo.owner.login }}.github.io/${{ github.event.pull_request.base.repo.name }}/previews/PR${{ github.event.number }}/'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 0b46ee7

Please sign in to comment.