Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Deploy to Pages

on:
push:
branches:
- master
- pages
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set Python
uses: actions/setup-python@v5
with:
python-version: 3.13
- name: Build site
run: src/python/build_site.py
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: '_site'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__
*egg-info
src/python/build
Benchmark-Models/Smith_BMCSystBiol2013/amici_models/*
/_site/
60 changes: 60 additions & 0 deletions src/python/build_site.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
"""Prepare static site for deployment to GitHub pages."""

import shutil
from pathlib import Path
import subprocess


REPO_ROOT = Path(__file__).parents[2]
SITE_ROOT = REPO_ROOT / "_site"


def main():
"""Main function to build the static site."""
if not (REPO_ROOT / ".git").is_dir():
raise AssertionError("Repo root is not a git repository")

print("Building static site at ", SITE_ROOT.absolute())

if SITE_ROOT.exists():
print("Removing existing static site directory")
shutil.rmtree(SITE_ROOT)

SITE_ROOT.mkdir(parents=True)

copy_worktree(SITE_ROOT / "tree")

print("Done.")


def copy_worktree(dest: Path):
"""Copy the worktree to the static site directory."""
print("Copying worktree to ", dest.absolute())
git_archive_unpack(dest)


def git_archive_unpack(output_dir: Path):
"""Create a git archive and unpack it to the specified directory."""
output_dir = output_dir.resolve()
if not output_dir.exists():
output_dir.mkdir(parents=True)

# Create the git archive and unpack it
try:
ga = subprocess.Popen(
["git", "archive", "--format=tar", "HEAD"],
stdout=subprocess.PIPE,
)
subprocess.check_output(
["tar", "-x", "-C", str(output_dir)],
stdin=ga.stdout,
)
print(f"Repository contents unpacked to: {output_dir}")
except subprocess.CalledProcessError as e:
print(f"Error during git archive or unpacking: {e}")
raise


if __name__ == "__main__":
main()