-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update actions to preview on GitHub Pages (#51)
* Update actions to preview on GitHub Pages * Tweak paths
- Loading branch information
1 parent
9b19ac3
commit e10662a
Showing
8 changed files
with
200 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: build-site | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
environment_name: | ||
description: 'Name of conda environment to activate' | ||
required: false | ||
default: 'pythia' | ||
type: string | ||
environment_file: | ||
description: 'Name of conda environment file' | ||
required: false | ||
default: 'environment.yml' | ||
type: string | ||
path_to_source: | ||
description: 'Location of the Sphinx source relative to repo root' | ||
required: false | ||
default: './' | ||
type: string | ||
use_cached_environment: | ||
description: 'Flag for whether we should attempt to retrieve a previously cached environment.' | ||
required: false | ||
default: 'true' | ||
type: string # had a lot of trouble with boolean types, see https://github.com/actions/runner/issues/1483 | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash -l {0} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup Mambaforge | ||
uses: conda-incubator/setup-miniconda@v2 | ||
with: | ||
miniforge-variant: Mambaforge | ||
miniforge-version: latest | ||
activate-environment: ${{ inputs.environment_name }} | ||
use-mamba: true | ||
|
||
- name: Set cache date | ||
if: ${{ inputs.use_cached_environment == 'true' }} | ||
run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV | ||
|
||
- uses: actions/cache@v3 | ||
if: inputs.use_cached_environment == 'true' | ||
with: | ||
path: /usr/share/miniconda3/envs/${{ inputs.environment_name }} | ||
# This should create a key that looks like 'linux-64-conda-environment.yml-[HASH]-DATE' | ||
# Logic inspired by https://dev.to/epassaro/caching-anaconda-environments-on-github-actions-2d08 | ||
key: ${{ format('linux-64-conda-{0}-{1}-{2}', inputs.environment_file, hashFiles(format('{0}', inputs.environment_file)), env.DATE )}} | ||
id: cache | ||
|
||
- name: Update environment | ||
if: | | ||
inputs.use_cached_environment != 'true' | ||
|| steps.cache.outputs.cache-hit != 'true' | ||
run: mamba env update -n ${{ inputs.environment_name }} -f ${{ inputs.environment_file }} | ||
|
||
- name: Build the site | ||
run: | | ||
cd ${{ inputs.path_to_source }} | ||
make -j4 html | ||
- name: Zip the site | ||
run: | | ||
set -x | ||
set -e | ||
if [ -f site.zip ]; then | ||
rm -rf site.zip | ||
fi | ||
zip -r site.zip ${{ inputs.path_to_source }}/_build/html | ||
- name: Upload zipped site artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: site-zip-${{github.event.number}} | ||
path: ./site.zip |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: delete-preview | ||
|
||
# Only run this when the main branch changes | ||
on: | ||
pull_request_target: | ||
types: closed | ||
|
||
jobs: | ||
delete: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash -l {0} | ||
steps: | ||
- name: Checkout gh-pages branch | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: gh-pages | ||
- name: Delete preview files | ||
run: | | ||
rm -rf _preview/${{ github.event.pull_request.number }} | ||
- name: Commit the changes | ||
uses: stefanzweifel/git-auto-commit-action@v4 | ||
with: | ||
branch: gh-pages | ||
commit_message: Delete preview for pull request \#${{ github.event.pull_request.number }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: deploy-site | ||
|
||
on: | ||
# Trigger the workflow on push to main branch | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
uses: ./.github/workflows/build-site.yaml | ||
with: | ||
environment_name: pythia-tutorial-dev | ||
environment_file: environment.yml | ||
path_to_source: ./site | ||
|
||
deploy: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash -l {0} | ||
steps: | ||
- name: Download Artifact Site | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: site-zip-${{ github.event.number }} | ||
|
||
- name: Unzip the site | ||
run: | | ||
rm -rf site/_build/html | ||
unzip site.zip | ||
rm -f site.zip | ||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v3.8.0 | ||
if: github.ref == 'refs/heads/main' | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: site/_build/html | ||
keep_files: true # This preserves existing previews from open PRs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: trigger-site-build | ||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
uses: ./.github/workflows/build-site.yaml | ||
with: | ||
environment_name: pythia-tutorial-dev | ||
environment_file: environment.yml | ||
path_to_source: ./site | ||
use_cached_environment: 'true' # This is default, not strickly needed. Set to 'false' to always build a new environment |
This file was deleted.
Oops, something went wrong.
File renamed without changes.