Skip to content

Commit

Permalink
Merge pull request #18 from danielballan/restructure
Browse files Browse the repository at this point in the history
Apply toolchain developed in interactive-tutorial-demo
  • Loading branch information
danielballan authored Sep 17, 2024
2 parents 081ed14 + 9aa5111 commit 0c4c60a
Show file tree
Hide file tree
Showing 24 changed files with 5,271 additions and 405 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
27 changes: 0 additions & 27 deletions .github/workflows/_check.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .github/workflows/_nox.yml

This file was deleted.

102 changes: 102 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
name: Publish

on:
push:
branches:
- main
schedule:
- cron: '0 5 * * 1'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

build:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
name: Build Jupyter Notebooks and HTML
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup GitHub Pages
uses: actions/configure-pages@v5

- name: Setup pixi
uses: prefix-dev/[email protected]
with:
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}

- name: Build executed notebooks and HTML
run: pixi run build

- name: Upload executed notebooks as GitHub artifact
uses: actions/upload-artifact@v4
with:
name: executed-notebooks
path: build/jupyter_execute/recipes
if-no-files-found: error

- name: Prepare for Jupyter Lite
run: |
cp README.md docs/recipes/
# Convert Jupytext to ipynb format.
pixi run ./convert_all.sh ipynb
- name: Build Jupyter Lite
run: pixi run -e jupyterlite jupyter lite build --contents docs/recipes --output-dir build/html/jupyterlite

- name: Upload HTML as GitHub artifact
uses: actions/upload-pages-artifact@v3
with:
path: build/html

deploy-gh-pages:
name: Deploy HTML to GitHub Pages
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy HTML to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

deploy-notebooks:
name: Push to 'notebooks' branch ipynb-formatted version
# Sets permissions of the GITHUB_TOKEN to allow pushing to 'notebooks' branch
permissions:
contents: write
runs-on: ubuntu-latest
needs: build
steps:

- name: Checkout
uses: actions/checkout@v4

- name: Setup pixi
uses: prefix-dev/[email protected]

- name: Publish ipynb-formatted variant to 'notebooks' branch of this repo
run: |
git fetch origin
git checkout -B notebooks
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
pixi run ./convert_all.sh ipynb
git add .
git commit -am "Convert jupytext to ipynb format"
git push origin notebooks --force-with-lease
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Test notebooks

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: '0 5 * * 1'
workflow_dispatch:

jobs:
test:
name: Test all executable examples
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pixi
uses: prefix-dev/[email protected]

- name: Test all files
run: pixi run ./test.sh --all
32 changes: 0 additions & 32 deletions .github/workflows/gh-pages.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ lockfiles/

# ruff cache
.ruff_cache/

/build/*
.ipynb_checkpoints
/.pixi/*
23 changes: 2 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
# bluesky-cookbook

Documentation for various use cases, ideas and "recipes" within the bluesky framework
Documentation for various use cases, ideas and "recipes" within the bluesky ecosystem

See it live [here](http://blueskyproject.io/bluesky-cookbook/)!

Each recipe should:

* Be self contained
* Include a list of "ingredients" i.e. which parts of the bluesky framework you need and what data you need
* Be a markdown document
* Be categorised as a [tutorial or how-to guide](https://diataxis.fr/)
* Tagged
* User
* Developer
* Admin
* Manager

## How to Build

```bash
pip install nox
nox -s docs
```
See it live at [blueskyproject.io/bluesky-cookbook](http://blueskyproject.io/bluesky-cookbook/)!
49 changes: 49 additions & 0 deletions convert_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# If no arguments were provided, exit with error and show usage.
if [ $# -eq 0 ]; then
echo "Usage: $0 md | ipynb " >&2
exit 1
fi

# Variable to track if any errors occur
error_occurred=0

if [ "$1" = "ipynb" ]; then
files=$(find docs/recipes/ -name "*.md" | grep -v .ipynb_checkpoints)
for file in $files; do
# Extract the kernel information from the Jupytext Markdown file
kernel_info=$(grep -A 10 '^---$' "$file" | grep -E 'kernelspec')
# Skip if no kernel information was found
if [ -z "$kernel_info" ]; then
continue
fi
jupytext --to ipynb "$file" && rm "$file"
if [ $? -ne 0 ]; then
error_occurred=1
echo "Errors when converting $file"
else
echo "Converted $file"
fi
done
elif [ "$1" = "md" ]; then
files=$(find docs/recipes/ -name "*.ipynb" | grep -v .ipynb_checkpoints)
for file in $files; do
jupytext --to markdown "$file" && rm "$file"
if [ $? -ne 0 ]; then
error_occurred=1
echo "Errors when converting $file"
else
echo "Converted $file"
fi
done
fi

if [ $error_occurred -ne 0 ]; then
echo "Some files failed to convert." >&2
exit 1
else
echo "All files converted successfully." >&2
exit 0
fi

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0c4c60a

Please sign in to comment.