Skip to content
Merged
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
63 changes: 60 additions & 3 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ name: Python Publish

on:
release:
types: [created]
types: [published]

jobs:
install-test-and-build:
name: Install, test & build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

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

Expand All @@ -21,6 +25,18 @@ jobs:
with:
poetry-version: 2.1.3

- name: Bump version from tag
run: |
TAG_NAME="${{ github.event.release.tag_name }}"
# expecting tags like v1.2.3
VERSION="${TAG_NAME#v}"
if [ -z "$VERSION" ]; then
echo "Could not extract version from tag: $TAG_NAME" >&2
exit 1
fi
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
poetry run python scripts/bump_version.py "$VERSION"

- name: Test
run: |
poetry install
Expand All @@ -31,6 +47,25 @@ jobs:
rm -rf dist
poetry build

- name: Commit version bump
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

# Show status for debugging
git status

# Add changed files
git add pyproject.toml poetry.lock novem/version.py

# Only commit if there are changes
if ! git diff --cached --quiet; then
git commit -m "Release v$VERSION"
git push origin HEAD:main
else
echo "No changes to commit"
fi

- name: Storage wheel
uses: actions/upload-artifact@v4
with:
Expand All @@ -56,3 +91,25 @@ jobs:

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

- name: Send release notification to Discord
if: success()
env:
RELEASE_NAME: ${{ github.event.release.name }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_URL: ${{ github.event.release.html_url }}
REPO_FULL_NAME: ${{ github.repository }}
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }}
run: |
REPO_NAME=$(echo $REPO_FULL_NAME | cut -d'/' -f2)
MESSAGE=$(jq -n \
--arg repo "$REPO_NAME" \
--arg tag "$RELEASE_TAG" \
--arg name "$RELEASE_NAME" \
--arg url "$RELEASE_URL" \
--arg icon "🚀" \
'{content: "\($icon) \($repo) > [\($tag): \($name)](\($url)) has been released!"}')
curl -H "Content-Type: application/json" \
-X POST \
-d "$MESSAGE" \
"$DISCORD_WEBHOOK"
9 changes: 8 additions & 1 deletion scripts/bump_version.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import pathlib
import re
import subprocess
import sys

VERSION_FILE = pathlib.Path("novem/version.py")


def main() -> None:
next_version = subprocess.check_output(["poetry", "version", "patch", "-s"], text=True).strip()
if len(sys.argv) > 1:
# Use provided version
next_version = sys.argv[1]
subprocess.check_call(["poetry", "version", next_version])
else:
# Default: patch bump
next_version = subprocess.check_output(["poetry", "version", "patch", "-s"], text=True).strip()

content = VERSION_FILE.read_text()
content = re.sub(r'__version__ = ".*?"', f'__version__ = "{next_version}"', content)
Expand Down