Skip to content

Prepare to release v1.10.0 of the xAI Python SDK (#121) #24

Prepare to release v1.10.0 of the xAI Python SDK (#121)

Prepare to release v1.10.0 of the xAI Python SDK (#121) #24

Workflow file for this run

name: Auto-Tag on Version Change
on:
push:
branches: [main]
paths:
- src/xai_sdk/__about__.py
jobs:
auto-tag:
runs-on: xai-sdk-python-runner
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history to compare commits
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install uv
uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6
with:
version: "0.7.3"
- name: Install dependencies
run: uv sync --locked
- name: Check version update and create tag
env:
GH_TOKEN: ${{ github.token }}
run: |
# Get the new version (from the current __about__.py, already checked out at HEAD)
export NEW_VERSION=$(uv run hatch version)
echo "New version: $NEW_VERSION"
# Get the previous version (from the previous commit's __about__.py)
PREVIOUS_COMMIT=$(git rev-parse origin/main^)
git checkout $PREVIOUS_COMMIT -- src/xai_sdk/__about__.py
export PREVIOUS_VERSION=$(uv run hatch version)
echo "Previous version: $PREVIOUS_VERSION"
# Restore the modified __about__.py to the latest commit
git restore src/xai_sdk/__about__.py
# 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.')
"
# If all checks pass, create and push the tag, assuming it doesn't already exist
if [ -n "$(git tag -l "v${NEW_VERSION}")" ]; then
echo "Tag v${NEW_VERSION} already exists, skipping."
exit 0
fi
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git tag -a v${NEW_VERSION} -m "Release version ${NEW_VERSION} of the xAI Python SDK"
git push origin v${NEW_VERSION}