release.yml•4.49 kB
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., v1.0.0)'
required: true
type: string
env:
REGISTRY: ghcr.io
IMAGE_NAME: startreedata/mcp-pinot
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run tests
run: |
pytest tests/ --cov=mcp_pinot --cov-report=xml
build-and-push:
needs: [test]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
create-release:
needs: [test, build-and-push]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version from tag or input
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Generate changelog
id: changelog
run: |
# Get the previous tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1)
# Generate changelog content
CHANGELOG="## Changes since $PREVIOUS_TAG"
CHANGELOG="$CHANGELOG\n\n"
CHANGELOG="$CHANGELOG$(git log --pretty=format:"- %s" $PREVIOUS_TAG..HEAD)"
# Set the changelog output using a different approach
{
echo "changelog<<CHANGELOG_EOF"
echo -e "$CHANGELOG"
echo "CHANGELOG_EOF"
} >> $GITHUB_OUTPUT
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.version }}
release_name: Release ${{ steps.version.outputs.version }}
body: |
${{ steps.changelog.outputs.changelog }}
## Docker Image
The Docker image is available at:
```
ghcr.io/${{ github.repository }}:${{ steps.version.outputs.version }}
```
draft: false
prerelease: ${{ contains(steps.version.outputs.version, 'alpha') || contains(steps.version.outputs.version, 'beta') || contains(steps.version.outputs.version, 'rc') }}
notify:
needs: [create-release]
runs-on: ubuntu-latest
if: always()
steps:
- name: Notify on success
if: needs.create-release.result == 'success'
run: |
echo "✅ Release ${{ github.ref_name }} created successfully!"
echo "🐳 Docker image published to ghcr.io/${{ github.repository }}:${{ github.ref_name }}"
echo "📦 Release available at https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }}"
- name: Notify on failure
if: needs.create-release.result == 'failure'
run: |
echo "❌ Release creation failed!"
exit 1