Skip to content

self-hosted

self-hosted #358

Workflow file for this run

name: CI
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
JULIA_CI: 'true'
JULIA_CONDAPKG_BACKEND: 'Null'
JULIA_CONDAPKG_OFFLINE: 'true'
JULIA_NUM_THREADS: 'auto'
# JULIA_CPU_TARGET: 'generic;icelake-server,clone_all;znver3,clone_all'
NBCACHE: '.cache'
LITERATE_PROC: '6'
PY_VER: '3.13'
jobs:
CI:
runs-on: self-hosted
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Python
uses: actions/setup-python@v6
id: setup-python
with:
python-version: ${{ env.PY_VER }}
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v7
- name: Install Python dependencies
run: uv pip install --system -r requirements.txt
- name: Read Julia version
id: julia-version
run: python -c 'import tomllib; from pathlib import Path; print("value=", tomllib.loads(Path("Manifest.toml").read_text())["julia_version"], sep="")' >> "$GITHUB_OUTPUT"
- name: Get hashes
id: hash
run: |
echo "ver=${{ runner.os }}-julia-${{ steps.julia-version.outputs.value }}" >> "$GITHUB_OUTPUT"
echo "value=${{ hashFiles('Project.toml', 'Manifest.toml', 'src/**') }}" >> "$GITHUB_OUTPUT"
echo "nb=${{ hashFiles('docs/**/*.jl', 'docs/**/*.ipynb') }}" >> "$GITHUB_OUTPUT"
- name: Cache executed notebooks
uses: actions/cache@v4
id: cache-nb
with:
path: |
${{ env.NBCACHE }}/**/*.ipynb
${{ env.NBCACHE }}/**/*.sha
key: notebook-${{ steps.hash.outputs.value }}-${{ steps.hash.outputs.nb }}
restore-keys: |
notebook-${{ steps.hash.outputs.value }}-
- name: Setup Julia
uses: julia-actions/setup-julia@v2
with:
version: ${{ steps.julia-version.outputs.value }}
arch: ${{ runner.arch }}
show-versioninfo: 'true'
- name: Restore Julia packages
uses: actions/cache/restore@v4
if: ${{ runner.environment == 'github-hosted' }}
id: cache-julia
with:
path: ~/.julia
key: ${{ steps.hash.outputs.ver }}-${{ steps.hash.outputs.value }}
restore-keys: |
${{ steps.hash.outputs.ver }}-
- name: Install Julia packages
if: ${{ runner.environment == 'self-hosted' || steps.cache-julia.outputs.cache-hit != 'true' }}
shell: julia --color=yes {0}
run: |
using Pkg, Dates
Pkg.add(["Literate", "JSON", "Tables", "MarkdownTables", "SHA"])
Pkg.activate(".")
Pkg.instantiate()
Pkg.precompile()
if ENV["RUNNER_ENVIRONMENT"] == "github-hosted"
Pkg.gc(;collect_delay=Day(0))
end
- name: Save Julia packages
uses: actions/cache/save@v4
if: ${{ runner.environment == 'github-hosted' && steps.cache-julia.outputs.cache-hit != 'true' }}
with:
path: ~/.julia
key: ${{ steps.cache-julia.outputs.cache-primary-key }}
- name: Run notebooks
if: ${{ steps.cache-nb.outputs.cache-hit != 'true' }}
run: julia --project=@. --color=yes -p ${{ env.LITERATE_PROC }} .github/ci.jl
- name: Upload Notebooks
uses: actions/upload-artifact@v5
if: ${{ github.ref == 'refs/heads/main' }}
with:
path: ${{ env.NBCACHE }}/**/*.ipynb
include-hidden-files: true
name: notebooks
retention-days: 1
- name: Copy back built notebooks
run: cp --verbose -rf ${{ env.NBCACHE }}/docs/* docs/
- name: Build website
run: uvx --from 'jupyter-book<2' jupyter-book build docs/
- name: Upload pages artifact
if: ${{ github.ref == 'refs/heads/main' }}
uses: actions/upload-pages-artifact@v4
with:
path: docs/_build/html/
# Deployment job
deploy:
name: Deploy to GitHub pages and Notebook branch
needs: CI
if: ${{ github.ref == 'refs/heads/main' }}
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
contents: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Download notebooks
uses: actions/download-artifact@v6
with:
name: notebooks
path: ${{ env.NBCACHE }}
- name: Copy back built notebooks
run: |
cp --verbose -rf ${{ env.NBCACHE }}/docs/* docs/
rm -rf ${{ env.NBCACHE }}
- name: Setup Python
uses: actions/setup-python@v6
id: setup-python
with:
python-version: ${{ env.PY_VER }}
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v7
- name: Install nbconvert
run: uv pip install --system nbconvert
- name: Find notebooks and clear their outputs
run: find docs/ -type f -name '*.ipynb' | parallel jupyter nbconvert --clear-output --inplace {}
- name: Deploy notebooks
uses: peaceiris/actions-gh-pages@v4
with:
publish_dir: .
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: ipynb
force_orphan: true
commit_message: ${{ github.event.head_commit.message }}
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4