feat: add codeflash-benchmark automated release to publish workflow #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Publish" | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'codeflash/version.py' | |
| - 'codeflash-benchmark/codeflash_benchmark/__init__.py' | |
| jobs: | |
| 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 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract version from version.py | |
| id: extract_version | |
| run: | | |
| VERSION=$(grep -oP '__version__ = "\K[^"]+' codeflash/version.py) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=v$VERSION" >> $GITHUB_OUTPUT | |
| echo "Extracted version: $VERSION" | |
| - name: Check if tag already exists | |
| id: check_tag | |
| run: | | |
| if git rev-parse "v${{ steps.extract_version.outputs.version }}" >/dev/null 2>&1; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| echo "Tag v${{ steps.extract_version.outputs.version }} already exists, skipping release" | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| echo "Tag v${{ steps.extract_version.outputs.version }} 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 | |
| - 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: Release ${{ steps.extract_version.outputs.tag }} | |
| body: | | |
| ## What's Changed | |
| Release ${{ steps.extract_version.outputs.version }} of codeflash. | |
| **Full Changelog**: https://github.com/${{ github.repository }}/commits/${{ steps.extract_version.outputs.tag }} | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: true | |
| files: | | |
| 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/* |