reduce deployments #314
Workflow file for this run
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
name: on-pull-request | |
on: | |
pull_request: | |
types: | |
- opened | |
- reopened | |
- synchronize | |
- closed | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
PRE_BUILD_DIR: "_pre_build" | |
PRE_BUILD_FLAGS: "--disclaimer" | |
defaults: | |
run: | |
shell: bash -l {0} | |
jobs: | |
pre-commit: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
- uses: pre-commit/[email protected] | |
deploy-preview: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
- run: git fetch origin gh-pages | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
cache: 'pip' | |
- uses: actions/checkout@v4 | |
- name: Get changed notebooks | |
id: changed-files | |
uses: tj-actions/changed-files@v45 | |
with: | |
files: | | |
**.ipynb | |
- name: Remove untouched notebooks | |
id: remove-untouched-notebooks | |
env: | |
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} | |
run: |- | |
for file in ${ALL_CHANGED_FILES}; do | |
mv "$file" "$file".keep | |
done | |
find . -type f -name "*.ipynb" -not -path "./templates/*" -exec rm -f {} + | |
for file in ${ALL_CHANGED_FILES}; do | |
mv "$file".keep "$file" | |
done | |
- run: pip install -r requirements.txt | |
- run: make build-book PRE_BUILD_DIR=${{ env.PRE_BUILD_DIR }} PRE_BUILD_FLAGS=${{ env.PRE_BUILD_FLAGS }} | |
- uses: rossjrw/pr-preview-action@v1 | |
if: steps.changed-files.outputs.any_changed == 'true' | |
with: | |
source-dir: "${{ env.PRE_BUILD_DIR }}/_build/html" | |
comment-pr: | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get changed notebooks | |
id: changed-files | |
uses: tj-actions/changed-files@v45 | |
with: | |
files: | | |
**.ipynb | |
- name: Build permalinks | |
id: build-permalinks | |
env: | |
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} | |
run: |- | |
permalinks="<ul>" | |
for fullfile in ${ALL_CHANGED_FILES}; do | |
fullfile="${fullfile//\\&/&}" | |
commit=$(git rev-list -1 HEAD "$fullfile") | |
suffix="${fullfile//&/%26}" | |
url=${{ github.server_url }}/${{ github.repository }}/blob/$commit/$suffix | |
permalinks+="<li><a href=\"$url\">$url</a></li>" | |
done | |
permalinks+="</ul>" | |
echo "permalinks=$permalinks" >>"$GITHUB_OUTPUT" | |
- name: Build URLs | |
id: build-urls | |
env: | |
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} | |
run: |- | |
permalinks="<ul>" | |
previews="<ul>" | |
for fullfile in ${ALL_CHANGED_FILES}; do | |
fullfile="${fullfile//\\&/&}" | |
commit=$(git rev-list -1 HEAD "$fullfile") | |
suffix="${fullfile//&/%26}" | |
permalink=${{ github.server_url }}/${{ github.repository }}/blob/$commit/$suffix | |
permalinks+="<li><a href=\"$permalink\">$permalink</a></li>" | |
suffix="${fullfile/.ipynb/.html}" | |
preview=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.number }}/$suffix | |
previews+="<li><a href=\"$preview\">$preview</a></li>" | |
done | |
permalinks+="</ul>" | |
echo "permalinks=$permalinks" >>"$GITHUB_OUTPUT" | |
previews+="</ul>" | |
echo "previews=$previews" >>"$GITHUB_OUTPUT" | |
- name: Comment PR with permalinks | |
uses: thollander/actions-comment-pull-request@v3 | |
with: | |
message: | | |
**Permalinks:** | |
${{ steps.build-urls.outputs.permalinks }} | |
comment-tag: permalinks | |
- name: Comment PR with previews | |
uses: thollander/actions-comment-pull-request@v3 | |
with: | |
message: | | |
**Previews:** | |
${{ steps.build-urls.outputs.previews }} | |
comment-tag: previews |