Skip to content

Commit aca4a6e

Browse files
authored
1 parent 2a87adc commit aca4a6e

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

.github/workflows/gh-pages.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Deploy to Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- pages
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
pages: write
13+
id-token: write
14+
15+
concurrency:
16+
group: "pages"
17+
cancel-in-progress: false
18+
19+
jobs:
20+
deploy:
21+
environment:
22+
name: github-pages
23+
url: ${{ steps.deployment.outputs.page_url }}
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
- name: Set Python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: 3.13
32+
- name: Build site
33+
run: src/python/build_site.py
34+
- name: Setup Pages
35+
uses: actions/configure-pages@v5
36+
- name: Upload artifact
37+
uses: actions/upload-pages-artifact@v3
38+
with:
39+
path: '_site'
40+
- name: Deploy to GitHub Pages
41+
id: deployment
42+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ __pycache__
55
*egg-info
66
src/python/build
77
Benchmark-Models/Smith_BMCSystBiol2013/amici_models/*
8+
/_site/

src/python/build_site.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python3
2+
"""Prepare static site for deployment to GitHub pages."""
3+
4+
import shutil
5+
from pathlib import Path
6+
import subprocess
7+
8+
9+
REPO_ROOT = Path(__file__).parents[2]
10+
SITE_ROOT = REPO_ROOT / "_site"
11+
12+
13+
def main():
14+
"""Main function to build the static site."""
15+
if not (REPO_ROOT / ".git").is_dir():
16+
raise AssertionError("Repo root is not a git repository")
17+
18+
print("Building static site at ", SITE_ROOT.absolute())
19+
20+
if SITE_ROOT.exists():
21+
print("Removing existing static site directory")
22+
shutil.rmtree(SITE_ROOT)
23+
24+
SITE_ROOT.mkdir(parents=True)
25+
26+
copy_worktree(SITE_ROOT / "tree")
27+
28+
print("Done.")
29+
30+
31+
def copy_worktree(dest: Path):
32+
"""Copy the worktree to the static site directory."""
33+
print("Copying worktree to ", dest.absolute())
34+
git_archive_unpack(dest)
35+
36+
37+
def git_archive_unpack(output_dir: Path):
38+
"""Create a git archive and unpack it to the specified directory."""
39+
output_dir = output_dir.resolve()
40+
if not output_dir.exists():
41+
output_dir.mkdir(parents=True)
42+
43+
# Create the git archive and unpack it
44+
try:
45+
ga = subprocess.Popen(
46+
["git", "archive", "--format=tar", "HEAD"],
47+
stdout=subprocess.PIPE,
48+
)
49+
subprocess.check_output(
50+
["tar", "-x", "-C", str(output_dir)],
51+
stdin=ga.stdout,
52+
)
53+
print(f"Repository contents unpacked to: {output_dir}")
54+
except subprocess.CalledProcessError as e:
55+
print(f"Error during git archive or unpacking: {e}")
56+
raise
57+
58+
59+
if __name__ == "__main__":
60+
main()

0 commit comments

Comments
 (0)