Skip to content

Commit

Permalink
add preview page
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Jul 23, 2024
1 parent 815d57f commit 186ede2
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Preview Sphinx site

on:
pull_request:
branches: [ main ]

jobs:
build_and_preview:
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4

- name: Setup Micromamba
uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822 #v1
with:
environment-name: IOOS
init-shell: bash
create-args: >-
--file .binder/conda-lock.yml
- name: Build documentation
shell: bash -l {0}
run: >
set -e
&& jupyter-book build jupyterbook --builder linkcheck
&& jupyter-book build jupyterbook
- name: Commit documentation changes to preview branch
run: |
if git clone https://github.com/ioos/ioos_code_lab.git --branch ${{ github.head_ref }}-preview --single-branch gh-pages ; then
cd gh-pages
echo "COMMENT_ON_PR=false" >> $GITHUB_ENV
else
git clone https://github.com/ioos/ioos_code_lab.git --branch gh-pages --single-branch gh-pages
cd gh-pages
git checkout -b ${{ github.head_ref }}-preview
echo "COMMENT_ON_PR=true" >> $GITHUB_ENV
fi
cp -r ../jupyterbook/_build/html .
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m "Update documentation" -a || true
- name: Push documentation changes to preview branch
uses: ad-m/github-push-action@77c5b412c50b723d2a4fbc6d71fb5723bcd439aa # latest-main
with:
branch: ${{ github.head_ref }}-preview
directory: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Leave comment on pull request
if: env.COMMENT_ON_PR == 'true'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Thank you for your contributions!\n\nA preview of your changes can be viewed at:\n- https://raw.githack.com/ioos/ioos_code_lab/${{ github.head_ref }}-preview/index.html'
})

0 comments on commit 186ede2

Please sign in to comment.