136 lines
4.1 KiB
YAML
136 lines
4.1 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
env:
|
|
NTFY_URL: http://ntfy.observability.svc.cluster.local:80
|
|
|
|
jobs:
|
|
lint:
|
|
name: Lint
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up uv
|
|
uses: astral-sh/setup-uv@v7
|
|
with:
|
|
version: "latest"
|
|
activate-environment: false
|
|
|
|
- name: Set up Python
|
|
run: uv python install 3.13
|
|
|
|
- name: Install dependencies
|
|
run: uv sync --frozen --extra dev
|
|
|
|
- name: Run ruff check
|
|
run: uv run ruff check .
|
|
|
|
- name: Run ruff format check
|
|
run: uv run ruff format --check .
|
|
|
|
test:
|
|
name: Test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up uv
|
|
uses: astral-sh/setup-uv@v7
|
|
with:
|
|
version: "latest"
|
|
activate-environment: false
|
|
|
|
- name: Set up Python
|
|
run: uv python install 3.13
|
|
|
|
- name: Install dependencies
|
|
run: uv sync --frozen --extra dev
|
|
|
|
- name: Run tests with coverage
|
|
run: uv run pytest --cov=handler_base --cov-report=xml --cov-report=term
|
|
|
|
release:
|
|
name: Release
|
|
runs-on: ubuntu-latest
|
|
needs: [lint, test]
|
|
if: gitea.ref == 'refs/heads/main' && gitea.event_name == 'push'
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Determine version bump
|
|
id: version
|
|
run: |
|
|
# Get latest tag or default to v0.0.0
|
|
LATEST=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
|
VERSION=${LATEST#v}
|
|
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
|
|
|
|
# Check commit message for keywords
|
|
MSG="${{ gitea.event.head_commit.message }}"
|
|
if echo "$MSG" | grep -qiE "^major:|BREAKING CHANGE"; then
|
|
MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0
|
|
BUMP="major"
|
|
elif echo "$MSG" | grep -qiE "^(minor:|feat:)"; then
|
|
MINOR=$((MINOR + 1)); PATCH=0
|
|
BUMP="minor"
|
|
else
|
|
PATCH=$((PATCH + 1))
|
|
BUMP="patch"
|
|
fi
|
|
|
|
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
|
|
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
echo "bump=$BUMP" >> $GITHUB_OUTPUT
|
|
echo "Bumping $LATEST → $NEW_VERSION ($BUMP)"
|
|
|
|
- name: Create and push tag
|
|
run: |
|
|
git config user.name "gitea-actions[bot]"
|
|
git config user.email "actions@git.daviestechlabs.io"
|
|
git tag -a ${{ steps.version.outputs.version }} -m "Release ${{ steps.version.outputs.version }}"
|
|
git push origin ${{ steps.version.outputs.version }}
|
|
|
|
notify:
|
|
name: Notify
|
|
runs-on: ubuntu-latest
|
|
needs: [lint, test, release]
|
|
if: always()
|
|
steps:
|
|
- name: Notify on success
|
|
if: needs.lint.result == 'success' && needs.test.result == 'success'
|
|
run: |
|
|
curl -s \
|
|
-H "Title: ✅ CI Passed: ${{ gitea.repository }}" \
|
|
-H "Priority: default" \
|
|
-H "Tags: white_check_mark,github" \
|
|
-H "Click: ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" \
|
|
-d "Branch: ${{ gitea.ref_name }}
|
|
Commit: ${{ gitea.event.head_commit.message || gitea.sha }}
|
|
Release: ${{ needs.release.result == 'success' && 'created' || 'skipped' }}" \
|
|
${{ env.NTFY_URL }}/gitea-ci
|
|
|
|
- name: Notify on failure
|
|
if: needs.lint.result == 'failure' || needs.test.result == 'failure'
|
|
run: |
|
|
curl -s \
|
|
-H "Title: ❌ CI Failed: ${{ gitea.repository }}" \
|
|
-H "Priority: high" \
|
|
-H "Tags: x,github" \
|
|
-H "Click: ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" \
|
|
-d "Branch: ${{ gitea.ref_name }}
|
|
Commit: ${{ gitea.event.head_commit.message || gitea.sha }}
|
|
Lint: ${{ needs.lint.result }}
|
|
Test: ${{ needs.test.result }}" \
|
|
${{ env.NTFY_URL }}/gitea-ci
|