Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 37 additions & 33 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,72 @@
name: Auto-release on version bump
name: Auto-release on push to main

permissions:
contents: write

on:
push:
branches: [main]
paths:
- 'anton/__init__.py'
workflow_dispatch:

concurrency:
group: auto-release-${{ github.ref }}
cancel-in-progress: false

env:
CALVER_MAJOR: 2

jobs:
auto-release:
runs-on: ubuntu-latest
# Skip auto-version commits to prevent loops (belt-and-suspenders;
# GITHUB_TOKEN commits don't trigger workflows anyway)
if: "!contains(github.event.head_commit.message, '[skip ci]')"
outputs:
tag: ${{ steps.version.outputs.tag }}
created: ${{ steps.tag_check.outputs.exists == 'false' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-depth: 0 # need tags for sequence calculation

- name: Read __version__ from anton/__init__.py
- name: Compute CalVer version
id: version
run: |
PKG_VERSION=$(grep -oE '__version__\s*=\s*"[^"]+"' anton/__init__.py | grep -oE '"[^"]+"' | tr -d '"')
if [ -z "${PKG_VERSION}" ]; then
echo "::error::Could not parse __version__ from anton/__init__.py"
exit 1
fi
echo "version=${PKG_VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=v${PKG_VERSION}" >> "$GITHUB_OUTPUT"
set -euo pipefail

- name: Check if tag already exists
id: tag_check
run: |
TAG="${{ steps.version.outputs.tag }}"
if git rev-parse "refs/tags/${TAG}" >/dev/null 2>&1; then
echo "Tag ${TAG} already exists; nothing to do."
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "Tag ${TAG} does not exist; will create release."
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
MAJOR=${{ env.CALVER_MAJOR }}
YY=$(date -u +%y) # e.g. 26
M=$(date -u +%-m) # e.g. 6 (no zero-pad)
DD=$(date -u +%-d) # e.g. 23 (no zero-pad)

# Find the highest sequence for today's date
PREFIX="v${MAJOR}.${YY}.${M}.${DD}."
SEQ=0
for tag in $(git tag -l "${PREFIX}*" | sort -t. -k5 -n); do
N="${tag##*.}"
if [[ "$N" =~ ^[0-9]+$ ]] && [ "$N" -gt "$SEQ" ]; then
SEQ="$N"
fi
done
SEQ=$((SEQ + 1))

VERSION="${MAJOR}.${YY}.${M}.${DD}.${SEQ}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=v${VERSION}" >> "$GITHUB_OUTPUT"
echo "Computed version: ${VERSION}"

- name: Create tag and GitHub release
if: steps.tag_check.outputs.exists == 'false'
- name: Create tag and GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.version.outputs.tag }}
run: |
gh release create "${TAG}" \
--target "${GITHUB_SHA}" \
--title "${TAG}" \
--generate-notes
git tag "${{ steps.version.outputs.tag }}"
git push origin "${{ steps.version.outputs.tag }}"
gh release create "${{ steps.version.outputs.tag }}" \
--generate-notes \
--title "${{ steps.version.outputs.tag }}"

publish:
name: Publish to PyPI
needs: auto-release
if: needs.auto-release.outputs.created == 'true'
runs-on: ubuntu-latest
environment: pypi
permissions:
Expand All @@ -71,6 +75,7 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ needs.auto-release.outputs.tag }}
fetch-depth: 0 # hatch-vcs needs tags to derive version

- name: Setup uv
uses: astral-sh/setup-uv@v5
Expand All @@ -87,7 +92,6 @@ jobs:

e2e:
needs: auto-release
if: needs.auto-release.outputs.created == 'true'
uses: ./.github/workflows/tests_e2e_release.yml
with:
tag: ${{ needs.auto-release.outputs.tag }}
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling"]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
Expand Down Expand Up @@ -50,8 +50,8 @@ Issues = "https://github.com/mindsdb/anton/issues"
anton = "anton.cli:app"

[tool.hatch.version]
source = "regex"
path = "anton/__init__.py"
source = "vcs"
fallback-version = "2.0.0-dev"

[tool.pytest.ini_options]
asyncio_mode = "auto"
Expand Down
Loading