name: Build and Release
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: |
python -m pytest tests/ -v || echo "No tests found, skipping"
- name: Lint with flake8
run: |
pip install flake8
flake8 src/ --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 src/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
release:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Analyze Conventional Commits
id: commits
run: |
# Get all commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
COMMITS=$(git log --pretty=%B)
else
COMMITS=$(git log $LAST_TAG..HEAD --pretty=%B)
fi
# Determine version bump type based on conventional commits
HAS_BREAKING=false
HAS_FEATURE=false
if echo "$COMMITS" | grep -q "^BREAKING CHANGE:"; then
HAS_BREAKING=true
fi
if echo "$COMMITS" | grep -q "^feat"; then
HAS_FEATURE=true
fi
echo "has_breaking=${HAS_BREAKING}" >> $GITHUB_OUTPUT
echo "has_feature=${HAS_FEATURE}" >> $GITHUB_OUTPUT
- name: Get current version
id: version
run: |
# Get the current version from git tags, default to 0.0.0 if no tags exist
CURRENT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
CURRENT_VERSION=${CURRENT_VERSION#v} # Remove 'v' prefix
# Parse version components
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
# Increment version based on Conventional Commits
if [ "${{ steps.commits.outputs.has_breaking }}" = "true" ]; then
NEW_MAJOR=$((MAJOR + 1))
NEW_VERSION="${NEW_MAJOR}.0.0"
elif [ "${{ steps.commits.outputs.has_feature }}" = "true" ]; then
NEW_MINOR=$((MINOR + 1))
NEW_VERSION="${MAJOR}.${NEW_MINOR}.0"
else
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}"
fi
echo "current_version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
echo "new_version_tag=v${NEW_VERSION}" >> $GITHUB_OUTPUT
- name: Create git tag
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git tag ${{ steps.version.outputs.new_version_tag }}
git push origin ${{ steps.version.outputs.new_version_tag }}
- name: Create release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.new_version_tag }}
release_name: Release ${{ steps.version.outputs.new_version_tag }}
body: |
## What's Changed
Automated release ${{ steps.version.outputs.new_version_tag }}
### Docker Image
```bash
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.new_version_tag }}
```
### Features
- Wealthfolio API integration
- FastAPI MCP server
- OpenWebUI compatibility
- n8n workflow support
### Previous Version
${{ steps.version.outputs.current_version }}
draft: false
prerelease: false
build-and-push:
runs-on: ubuntu-latest
needs: release
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get current version for Docker tag
id: docker_version
run: |
CURRENT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "version_tag=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
- name: Extract metadata
id: meta
run: |
echo "tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.docker_version.outputs.version_tag }}" >> $GITHUB_OUTPUT
echo "labels=org.opencontainers.image.title=Wealthfolio MCP Server" >> $GITHUB_OUTPUT
echo "labels=org.opencontainers.image.description=A Model Context Protocol server for Wealthfolio integration" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}