Files
mushroom-strategy/.github/workflows/deploy-docs.yml
T
DigiLive 59ceded431 Refactor deployment workflow for documentation
Improve the GitHub Actions workflow for deploying documentation by
adding concurrency control, adjusting permissions, and enhancing
error handling for branch fetching. This ensures a more robust
and efficient deployment process.
2026-03-23 15:57:56 +01:00

144 lines
5.0 KiB
YAML

# ==============================================================================
# HOW TO USE THIS WORKFLOW:
# ==============================================================================
# 1. PUSH TO 'main' BRANCH:
# - Automatically updates the '/main/' folder on the gh-pages branch.
# - NOTE: This only triggers if files in 'docs/' or 'mkdocs.yml' changed.
# - Use this for "Bleeding Edge" documentation.
#
# 2. PUBLISH A RELEASE:
# - Automatically creates a folder named after the tag (e.g., /v2.5.0/).
# - Automatically points the '/latest/' folder (alias) to that new tag.
# - Use this for official, stable version launches.
#
# 3. MANUAL RUN (GitHub Actions UI -> "Run workflow"):
# - "Version": The folder name you want to create or overwrite (e.g., v2.5.0).
# - "Alias": (Optional) The redirect folder you want to point to that version
# (e.g., enter 'latest' to move the latest pointer to the version above).
# - Use this to FIX an existing version folder without making a new release.
# ==============================================================================
name: Deploy Documentation
concurrency:
group: deploy-docs-${{ github.ref }}
cancel-in-progress: false
on:
release:
types: [published]
push:
branches:
- main
# checkov:skip=CKV_GHA_7: Inputs are sanitized via regex in the run block to prevent injection.
workflow_dispatch:
inputs:
version:
description: 'Version to deploy (e.g., v2.5.0 or main)'
required: true
default: 'main'
alias:
description: 'Alias to update (e.g., latest)'
required: false
default: ''
permissions:
contents: read
jobs:
check-for-changes:
name: Check for changes
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.check_files.outputs.any_changed }}
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check for changed documentation files
id: check_files
uses: tj-actions/changed-files@v47
with:
files: |
docs/**
mkdocs.yml
deploy:
name: Deploy MkDocs Site
permissions:
contents: write
runs-on: ubuntu-latest
timeout-minutes: 10
needs: check-for-changes
if: |
needs.check-for-changes.outputs.changed == 'true' ||
github.event_name == 'workflow_dispatch' ||
github.event_name == 'release'
env:
CI_COMMIT_AUTHOR: 'CI Bot'
CI_COMMIT_EMAIL: 'ci@noreply.github.com'
CI_COMMIT_MESSAGE: 'Continuous Integration - Deploy Documentation'
steps:
- name: Generate GitHub App Token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Checkout Code
uses: actions/checkout@v6
with:
token: ${{ steps.generate_token.outputs.token }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.x'
cache: 'pip'
- name: Install MkDocs and dependencies
run: pip install -r requirements.txt
- name: Deploy Docs to GitHub Pages
env:
MY_VERSION: ${{ github.event.inputs.version }}
MY_ALIAS: ${{ github.event.inputs.alias }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
git config --global user.email "${{ env.CI_COMMIT_EMAIL }}"
git remote set-url origin https://x-access-token:${{ steps.generate_token.outputs.token }}@github.com/DigiLive/mushroom-strategy.git
if ! git fetch origin gh-pages --depth=1 2>/dev/null; then
echo "::notice::gh-pages branch does not exist yet. Mike will create it."
fi
if [ "${{ github.event_name }}" == "release" ]; then
# Release: Create a permanent version folder and update latest alias.
mike deploy --push --rebase --update-aliases "$RELEASE_TAG" latest
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
# Manual: Use UI inputs for version and optional alias.
if [[ ! "$MY_VERSION" =~ ^[a-zA-Z0-9._-]+$ ]]; then
echo "::error::Invalid version name: $MY_VERSION. Only alphanumeric, dots, and hyphens allowed."
exit 1
fi
if [[ -n "$MY_ALIAS" && ! "$MY_ALIAS" =~ ^[a-zA-Z0-9._-]+$ ]]; then
echo "::error::Invalid alias name: $MY_ALIAS. Only alphanumeric, dots, and hyphens allowed."
exit 1
fi
if [ -n "$MY_ALIAS" ]; then
mike deploy --push --rebase --update-aliases "$MY_VERSION" "$MY_ALIAS"
else
mike deploy --push --rebase "$MY_VERSION"
fi
else
# Push: Update the /main/ folder
mike deploy --push --rebase main
fi