Skip to content

Commit

Permalink
new try for version bumps
Browse files Browse the repository at this point in the history
  • Loading branch information
killiansheriff committed Aug 8, 2023
1 parent cd4ad80 commit 98b722f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 43 deletions.
48 changes: 48 additions & 0 deletions .github/scripts/release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3
import json
import subprocess


def get_last_version() -> str:
"""Return the version number of the last release."""
json_string = (
subprocess.run(
["gh", "release", "view", "--json", "tagName"],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
.stdout.decode("utf8")
.strip()
)

return json.loads(json_string)["tagName"]


def bump_patch_number(version_number: str) -> str:
"""Return a copy of `version_number` with the patch number incremented."""
major, minor, patch = version_number.split(".")
return f"{major}.{minor}.{int(patch) + 1}"


def create_new_patch_release():
"""Create a new patch release on GitHub."""
try:
last_version_number = get_last_version()
except subprocess.CalledProcessError as err:
if err.stderr.decode("utf8").startswith("HTTP 404:"):
# The project doesn't have any releases yet.
new_version_number = "0.0.1"
else:
raise
else:
new_version_number = bump_patch_number(last_version_number)

subprocess.run(
["gh", "release", "create", "--generate-notes", new_version_number],
check=True,
)


if __name__ == "__main__":
create_new_patch_release()
17 changes: 17 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Publish to PyPI.org
on:
release:
types: [published]
jobs:
pypi:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- run: python3 -m pip install --upgrade build && python3 -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
39 changes: 0 additions & 39 deletions .github/workflows/python-publish.yml

This file was deleted.

12 changes: 12 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Create a new patch release
on: workflow_dispatch
jobs:
github:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create new patch release
run: .github/scripts/release.py
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
[build-system]
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]


[project]
name = "WarrenCowleyParameters"
# version = "2023.1"
dynamic = ["version"]
[tool.setuptools_scm]
version_file = "WarrenCowleyParameters/_version.py"
description = "OVITO Python modifier to compute Warren-Cowley parameters."
keywords = ["ovito", "python-modifier"]
authors = [{name = "Killian Sheriff", email = "[email protected]"}]
Expand Down

0 comments on commit 98b722f

Please sign in to comment.