diff --git a/.github/workflows/ExportNotebooks.yml b/.github/workflows/ExportNotebooks.yml index c011442f..7a72d033 100644 --- a/.github/workflows/ExportNotebooks.yml +++ b/.github/workflows/ExportNotebooks.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/PRCleanup.yml b/.github/workflows/PRCleanup.yml new file mode 100644 index 00000000..404eeea3 --- /dev/null +++ b/.github/workflows/PRCleanup.yml @@ -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 "documenter@juliadocs.github.io" + 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 }} \ No newline at end of file diff --git a/.github/workflows/PRComment.yml b/.github/workflows/PRComment.yml new file mode 100644 index 00000000..a4c048c6 --- /dev/null +++ b/.github/workflows/PRComment.yml @@ -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 }} \ No newline at end of file