Skip to content

Commit b1d1a1e

Browse files
feat: add CI/CD workflows and version management
Add GitHub Actions for CI (pre-commit + tests on PR), version-check (pyproject.toml and __init__.py consistency), auto-tag on merge to main, and release creation on tag push. Add make bump target for semver version bumping.
1 parent 3f1a06b commit b1d1a1e

6 files changed

Lines changed: 143 additions & 1 deletion

File tree

.github/workflows/auto-tag.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Auto Tag
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
auto-tag:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Create tag if needed
20+
run: |
21+
VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
22+
TAG="v${VERSION}"
23+
24+
echo "Detected version: $VERSION"
25+
echo "Tag: $TAG"
26+
27+
if git rev-parse "$TAG" >/dev/null 2>&1; then
28+
echo "Tag $TAG already exists. Nothing to do."
29+
exit 0
30+
fi
31+
32+
echo "Creating and pushing tag $TAG"
33+
git tag "$TAG"
34+
git push origin "$TAG"

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
lint-and-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: '3.12'
21+
22+
- name: Install Poetry
23+
uses: snok/install-poetry@v1
24+
with:
25+
version: latest
26+
virtualenvs-create: true
27+
virtualenvs-in-project: true
28+
29+
- name: Install dependencies
30+
run: poetry install --no-interaction
31+
32+
- name: Run pre-commit hooks
33+
run: poetry run pre-commit run --all-files
34+
35+
- name: Run tests
36+
run: poetry run pytest tests/ -v

.github/workflows/release.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Create Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Create GitHub Release
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
run: |
22+
TAG="${GITHUB_REF#refs/tags/}"
23+
gh release create "$TAG" \
24+
--title "Release $TAG" \
25+
--generate-notes
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Version Check
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
check-version-sync:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Check version consistency
16+
run: |
17+
PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
18+
INIT_VERSION=$(grep '^__version__ = ' squawk_alembic/__init__.py | sed 's/__version__ = "\(.*\)"/\1/')
19+
20+
echo "pyproject.toml version: $PYPROJECT_VERSION"
21+
echo "__init__.py version: $INIT_VERSION"
22+
23+
if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ]; then
24+
echo "::error::Version mismatch: pyproject.toml ($PYPROJECT_VERSION) != __init__.py ($INIT_VERSION)"
25+
echo "Run 'make bump VERSION=x.y.z' to update both files."
26+
exit 1
27+
fi
28+
29+
echo "Versions match."

Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
.PHONY: setup_pre_commit run_pre-commit run_unit_tests run_ruff run_pyrefly clean help
1+
.PHONY: setup_pre_commit run_pre-commit run_unit_tests run_ruff run_pyrefly clean help bump
2+
3+
INIT_PY := squawk_alembic/__init__.py
24

35
# This trick comes from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
46
help:
@@ -23,3 +25,18 @@ run_pyrefly: ## Run pyrefly, a static type checker for Python
2325
clean: ## Clean up the project (e.g., remove cache files)
2426
@find . -type f -name '*.pyc' -delete
2527
@find . -type d -name '__pycache__' -delete
28+
29+
bump: ## Bump version (usage: make bump VERSION=0.2.0)
30+
ifndef VERSION
31+
$(error Usage: make bump VERSION=0.2.0)
32+
endif
33+
@echo "Bumping version to $(VERSION)"
34+
@if ! echo "$(VERSION)" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$$'; then \
35+
echo "Error: VERSION must be in semver format (e.g. 0.2.0)"; \
36+
exit 1; \
37+
fi
38+
sed -i.bak 's/^version = ".*"/version = "$(VERSION)"/' pyproject.toml
39+
rm -f pyproject.toml.bak
40+
sed -i.bak 's/^__version__ = ".*"/__version__ = "$(VERSION)"/' $(INIT_PY)
41+
rm -f $(INIT_PY).bak
42+
@echo "Updated pyproject.toml and $(INIT_PY) to $(VERSION)"

squawk_alembic/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.1.0"

0 commit comments

Comments
 (0)