Skip to content
Latchkey

Validate Version Bump workflow (xai-org/xai-sdk-python)

The Validate Version Bump workflow from xai-org/xai-sdk-python, explained and optimized by Latchkey.

D

CI health: D - needs work

Run this on Latchkey for self-healing, caching, and up to 58% lower cost.

Grade your own workflow free or run it on Latchkey →
Source: xai-org/xai-sdk-python.github/workflows/validate-version-bump.yamlLicense Apache-2.0View source

What it does

This is the Validate Version Bump workflow from the xai-org/xai-sdk-python 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: Validate Version Bump

on:
  pull_request:
    branches: [main]
    paths:
      - src/xai_sdk/__about__.py

jobs:
  validate-version-bump:
    runs-on: xai-sdk-python-runner
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
        with:
          fetch-depth: 0 # Fetch all history to compare commits

      - name: Set up Python
        uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
        with:
          python-version: "3.10"

      - name: Install uv
        uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
        with:
          version: "0.7.3"

      - name: Install dependencies
        run: uv sync --locked

      - name: Validate version bump
        run: |
          # Get the commit from the tip of main
          MAIN_COMMIT=$(git rev-parse origin/main)

          # Get the commit from the PR's source branch
          PR_COMMIT=${{ github.event.pull_request.head.sha }}

          # Get the previous version (from main)
          git checkout $MAIN_COMMIT -- src/xai_sdk/__about__.py
          export PREVIOUS_VERSION=$(uv run hatch version)
          echo "Previous version: $PREVIOUS_VERSION"

          # Get the new version (from the PR branch)
          git checkout $PR_COMMIT -- src/xai_sdk/__about__.py
          export NEW_VERSION=$(uv run hatch version)
          echo "New version: $NEW_VERSION"

          # Compare versions semantically to ensure the new version is greater
          uv run python -c "
          import os
          from packaging import version

          previous_version = os.environ['PREVIOUS_VERSION']
          new_version = os.environ['NEW_VERSION']

          prev_ver = version.parse(previous_version)
          new_ver = version.parse(new_version)

          if new_ver <= prev_ver:
              print(f'Error: New version {new_version} is not greater than previous version {previous_version}')
              exit(1)
          else:
              print('Version bump is valid.')
          "

The same workflow, on Latchkey

Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.

name: Validate Version Bump
 
on:
  pull_request:
    branches: [main]
    paths:
      - src/xai_sdk/__about__.py
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  validate-version-bump:
    timeout-minutes: 30
    runs-on: xai-sdk-python-runner
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
        with:
          fetch-depth: 0 # Fetch all history to compare commits
 
      - name: Set up Python
        uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
        with:
          cache: 'pip'
          python-version: "3.10"
 
      - name: Install uv
        uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
        with:
          version: "0.7.3"
 
      - name: Install dependencies
        run: uv sync --locked
 
      - name: Validate version bump
        run: |
          # Get the commit from the tip of main
          MAIN_COMMIT=$(git rev-parse origin/main)
 
          # Get the commit from the PR's source branch
          PR_COMMIT=${{ github.event.pull_request.head.sha }}
 
          # Get the previous version (from main)
          git checkout $MAIN_COMMIT -- src/xai_sdk/__about__.py
          export PREVIOUS_VERSION=$(uv run hatch version)
          echo "Previous version: $PREVIOUS_VERSION"
 
          # Get the new version (from the PR branch)
          git checkout $PR_COMMIT -- src/xai_sdk/__about__.py
          export NEW_VERSION=$(uv run hatch version)
          echo "New version: $NEW_VERSION"
 
          # Compare versions semantically to ensure the new version is greater
          uv run python -c "
          import os
          from packaging import version
 
          previous_version = os.environ['PREVIOUS_VERSION']
          new_version = os.environ['NEW_VERSION']
 
          prev_ver = version.parse(previous_version)
          new_ver = version.parse(new_version)
 
          if new_ver <= prev_ver:
              print(f'Error: New version {new_version} is not greater than previous version {previous_version}')
              exit(1)
          else:
              print('Version bump is valid.')
          "
 

What changed

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