Skip to content

chore: format

chore: format #13

name: Release and Deploy Versioned Docs
on:
push:
branches:
- production
jobs:
release_and_docs:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
issues: write
pull-requests: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Python build dependencies
run: |
pip install build twine
- name: Build Python package
run: python -m build
- name: Install Node dependencies
run: >
npm install --no-save
semantic-release
@semantic-release/commit-analyzer
@semantic-release/release-notes-generator
semantic-release-pypi
@semantic-release/git
@semantic-release/github
- name: Run semantic-release
id: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN_PROD }}
PYPI_REPO_URL: https://upload.pypi.org/legacy/
run: |
npx semantic-release
VERSION=$(git describe --tags --abbrev=0 --match "v*" 2>/dev/null || echo "no-version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Released version: $VERSION"
- name: Build documentation
run: |
pip install -e ".[ml,dev]"
cd docs/
pip install -r docs_requirements.txt
make html
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages
fetch-depth: 0
- name: Deploy versioned docs
run: |
VERSION="${{ steps.release.outputs.version }}"
# Only deploy if we have a valid version
if [[ "$VERSION" != "no-version" ]]; then
echo "Deploying documentation for version: $VERSION"
# Create version directory and copy docs
mkdir -p "gh-pages/$VERSION"
rsync -av --delete docs/_build/html/ "gh-pages/$VERSION/"
# Also create/update 'latest' to point to this version
mkdir -p gh-pages/latest
rsync -av --delete docs/_build/html/ gh-pages/latest/
# Build switcher.json for all versions
cd gh-pages
versions=()
# Collect all version directories
for d in */; do
d=${d%/} # Remove trailing slash
if [[ "$d" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || [[ "$d" == "latest" ]]; then
versions+=("$d")
fi
done
# Sort versions (latest first, then reverse semver order)
IFS=$'\n' sorted_versions=($(printf '%s\n' "${versions[@]}" | sort -V -r))
# Create switcher.json content
switcher_content="["
first=true
for v in "${sorted_versions[@]}"; do
if [[ "$first" == "true" ]]; then
first=false
else
switcher_content="$switcher_content,"
fi
if [[ "$v" == "latest" ]]; then
entry="{\"version\": \"latest\", \"url\": \"https://baker-laboratory.github.io/atomworks-dev/latest/index.html\", \"name\": \"latest\"}"
else
disp="${v#v}"
# Mark the newest stable version as preferred
if [[ "$v" == "$VERSION" ]]; then
preferred="true"
else
preferred="false"
fi
entry="{\"version\": \"$disp\", \"url\": \"https://baker-laboratory.github.io/atomworks-dev/$v/index.html\", \"name\": \"v$disp\", \"preferred\": $preferred}"
fi
switcher_content="$switcher_content$entry"
done
switcher_content="$switcher_content]"
# Write switcher.json to all version directories
for v in "${sorted_versions[@]}"; do
mkdir -p "$v/_static"
echo "$switcher_content" > "$v/_static/switcher.json"
echo "Created switcher.json for $v"
done
echo "Switcher content: $switcher_content"
else
echo "No version tag found, skipping documentation deployment"
fi
- name: Deploy to GitHub Pages
if: steps.release.outputs.version != 'no-version'
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: gh-pages
keep_files: true # Keep existing versions
force_orphan: false # Don't force orphan, preserve history
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'