Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
100 changes: 80 additions & 20 deletions .github/workflows/docs-gh-pages.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,100 @@
name: Build and Deploy Documentation
name: Docs — Build & Preview

on:
push:
branches:
- main
branches: [ main ] # regular prod deploy
paths:
- 'mkdocs.yml'
- 'docs/**'
pull_request: # preview only when docs are touched
branches: [ '**' ]
paths:
- 'mkdocs.yml'
- 'docs/**'

jobs:
build-and-deploy-docs:
build:
runs-on: ubuntu-latest
outputs:
short_sha: ${{ steps.sha.outputs.short }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for .git-restore-mtime to work correctly

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
with: { fetch-depth: 0 }

- name: Install uv via GitHub Action
uses: astral-sh/setup-uv@v6
- uses: astral-sh/setup-uv@v6

- name: Install mesa-frames + docs dependencies
- name: Install mesa-frames + docs deps
run: |
uv pip install --system .
uv pip install --group docs --system
- name: Build MkDocs site (general documentation)
run: mkdocs build --config-file mkdocs.yml --site-dir ./site
- name: Convert jupytext .py notebooks to .ipynb
run: |
set -euxo pipefail
# Convert any jupytext .py files to .ipynb without executing them.
# Enable nullglob so the pattern expands to empty when there are no matches
# and globstar so we recurse into subdirectories (e.g., user-guide/).
shopt -s nullglob globstar || true
files=(docs/general/**/*.py)
if [ ${#files[@]} -eq 0 ]; then
echo "No jupytext .py files found under docs/general"
else
for src in "${files[@]}"; do
[ -e "$src" ] || continue
dest="${src%.py}.ipynb"
echo "Converting $src -> $dest"
# jupytext will write the .ipynb alongside the source file
uv run jupytext --to notebook "$src"
done
fi
- name: Build MkDocs site
run: uv run mkdocs build --config-file mkdocs.yml --site-dir ./site

- name: Build Sphinx docs (API)
run: uv run sphinx-build -b html docs/api site/api

- name: Short SHA
id: sha
run: echo "short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"

- name: Upload site artifact
uses: actions/upload-artifact@v4
with:
name: site
path: site

- name: Build Sphinx docs (API documentation)
run: sphinx-build -b html docs/api site/api
deploy-main:
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with: { name: site, path: site }
- name: Deploy to GitHub Pages (main)
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: ./site
force_orphan: true

- name: Deploy to GitHub Pages
deploy-preview:
needs: build
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with: { name: site, path: site }
- name: Deploy preview under subfolder
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: ./site
force_orphan: true
destination_dir: preview/${{ github.head_ref || github.ref_name }}/${{ needs.build.outputs.short_sha }}
keep_files: true # keep previous previews
# DO NOT set force_orphan here
- name: Print preview URL
run: |
echo "Preview: https://${{ github.repository_owner }}.github.io/$(basename ${{ github.repository }})/preview/${{ github.head_ref || github.ref_name }}/${{ needs.build.outputs.short_sha }}/"
73 changes: 54 additions & 19 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,78 @@ jobs:
with:
fetch-depth: 0
token: ${{ secrets.VERSION_PUSH_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch
- name: Setup uv
uses: astral-sh/setup-uv@v3
- name: Set release version
run: |
# Get the tag from the GitHub release
TAG=${GITHUB_REF#refs/tags/}
# Remove 'v' prefix if present
VERSION=${TAG#v}
hatch version $VERSION
uvx hatch version $VERSION
- name: Build package
run: hatch build
run: uvx hatch build
- name: Run tests
run: hatch run test:pytest
run: uvx hatch run test:pytest
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Verify PyPI Release
run: |
# Verify PyPI release
PACKAGE_NAME="mesa_frames"
CURRENT_VERSION=$(hatch version)
pip install $PACKAGE_NAME==$CURRENT_VERSION
CURRENT_VERSION=$(uvx hatch version)
uv pip install --system $PACKAGE_NAME==$CURRENT_VERSION
python -c "import mesa_frames; print(mesa_frames.__version__)"
- name: Update GitHub Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
dist/*
- name: Generate changelog from release notes
id: notes
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const tag = (context.payload.release && context.payload.release.tag_name)
? context.payload.release.tag_name
: (process.env.GITHUB_REF || '').replace('refs/tags/', '');

const body = (context.payload.release && context.payload.release.body) ? context.payload.release.body : '';
if (!body || body.trim().length === 0) {
core.setFailed('Release body is empty. Ensure the GitHub Release is created with auto-generated notes configured by .github/release.yml or supply a body.');
}

fs.writeFileSync('RELEASE_BODY.md', body, 'utf8');
core.setOutput('tag', tag);
- name: Prepend notes to CHANGELOG.md
env:
TAG: ${{ steps.notes.outputs.tag }}
run: |
VERSION_NO_V=${TAG#v}
DATE_UTC=$(date -u +%Y-%m-%d)
echo "## Version ${VERSION_NO_V} — ${DATE_UTC}" > RELEASE_HEADER.md
echo "" >> RELEASE_HEADER.md
if [ -f CHANGELOG.md ]; then
cat RELEASE_HEADER.md RELEASE_BODY.md CHANGELOG.md > CHANGELOG.new
else
cat RELEASE_HEADER.md RELEASE_BODY.md > CHANGELOG.new
fi
mv CHANGELOG.new CHANGELOG.md
- name: Commit and push CHANGELOG update
env:
TAG: ${{ steps.notes.outputs.tag }}
run: |
git config user.name github-actions
git config user.email [email protected]
git add CHANGELOG.md
# Avoid CI cycles
git commit -m "Changelog: add notes for ${TAG} [skip ci]" || echo "No changelog changes to commit"
git push origin main || true
- name: Create or recreate version branch
run: |
CURRENT_VERSION=$(hatch version)
CURRENT_VERSION=$(uvx hatch version)
BRANCH_NAME="v$CURRENT_VERSION"

git config user.name github-actions
Expand All @@ -72,15 +107,15 @@ jobs:
- name: Update to Next Version
run: |
# Bump to next development version
hatch version patch
hatch version dev
uvx hatch version patch
uvx hatch version dev

# Get the new version
NEW_VERSION=$(hatch version)
NEW_VERSION=$(uvx hatch version)

# Commit and push the version bump
git config user.name github-actions
git config user.email [email protected]
git add mesa_frames/__init__.py
git add mesa_frames/__init__.py CHANGELOG.md
git commit -m "Bump version to $NEW_VERSION [skip ci]"
git push origin main
git push origin main
Loading