Skip to content
Open
Changes from all commits
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
39 changes: 34 additions & 5 deletions .github/workflows/deploy-mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ on:
types:
- published
workflow_dispatch:
inputs:
is_release:
description: 'Deploy as a Release version (using most recent release)?'
type: boolean
default: false

permissions:
contents: write
Expand All @@ -26,6 +31,7 @@ jobs:
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
ref: ${{ github.event_name == 'pull_request' && 'main' || github.ref }}

- name: Set up Python from pyproject.toml
Expand All @@ -44,23 +50,46 @@ jobs:
git fetch origin gh-pages --depth=1 || true

- name: Deploy Development Docs
if: github.event_name != 'release'
if: github.event_name != 'release' &&
(github.event_name != 'workflow_dispatch' || inputs.is_release == false)
run: mike deploy --push dev

- name: Deploy Release Docs
if: github.event_name == 'release'
env:
TAG: ${{ github.event.release.tag_name }}
if: github.event_name == 'release' ||
(github.event_name == 'workflow_dispatch' && inputs.is_release == true)
run: |

# Auto-detect tag from release event or latest git tag
TAG="${{ github.event.release.tag_name }}"
if [ -z "$TAG" ]; then
TAG=$(git tag -l | sort -V | tail -1)
fi

if [ -z "$TAG" ]; then
echo "Error: No release tag found"
exit 1
fi

echo "Deploying release docs for tag: $TAG"

# Check if docs for this version already exist
if mike list | grep -q "\"$TAG\""; then
echo "Docs for $TAG already exist. Skipping deploy."
exit 0
fi

# Clean up the title of the previous 'latest' version
PREV_LATEST=$(mike list | grep "(latest)" | awk '{print $1}')
PREV_LATEST=$(mike list | grep "(latest)" | awk '{print $1}' | sed 's/"//g')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more just for my understanding rather than a concern about the code, why is it important to remove quotes from the version? Aka. when do the quotes appear?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running mike list will produce an output where the latest version will be formatted like so:
"v2.4.0 (latest)" (v2.4.0) [latest]

Then awk '{print 1}' will grab the first group (using spaces as a separator) which produces:
"v2.4.0

and then the code then code crashes because it can't match that version, due to the leading "

So sed 's/"//g' fixes this by finding any " and replacing it with nothing, which returns: v2.4.0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aah makes sense, thank you


# Probably overkill but leaving in as fallback - check versions.json if mike list is empty
if [ -z "$PREV_LATEST" ]; then
echo "Previous latest not found, checking versions.json"
git checkout origin/gh-pages -- versions.json 2>/dev/null || echo "[]" > versions.json
PREV_LATEST=$(jq -r '.[] | select(.aliases[]? == "latest") | .version' versions.json)
fi

echo "Previous latest found: $PREV_LATEST"

if [ -n "$PREV_LATEST" ] && [ "$PREV_LATEST" != "null" ] && [ "$PREV_LATEST" != "$TAG" ]; then
echo "Stripping (latest) suffix from $PREV_LATEST"
mike retitle $PREV_LATEST "$PREV_LATEST"
Expand Down