DataDesigner/.github/workflows/publish-devnotes.yml
Andre Manoel f267e19a60
fix(ci): replace yq with Python nav patching in publish-devnotes (#548)
The yq JSON roundtrip was mangling the entire mkdocs.yml file
(indentation, quoting, comments), causing mike deploy to fail.

Extract a Python script that surgically replaces only the Dev Notes
nav block, leaving all other content byte-identical.
2026-04-14 16:03:49 -03:00

74 lines
3 KiB
YAML

name: Publish devnotes
on:
push:
branches: [main]
paths:
- "docs/devnotes/**"
workflow_dispatch:
permissions: {}
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
actions: read
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Get last deployed docs state
run: |
git fetch origin gh-pages --depth=1
DEPLOY_MSG=$(git log FETCH_HEAD -1 --format="%s")
SOURCE_SHA=$(echo "$DEPLOY_MSG" | sed -n 's/^Deployed \([0-9a-f]*\) to .*/\1/p')
VERSION=$(echo "$DEPLOY_MSG" | sed -n 's/^Deployed [0-9a-f]* to \([^ ]*\) .*/\1/p')
if [ -z "$SOURCE_SHA" ] || [ -z "$VERSION" ]; then
echo "::error::Could not parse deploy info from gh-pages. Expected: 'Deployed <sha> to <version> ...'"
exit 1
fi
echo "::notice::Last deploy: commit $SOURCE_SHA for version $VERSION"
echo "SOURCE_SHA=$SOURCE_SHA" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Checkout docs source and overlay devnotes
run: |
git checkout ${{ env.SOURCE_SHA }}
git checkout ${{ github.sha }} -- docs/devnotes/ .github/scripts/patch-devnotes-nav.py
# Patch the "Dev Notes" nav section from HEAD's mkdocs.yml into the
# old source's mkdocs.yml. This keeps nav entries for new devnotes
# without pulling in entries for non-devnotes pages that may not
# exist in the old source checkout.
git show ${{ github.sha }}:mkdocs.yml > /tmp/mkdocs-head.yml
python3 .github/scripts/patch-devnotes-nav.py /tmp/mkdocs-head.yml mkdocs.yml
- name: Install uv
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
with:
version: "0.9.5"
- name: Set up Python
run: uv python install 3.11
- name: Install dependencies for docs
run: uv sync --all-packages --group docs
- name: Download notebooks from last docs build
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p docs/notebooks
LAST_RUN_ID=$(gh run list --workflow build-docs.yml --status success --limit 1 --json databaseId -q '.[0].databaseId')
if [ -z "$LAST_RUN_ID" ]; then
echo "::error::No successful build-docs run found. Cannot build without notebooks."
exit 1
fi
gh run download "$LAST_RUN_ID" --name notebooks --dir docs/notebooks
echo "::notice::Downloaded notebooks from build-docs run $LAST_RUN_ID"
- name: Setup doc deploy
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Rebuild latest docs
run: uv run mike deploy --push --update-aliases ${{ env.VERSION }} latest