Skip to content
Open
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
65 changes: 65 additions & 0 deletions .github/scripts/publish_fornax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
Script to handle Fornax branch deployment with CI
"""
import glob
from pathlib import Path
import shutil
import yaml

FORNAX_NOTEBOOK_BASEPATH = "mast_notebooks"
FORNAX_MANIFEST = "fornax-manifest.yml"
FORNAX_REQUIREMENTS = "requirements_mast_tutorials.txt"
FORNAX_METADATA_YAML = "notebook_metadata.yml"


def main():
"""
Do Fornax branch formatting.
"""

with open(FORNAX_MANIFEST, "r", encoding="utf-8") as f:
manifest = yaml.safe_load(f)

# Fornax-preferred renaming:
Path(FORNAX_NOTEBOOK_BASEPATH).mkdir(parents=True, exist_ok=True)

# Copy & rename requirements:
shutil.copy(
manifest["global-requirements"][0]["requirements-file"],
f"{FORNAX_NOTEBOOK_BASEPATH}/{FORNAX_REQUIREMENTS}"
)

# Copy notebooks over & create reformatted metadata dict:
nbs_metadata = []
for nb in manifest["notebooks"]:
# Copy files:
orig_path = '/'.join(nb['file'].split('/')[:-1])
new_path = orig_path.replace("notebooks/", f"{FORNAX_NOTEBOOK_BASEPATH}/")
shutil.copytree(orig_path, new_path, dirs_exist_ok=True)

# Reformatted metadata:
metadict = {}
for key in ["title", "file", "section", "subsection", "description"]:
val = nb.get(key, None)
if val is not None:
metadict[key] = val

# Update filename:
metadict[key] = metadict[key].replace("notebooks/", f"{FORNAX_NOTEBOOK_BASEPATH}/")
nbs_metadata.append(metadict)

# Remove the individual file reqiurements.txt files:
for file in glob.glob(
f"{FORNAX_NOTEBOOK_BASEPATH}/**/requirements.txt", recursive=True
):
# print(file)
Path(file).unlink(missing_ok=True)

# Write out a stripped down yml file with metadata:
# Title, section, subsection, file
with open(f"{FORNAX_METADATA_YAML}", 'w', encoding="utf-8") as f:
yaml.dump(nbs_metadata, f, default_flow_style=False, sort_keys=False)


if __name__ == "__main__":
main()
38 changes: 38 additions & 0 deletions .github/workflows/fornax_branch_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy MAST notebooks to Fornax branch

on:
push:
branches: [ main, fornax-manifest ]
workflow_dispatch:

jobs:
deploy_notebooks:
name: Deploy deploy_to_fornax branch
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'

- name: Install dependencies
run: pip install pyaml

- name: Deploy to deploy_to_fornax branch
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
gith=$(git rev-parse HEAD)
git checkout --orphan deploy_to_fornax
git rm --cached -r .
# Do Fornax preferred renaming
python .github/scripts/publish_fornax.py
git add mast_notebooks
git commit -m "Deploy for fornax for commit ${gith}"
git add notebook_metadata.yml
git commit -m "Adding notebook metadata"
git push origin deploy_to_fornax --force
Loading
Loading