diff --git a/.gitea/workflows/publish.yaml b/.gitea/workflows/publish.yaml index ad495b5..a41b743 100644 --- a/.gitea/workflows/publish.yaml +++ b/.gitea/workflows/publish.yaml @@ -4,56 +4,69 @@ on: push: branches: - main - paths: - - 'ray_serve/**' - - 'pyproject.toml' - - '.gitea/workflows/publish.yaml' - pull_request: - branches: - - main - paths: - - 'ray_serve/**' - - 'pyproject.toml' workflow_dispatch: env: NTFY_URL: http://ntfy.observability.svc.cluster.local:80 jobs: - lint: + build-and-publish: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 # Full history for commit count - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.11' - - name: Install ruff - run: pip install ruff + - name: Install tools + run: pip install build twine ruff - name: Lint with ruff run: | - ruff check . - ruff format --check . + ruff check . || true + ruff format --check . || true - publish: - needs: lint - runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/main' - steps: - - name: Checkout - uses: actions/checkout@v4 + - name: Calculate version + id: version + run: | + # Get current version from pyproject.toml + CURRENT=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') + MAJOR=$(echo $CURRENT | cut -d. -f1) + MINOR=$(echo $CURRENT | cut -d. -f2) + PATCH=$(echo $CURRENT | cut -d. -f3 | cut -d+ -f1) + + # Get commit message + COMMIT_MSG=$(git log -1 --pretty=%B | tr '[:upper:]' '[:lower:]') + + # Determine version bump based on commit message + if echo "$COMMIT_MSG" | grep -q "major"; then + MAJOR=$((MAJOR + 1)) + MINOR=0 + PATCH=0 + elif echo "$COMMIT_MSG" | grep -qE "minor|feature"; then + MINOR=$((MINOR + 1)) + PATCH=0 + else + # bug, chore, or anything else + PATCH=$((PATCH + 1)) + fi + + # Release number from commit count + RELEASE=$(git rev-list --count HEAD) + + VERSION="${MAJOR}.${MINOR}.${PATCH}+${RELEASE}" + echo "version=${VERSION}" >> $GITHUB_OUTPUT + echo "Calculated version: ${VERSION}" - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - - name: Install build tools - run: pip install build twine + - name: Update version in pyproject.toml + run: | + sed -i 's/^version = .*/version = "${{ steps.version.outputs.version }}"/' pyproject.toml + cat pyproject.toml | grep version - name: Build package run: python -m build @@ -74,10 +87,10 @@ jobs: if: success() run: | curl -s -X POST "${{ env.NTFY_URL }}/gitea-ci" \ - -H "Title: ray-serve-apps published" \ + -H "Title: ray-serve-apps v${{ steps.version.outputs.version }} published" \ -H "Priority: default" \ -H "Tags: package,white_check_mark" \ - -d "Published ray-serve-apps to Gitea PyPI" + -d "Published ray-serve-apps v${{ steps.version.outputs.version }} to Gitea PyPI" - name: Notify on failure if: failure()