Skip to content

Commit

Permalink
✨ feature: implement semantic release workflow and update versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
jedzill4 committed Jan 25, 2025
1 parent 5858d4d commit de7a81a
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 13 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Release

on:
push:
branches:
- feature/gh-actions # Trigger on push to this branch
pull_request:
branches:
- main # Trigger on PR merge to main

concurrency:
group: release
cancel-in-progress: true

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: Configure Git User
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
- name: Install Dependencies
run: |
pip install python-semantic-release setuptools_scm
- name: Run Semantic Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYTHON_TOKEN: ${{ secrets.PYPI_TOKEN }} # Optional if uploading to PyPI
run: semantic-release publish

- name: Force Push Updated Tag (if required)
if: ${{ github.ref_name == 'feature/semantic-release' }}
run: |
latest_tag=$(git describe --tags --abbrev=0)
git tag -f "$latest_tag"
git push origin --tags --force
sync-dev:
needs: release
if: ${{ github.ref_name == 'main' }}
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Configure Git User
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
- name: Sync Dev Branch
run: |
git fetch origin
git checkout dev
git merge origin/main --no-edit
git push origin dev
4 changes: 2 additions & 2 deletions aymurai/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE

__version__ = version = "1.0.1.dev208+g3bcbdd7.d20241220"
__version_tuple__ = version_tuple = (1, 0, 1, "dev208", "g3bcbdd7.d20241220")
__version__ = version = "1.0.1.dev210+g5858d4d.d20250125"
__version_tuple__ = version_tuple = (1, 0, 1, "dev210", "g5858d4d.d20250125")
Empty file added hooks/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions hooks/semantic_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from subprocess import run


def post_version(version: str):
"""
Hook to update the version file, commit the changes, and force push the new tag.
This hook uses the Gitmoji specification for commit messages.
"""
# Update the version file using uv build
run(["uv", "build", "--frozen"], check=True)

# Commit the updated version file
run(["git", "add", "aymurai/version.py"], check=True)
run(["git", "commit", "-m", f"🔖 chore: update version to {version}"], check=True)
run(["git", "push"], check=True)

# Update and force-push the Git tag
tag_name = f"v{version}"
run(["git", "tag", "-f", tag_name], check=True)
run(["git", "push", "--force", "origin", tag_name], check=True)
60 changes: 50 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

#######################################################################################
# Project metadata
#######################################################################################
[project]
name = "aymurai"
requires-python = ">=3.10"
Expand Down Expand Up @@ -52,6 +55,9 @@ classifiers = [
"Programming Language :: Python :: 3.10",
]

#######################################################################################
# Dependencies
#######################################################################################
dependencies = [
"requests==2.32.3",
"numpy<2.0.0",
Expand Down Expand Up @@ -96,18 +102,15 @@ dependencies = [
"python-dotenv==1.0.1",
]

[project.urls]
Homepage = "https://www.aymurai.info/"
Repository = "https://github.com/aymurAI/backend"
Issues = "https://github.com/AymurAI/backend/issues"

# [project.optional-dependencies]
#######################################################################################
# Optional dependencies
#######################################################################################
[dependency-groups]
# gpu = [
# "torch @ https://download.pytorch.org/whl/cu113/torch-1.12.1%2Bcu113-cp310-cp310-linux_x86_64.whl",
# "spacy[cuda113]==3.8.3",
# ]

[dependency-groups]
dev = [
"tensorboard==2.18.0",
"matplotlib==3.10.0",
Expand All @@ -117,29 +120,66 @@ dev = [
"nbstripout==0.8.0",
"pip-search==0.0.12",
"jupyter==1.1.1",
"python-semantic-release>=9.16.1",
]
lint = ["ruff"]


#######################################################################################
# Project extra configuration
#######################################################################################
[project.urls]
Homepage = "https://www.aymurai.info/"
Repository = "https://github.com/aymurAI/backend"
Issues = "https://github.com/AymurAI/backend/issues"

# Package
# =======
[tool.setuptools.packages.find]
include = ["aymurai"]

# Scripts
# =======
[project.scripts]
aymurai-api = "aymurai.api.main:main"


# Package data
# ============
[tool.setuptools.package-data]
"*" = ["*.yml", "*.yaml", "*.csv"]

#######################################################################################
# Setuptools-scm configuration
#######################################################################################
[tool.setuptools_scm]
version_file = "aymurai/version.py"


[tool.uv]
python-preference = "system"
#######################################################################################
# Semantic-release configuration
#######################################################################################
[tool.semantic_release]
version_source = "tag" # Semantic-release uses Git tags to determine versions
# branch = "main" # Release from the main branch
branch = "feature/gh-actions" # Release from the main branch
commit_parser = "emoji" # Use Gitmoji for commit parsing
changelog_file = "CHANGELOG.md" # Optional changelog generation
upload_to_pypi = false

[tool.semantic_release.hooks]
post_version = "hooks.semantic_hooks:post_version"


#######################################################################################
# Pylint configuration
#######################################################################################
[tool.pylint.messages_control]
disable = "C0330, C0326"


#######################################################################################
# Isort configuration
#######################################################################################
[tool.isort]
profile = "black"
length_sort = true
Expand Down
Loading

0 comments on commit de7a81a

Please # to comment.