Skip to content
Latchkey

docs workflow (viser-project/viser)

The docs workflow from viser-project/viser, explained and optimized by Latchkey.

B

CI health: B - good

Point runs-on at Latchkey and get job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: viser-project/viser.github/workflows/docs.ymlLicense Apache-2.0View source

What it does

This is the docs workflow from the viser-project/viser repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: docs

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  release:
    types: [created]
  workflow_dispatch:

concurrency:
  group: docs-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: write

jobs:
  docs:
    runs-on: ubuntu-latest
    steps:
      # Check out source.
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 # This ensures the entire history is fetched so we can switch branches

      - name: Install uv
        uses: astral-sh/setup-uv@v5
        with:
          enable-cache: true

      # Get version from pyproject.toml.
      - name: Get version + subdirectory
        run: |
          VERSION=$(uv run --extra dev --python 3.12 python -c "import viser; print(viser.__version__)")
          echo "VISER_RELEASE_WORKFLOW_VERSION=$VERSION" >> $GITHUB_ENV
          echo "VERSION=$VERSION" >> $GITHUB_ENV
          echo "DOCS_SUBDIR=versions/$VERSION" >> $GITHUB_ENV

      # Hack to overwrite version.
      - name: Set version to 'main' for pushes (this will appear in the doc banner)
        run: |
          echo "VISER_VERSION_STR_OVERRIDE=main" >> $GITHUB_ENV
        if: github.event_name == 'push'

      # Build documentation.
      - name: Building documentation
        run: |
          uv run --extra dev --extra examples --python 3.12 --with-requirements docs/requirements.txt \
            sphinx-build docs/source docs/build -b dirhtml

      # Get version from pyproject.toml.
      - name: Override subdirectory to `main/` for pushes
        run: |
          echo "DOCS_SUBDIR=main" >> $GITHUB_ENV
        if: github.event_name == 'push'

      # Deploy to version-dependent subdirectory.
      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v4
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./docs/build
          destination_dir: ${{ env.DOCS_SUBDIR }}
          keep_files: false # This will only erase the destination subdirectory.
          cname: viser.studio
        if: github.event_name != 'pull_request'

      # We'll maintain an index of all versions under viser.studio/versions.
      # This will be useful for dynamically generating lists of possible doc links.
      - name: Update versions index.txt
        run: |
          git checkout .  # Revert change to pyproject.toml from earlier...
          git checkout gh-pages
          git pull
          git config --global user.email "yibrenth@gmail.com"
          git config --global user.name "Brent Yi"
          FILE="versions/index.txt"  # Replace with your file path
          if ! grep -qx "$VERSION" "$FILE"; then
            echo "$VERSION" >> "$FILE"
            git add $FILE
            git commit -m "Update versions.txt with new version $VERSION"
            git push origin gh-pages
          fi
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          VERSION: ${{ env.VERSION }}
        if: github.event_name == 'release'

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: docs
 
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  release:
    types: [created]
  workflow_dispatch:
 
concurrency:
  group: docs-${{ github.ref }}
  cancel-in-progress: true
 
permissions:
  contents: write
 
jobs:
  docs:
    timeout-minutes: 30
    runs-on: latchkey-small
    steps:
      # Check out source.
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 # This ensures the entire history is fetched so we can switch branches
 
      - name: Install uv
        uses: astral-sh/setup-uv@v5
        with:
          enable-cache: true
 
      # Get version from pyproject.toml.
      - name: Get version + subdirectory
        run: |
          VERSION=$(uv run --extra dev --python 3.12 python -c "import viser; print(viser.__version__)")
          echo "VISER_RELEASE_WORKFLOW_VERSION=$VERSION" >> $GITHUB_ENV
          echo "VERSION=$VERSION" >> $GITHUB_ENV
          echo "DOCS_SUBDIR=versions/$VERSION" >> $GITHUB_ENV
 
      # Hack to overwrite version.
      - name: Set version to 'main' for pushes (this will appear in the doc banner)
        run: |
          echo "VISER_VERSION_STR_OVERRIDE=main" >> $GITHUB_ENV
        if: github.event_name == 'push'
 
      # Build documentation.
      - name: Building documentation
        run: |
          uv run --extra dev --extra examples --python 3.12 --with-requirements docs/requirements.txt \
            sphinx-build docs/source docs/build -b dirhtml
 
      # Get version from pyproject.toml.
      - name: Override subdirectory to `main/` for pushes
        run: |
          echo "DOCS_SUBDIR=main" >> $GITHUB_ENV
        if: github.event_name == 'push'
 
      # Deploy to version-dependent subdirectory.
      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v4
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./docs/build
          destination_dir: ${{ env.DOCS_SUBDIR }}
          keep_files: false # This will only erase the destination subdirectory.
          cname: viser.studio
        if: github.event_name != 'pull_request'
 
      # We'll maintain an index of all versions under viser.studio/versions.
      # This will be useful for dynamically generating lists of possible doc links.
      - name: Update versions index.txt
        run: |
          git checkout .  # Revert change to pyproject.toml from earlier...
          git checkout gh-pages
          git pull
          git config --global user.email "yibrenth@gmail.com"
          git config --global user.name "Brent Yi"
          FILE="versions/index.txt"  # Replace with your file path
          if ! grep -qx "$VERSION" "$FILE"; then
            echo "$VERSION" >> "$FILE"
            git add $FILE
            git commit -m "Update versions.txt with new version $VERSION"
            git push origin gh-pages
          fi
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          VERSION: ${{ env.VERSION }}
        if: github.event_name == 'release'
 

What changed

2 third-party actions are referenced by a movable tag. Pin them to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.

This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow