Skip to content

Merge pull request #3 from kintsugi-tax/fix/bump-ver-0.3.1 #23

Merge pull request #3 from kintsugi-tax/fix/bump-ver-0.3.1

Merge pull request #3 from kintsugi-tax/fix/bump-ver-0.3.1 #23

Workflow file for this run

name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
lint-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Poetry
uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
with:
version: "2.1.3"
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install dependencies
run: poetry install --no-interaction
- name: Run pre-commit hooks
run: poetry run pre-commit run --all-files
- name: Check version consistency
run: |
PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/' || true)
INIT_VERSION=$(grep '^__version__ = ' squawk_alembic/__init__.py | sed 's/__version__ = "\(.*\)"/\1/' || true)
if [ -z "$PYPROJECT_VERSION" ] || [ -z "$INIT_VERSION" ]; then
echo "::error::Could not parse version from pyproject.toml or __init__.py"
exit 1
fi
if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ]; then
echo "::error::Version mismatch: pyproject.toml ($PYPROJECT_VERSION) != __init__.py ($INIT_VERSION)"
echo "Run 'make bump VERSION=x.y.z' to update both files."
exit 1
fi
echo "Versions match: $PYPROJECT_VERSION"
if [ "${{ github.event_name }}" = "pull_request" ]; then
git fetch origin main --depth=1
MAIN_VERSION=$(git show origin/main:pyproject.toml | grep '^version = ' | sed 's/version = "\(.*\)"/\1/' || true)
if [ -z "$MAIN_VERSION" ]; then
echo "::warning::Could not determine version on main, skipping version bump check"
elif [ "$PYPROJECT_VERSION" = "$MAIN_VERSION" ]; then
echo "::error::Version $PYPROJECT_VERSION is the same as on main. Please bump the version."
echo "Run 'make bump VERSION=x.y.z' to update both files."
exit 1
fi
fi
- name: Run tests
run: poetry run pytest tests/ -v
auto-tag:
needs: lint-and-test
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
tag: ${{ steps.tag.outputs.tag }}
created: ${{ steps.tag.outputs.created }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create tag if needed
id: tag
run: |
VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
TAG="v${VERSION}"
echo "Detected version: $VERSION"
echo "Tag: $TAG"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists. Nothing to do."
echo "created=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Creating and pushing tag $TAG"
git tag "$TAG"
git push origin "$TAG"
echo "created=true" >> "$GITHUB_OUTPUT"
release:
needs: auto-tag
if: needs.auto-tag.outputs.created == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.auto-tag.outputs.tag }}
run: |
gh release create "$TAG" \
--title "Release $TAG" \
--generate-notes