Merge pull request #10 from LinkedEarth/check #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sync JupyterBook | |
on: | |
push: | |
branches: [ main ] | |
workflow_dispatch: | |
jobs: | |
sync-jupyterbook: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
defaults: | |
run: | |
shell: bash -l {0} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: conda-incubator/setup-miniconda@v2 | |
with: | |
activate-environment: pylipd | |
environment-file: environment.yml | |
auto-activate-base: false | |
- name: Install dependencies | |
run: | | |
conda activate pylipd | |
pip install pyyaml | |
- name: Configure Git | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
- name: Copy Files and Update TOC | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git checkout jupyterbook | |
rm -rf notebooks/ data/ figures/ | |
git checkout main -- notebooks/ data/ figures/ | |
cat << 'EOF' > update_toc.py | |
import yaml | |
import glob | |
import os | |
toc = { | |
'format': 'jb-book', | |
'root': 'intro', | |
'parts': [ | |
{'caption': 'Dataset Representation in PyLiPD', 'chapters': [ | |
{'file': 'graph.md'}, | |
{'file': 'standards.md'} | |
]}, | |
{'caption': 'Getting Started', 'chapters': []}, | |
{'caption': 'Basic Functionalities', 'chapters': []}, | |
{'caption': 'Advanced Querying using SPARQL', 'chapters': []}, | |
{'caption': 'Editing LiPD files', 'chapters': []} | |
] | |
} | |
level_map = {'L0': 1, 'L1': 2, 'L2': 3, 'L3': 4} # Mapping to correct sections | |
notebooks = sorted(glob.glob('notebooks/L*.ipynb')) | |
for nb in notebooks: | |
level = os.path.basename(nb)[:2] # Extract L0, L1, etc. | |
if level in level_map: | |
part_index = level_map[level] | |
toc['parts'][part_index]['chapters'].append({'file': nb}) | |
with open('_toc.yml', 'w') as f: | |
yaml.dump(toc, f, sort_keys=False) | |
EOF | |
conda activate pylipd | |
python update_toc.py | |
git add notebooks/ data/ figures/ _toc.yml | |
if ! git diff --staged --quiet; then | |
git commit -m "Auto-sync notebooks, data, figures, and update TOC" | |
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}" | |
git push origin jupyterbook | |
fi |