Skip to content

Commit 20c956c

Browse files
committed
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.
1 parent 6020c4f commit 20c956c

2 files changed

Lines changed: 114 additions & 5 deletions

File tree

.github/workflows/publish.yml

Lines changed: 113 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,48 @@ on:
66
- main
77
paths:
88
- 'codeflash/version.py'
9+
- 'codeflash-benchmark/codeflash_benchmark/__init__.py'
910

1011
jobs:
11-
publish:
12+
detect-changes:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
codeflash: ${{ steps.filter.outputs.codeflash }}
16+
benchmark: ${{ steps.filter.outputs.benchmark }}
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v5
20+
with:
21+
fetch-depth: 2
22+
23+
- name: Detect which packages changed
24+
id: filter
25+
run: |
26+
if git diff --name-only HEAD~1 HEAD | grep -q '^codeflash/version.py$'; then
27+
echo "codeflash=true" >> $GITHUB_OUTPUT
28+
else
29+
echo "codeflash=false" >> $GITHUB_OUTPUT
30+
fi
31+
if git diff --name-only HEAD~1 HEAD | grep -q '^codeflash-benchmark/codeflash_benchmark/__init__.py$'; then
32+
echo "benchmark=true" >> $GITHUB_OUTPUT
33+
else
34+
echo "benchmark=false" >> $GITHUB_OUTPUT
35+
fi
36+
37+
publish-codeflash:
38+
needs: detect-changes
39+
if: needs.detect-changes.outputs.codeflash == 'true'
1240
runs-on: ubuntu-latest
1341
environment:
1442
name: pypi
1543
permissions:
1644
id-token: write
17-
contents: write # Changed from 'read' to 'write' to allow tag creation
45+
contents: write
1846
steps:
1947
- name: Checkout
2048
uses: actions/checkout@v5
2149
with:
22-
fetch-depth: 0 # Fetch all history for proper versioning
50+
fetch-depth: 0
2351

2452
- name: Extract version from version.py
2553
id: extract_version
@@ -76,4 +104,85 @@ jobs:
76104
prerelease: false
77105
generate_release_notes: true
78106
files: |
79-
dist/*
107+
dist/*
108+
109+
publish-benchmark:
110+
needs: detect-changes
111+
if: needs.detect-changes.outputs.benchmark == 'true'
112+
runs-on: ubuntu-latest
113+
environment:
114+
name: pypi
115+
permissions:
116+
id-token: write
117+
contents: write
118+
steps:
119+
- name: Checkout
120+
uses: actions/checkout@v5
121+
with:
122+
fetch-depth: 0
123+
124+
- name: Extract version from __init__.py
125+
id: extract_version
126+
run: |
127+
VERSION=$(grep -oP '__version__ = "\K[^"]+' codeflash-benchmark/codeflash_benchmark/__init__.py)
128+
echo "version=$VERSION" >> $GITHUB_OUTPUT
129+
echo "tag=benchmark-v$VERSION" >> $GITHUB_OUTPUT
130+
echo "Extracted version: $VERSION"
131+
132+
- name: Verify version matches pyproject.toml
133+
run: |
134+
INIT_VERSION=${{ steps.extract_version.outputs.version }}
135+
TOML_VERSION=$(grep -oP '^version = "\K[^"]+' codeflash-benchmark/pyproject.toml)
136+
if [ "$INIT_VERSION" != "$TOML_VERSION" ]; then
137+
echo "::error::Version mismatch: __init__.py=$INIT_VERSION, pyproject.toml=$TOML_VERSION"
138+
exit 1
139+
fi
140+
141+
- name: Check if tag already exists
142+
id: check_tag
143+
run: |
144+
if git rev-parse "${{ steps.extract_version.outputs.tag }}" >/dev/null 2>&1; then
145+
echo "exists=true" >> $GITHUB_OUTPUT
146+
echo "Tag ${{ steps.extract_version.outputs.tag }} already exists, skipping release"
147+
else
148+
echo "exists=false" >> $GITHUB_OUTPUT
149+
echo "Tag ${{ steps.extract_version.outputs.tag }} does not exist, proceeding with release"
150+
fi
151+
152+
- name: Create and push git tag
153+
if: steps.check_tag.outputs.exists == 'false'
154+
run: |
155+
git config user.name "github-actions[bot]"
156+
git config user.email "github-actions[bot]@users.noreply.github.com"
157+
git tag -a "${{ steps.extract_version.outputs.tag }}" -m "Release ${{ steps.extract_version.outputs.tag }}"
158+
git push origin "${{ steps.extract_version.outputs.tag }}"
159+
160+
- name: Install uv
161+
if: steps.check_tag.outputs.exists == 'false'
162+
uses: astral-sh/setup-uv@v6
163+
164+
- name: Build
165+
if: steps.check_tag.outputs.exists == 'false'
166+
run: uv build --package codeflash-benchmark
167+
168+
- name: Publish to PyPI
169+
if: steps.check_tag.outputs.exists == 'false'
170+
run: uv publish
171+
172+
- name: Create GitHub Release
173+
if: steps.check_tag.outputs.exists == 'false'
174+
uses: softprops/action-gh-release@v2
175+
with:
176+
tag_name: ${{ steps.extract_version.outputs.tag }}
177+
name: codeflash-benchmark ${{ steps.extract_version.outputs.tag }}
178+
body: |
179+
## What's Changed
180+
181+
Release ${{ steps.extract_version.outputs.version }} of codeflash-benchmark.
182+
183+
**Full Changelog**: https://github.com/${{ github.repository }}/commits/${{ steps.extract_version.outputs.tag }}
184+
draft: false
185+
prerelease: false
186+
generate_release_notes: true
187+
files: |
188+
dist/*
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""CodeFlash Benchmark - Pytest benchmarking plugin for codeflash.ai."""
22

3-
__version__ = "0.1.0"
3+
__version__ = "0.2.0"

0 commit comments

Comments
 (0)