feat: add codeflash-benchmark automated release to publish workflow

Extend the publish workflow to handle both codeflash and codeflash-benchmark
releases from a single workflow file, triggered by their respective version
files. Also syncs benchmark __init__.py version to match pyproject.toml.
This commit is contained in:
Kevin Turcios 2026-02-18 17:39:36 -05:00
parent 6020c4fab7
commit 20c956c0e9
2 changed files with 114 additions and 5 deletions

View file

@ -6,20 +6,48 @@ on:
- main
paths:
- 'codeflash/version.py'
- 'codeflash-benchmark/codeflash_benchmark/__init__.py'
jobs:
publish:
detect-changes:
runs-on: ubuntu-latest
outputs:
codeflash: ${{ steps.filter.outputs.codeflash }}
benchmark: ${{ steps.filter.outputs.benchmark }}
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 2
- name: Detect which packages changed
id: filter
run: |
if git diff --name-only HEAD~1 HEAD | grep -q '^codeflash/version.py$'; then
echo "codeflash=true" >> $GITHUB_OUTPUT
else
echo "codeflash=false" >> $GITHUB_OUTPUT
fi
if git diff --name-only HEAD~1 HEAD | grep -q '^codeflash-benchmark/codeflash_benchmark/__init__.py$'; then
echo "benchmark=true" >> $GITHUB_OUTPUT
else
echo "benchmark=false" >> $GITHUB_OUTPUT
fi
publish-codeflash:
needs: detect-changes
if: needs.detect-changes.outputs.codeflash == 'true'
runs-on: ubuntu-latest
environment:
name: pypi
permissions:
id-token: write
contents: write # Changed from 'read' to 'write' to allow tag creation
contents: write
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0 # Fetch all history for proper versioning
fetch-depth: 0
- name: Extract version from version.py
id: extract_version
@ -76,4 +104,85 @@ jobs:
prerelease: false
generate_release_notes: true
files: |
dist/*
dist/*
publish-benchmark:
needs: detect-changes
if: needs.detect-changes.outputs.benchmark == 'true'
runs-on: ubuntu-latest
environment:
name: pypi
permissions:
id-token: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Extract version from __init__.py
id: extract_version
run: |
VERSION=$(grep -oP '__version__ = "\K[^"]+' codeflash-benchmark/codeflash_benchmark/__init__.py)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=benchmark-v$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
- name: Verify version matches pyproject.toml
run: |
INIT_VERSION=${{ steps.extract_version.outputs.version }}
TOML_VERSION=$(grep -oP '^version = "\K[^"]+' codeflash-benchmark/pyproject.toml)
if [ "$INIT_VERSION" != "$TOML_VERSION" ]; then
echo "::error::Version mismatch: __init__.py=$INIT_VERSION, pyproject.toml=$TOML_VERSION"
exit 1
fi
- name: Check if tag already exists
id: check_tag
run: |
if git rev-parse "${{ steps.extract_version.outputs.tag }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag ${{ steps.extract_version.outputs.tag }} already exists, skipping release"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Tag ${{ steps.extract_version.outputs.tag }} does not exist, proceeding with release"
fi
- name: Create and push git tag
if: steps.check_tag.outputs.exists == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.extract_version.outputs.tag }}" -m "Release ${{ steps.extract_version.outputs.tag }}"
git push origin "${{ steps.extract_version.outputs.tag }}"
- name: Install uv
if: steps.check_tag.outputs.exists == 'false'
uses: astral-sh/setup-uv@v6
- name: Build
if: steps.check_tag.outputs.exists == 'false'
run: uv build --package codeflash-benchmark
- name: Publish to PyPI
if: steps.check_tag.outputs.exists == 'false'
run: uv publish
- name: Create GitHub Release
if: steps.check_tag.outputs.exists == 'false'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.extract_version.outputs.tag }}
name: codeflash-benchmark ${{ steps.extract_version.outputs.tag }}
body: |
## What's Changed
Release ${{ steps.extract_version.outputs.version }} of codeflash-benchmark.
**Full Changelog**: https://github.com/${{ github.repository }}/commits/${{ steps.extract_version.outputs.tag }}
draft: false
prerelease: false
generate_release_notes: true
files: |
dist/*

View file

@ -1,3 +1,3 @@
"""CodeFlash Benchmark - Pytest benchmarking plugin for codeflash.ai."""
__version__ = "0.1.0"
__version__ = "0.2.0"