Skip to content

Publish

Publish #27

Workflow file for this run

name: Publish
on:
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment'
required: true
type: choice
options:
- test
- production
default: 'test'
version_bump:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
default: 'patch'
prerelease:
description: 'Pre-release type (leave empty for stable release)'
required: false
type: choice
options:
- ''
- alpha
- beta
default: beta
permissions:
contents: write
id-token: write # Required for PyPI trusted publishing
jobs:
publish:
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.bump_version.outputs.new_version }}
environment:
name: ${{ inputs.environment == 'production' && 'production' || 'test' }}
url: ${{ inputs.environment == 'production' && 'https://pypi.org/p/agentkernel' || 'https://test.pypi.org/p/agentkernel' }}
defaults:
run:
shell: bash -e {0}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.MODULE_SYNC_TOKEN }} # Use PAT to bypass branch protection
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install uv
run: |
pip install uv
- name: Bump version
id: bump_version
working-directory: ak-py
run: |
python ../scripts/bump_version.py \
--bump ${{ inputs.version_bump }} \
${{ (inputs.prerelease == 'alpha' || inputs.prerelease == 'beta') && format('--prerelease {0}', inputs.prerelease) || '' }} \
--auto-prerelease-number
NEW_VERSION=$(python -c "import tomllib; f = open('pyproject.toml', 'rb'); print(tomllib.load(f)['project']['version'])")
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Build package
working-directory: ak-py
run: |
./build.sh
- name: Run tests
working-directory: ak-py
run: |
uv run pytest -s
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: ak-py/dist/
verbose: true
print-hash: true
repository-url: ${{ inputs.environment == 'test' && 'https://test.pypi.org/legacy/' || '' }}
- name: Commit version bump
if: inputs.environment == 'production'
run: |
git add ak-py/pyproject.toml ak-py/uv.lock
git commit -m "chore: bump version to ${{ steps.bump_version.outputs.new_version }}"
git push origin ${{ github.ref_name }}
- name: Update Terraform module versions
if: inputs.environment == 'production'
run: |
VERSION="${{ steps.bump_version.outputs.new_version }}"
# Convert PEP 440 format (1.0.0a1, 1.0.0b1) to hyphenated tag format (1.0.0-a1, 1.0.0-b1)
TAG_VERSION=$(echo "$VERSION" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+)([ab][0-9]+)$/\1-\2/')
echo "Updating Terraform module versions to ${TAG_VERSION}..."
python scripts/update_terraform_versions.py --version "${TAG_VERSION}"
# Check if there are any changes
if git diff --quiet ak-deployment/ examples/; then
echo "No Terraform module version changes"
else
echo "Terraform module versions updated"
git add ak-deployment/ examples/
git commit -m "chore: update terraform module versions to ${TAG_VERSION}"
git push origin ${{ github.ref_name }}
fi
- name: Create git tag
if: inputs.environment == 'production'
run: |
VERSION="${{ steps.bump_version.outputs.new_version }}"
# Convert PEP 440 format (1.0.0a1, 1.0.0b1) to hyphenated tag format (1.0.0-a1, 1.0.0-b1)
TAG_VERSION=$(echo "$VERSION" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+)([ab][0-9]+)$/\1-\2/')
git tag "v${TAG_VERSION}"
git push origin "v${TAG_VERSION}"
- name: Trigger Terraform module sync
if: inputs.environment == 'production'
run: |
VERSION="${{ steps.bump_version.outputs.new_version }}"
TAG_VERSION=$(echo "$VERSION" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+)([ab][0-9]+)$/\1-\2/')
gh workflow run sync-terraform.yaml \
--ref "v${TAG_VERSION}" \
-f tag_name="v${TAG_VERSION}"
echo "✅ Triggered Terraform module sync workflow for v${TAG_VERSION}"
env:
GH_TOKEN: ${{ secrets.MODULE_SYNC_TOKEN }}
- name: Create GitHub Release
if: inputs.environment == 'production'
run: |
VERSION="${{ steps.bump_version.outputs.new_version }}"
# Convert PEP 440 format to hyphenated tag format
TAG_VERSION=$(echo "$VERSION" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+)([ab][0-9]+)$/\1-\2/')
# Create release body
cat << EOF > release_body.md
🚀 **Agent Kernel v${VERSION}**
${{ inputs.prerelease && format('⚠️ Pre-release: {0}', inputs.prerelease) || '✅ Stable release' }}
📦 [View on PyPI](https://pypi.org/project/agentkernel/${VERSION}/)
### Installation
\`\`\`bash
pip install agentkernel==${VERSION}
\`\`\`
EOF
# Create release
gh release create "v${TAG_VERSION}" \
--title "v${TAG_VERSION}" \
--notes-file release_body.md \
${{ inputs.prerelease && '--prerelease' || '' }} \
--generate-notes \
ak-py/dist/*
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update examples with new version
if: inputs.environment == 'production'
run: |
python scripts/update_examples_version.py \
--version ${{ steps.bump_version.outputs.new_version }} \
--skip-lock
echo ""
echo "Committing changes..."
# Check if there are any changes
if git diff --quiet examples/; then
echo "No example file changes"
else
echo "Example pyproject.toml files updated"
git add examples/
git commit -m "chore: update examples to use agentkernel v${{ steps.bump_version.outputs.new_version }}"
git push origin ${{ github.ref_name }}
fi
echo ""
echo "Example update complete!"
- name: Test PyPI Summary
if: inputs.environment == 'test'
run: |
echo "## 🧪 Test PyPI Release" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Version **${{ steps.bump_version.outputs.new_version }}** has been published to Test PyPI." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**View on Test PyPI**: https://test.pypi.org/project/agentkernel/${{ steps.bump_version.outputs.new_version }}/" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Test Installation" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ ak==${{ steps.bump_version.outputs.new_version }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> ⚠️ **Note**: This is a test release. Version was NOT committed or tagged in git." >> $GITHUB_STEP_SUMMARY