Skip to content

eqctier3-351f07a4-f372-41a0-b8b2-c0bd2709daac #244

eqctier3-351f07a4-f372-41a0-b8b2-c0bd2709daac

eqctier3-351f07a4-f372-41a0-b8b2-c0bd2709daac #244

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
needs: pre-commit
steps:
- uses: actions/checkout@v4
- run: git fetch origin gh-pages
- uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: 'pip'
- 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
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@v2
with:
message: |
**Permalinks:**
${{ steps.build-urls.outputs.permalinks }}
comment_tag: permalinks
- name: Comment PR with previews
uses: thollander/actions-comment-pull-request@v2
with:
message: |
**Previews:**
${{ steps.build-urls.outputs.previews }}
comment_tag: previews