From fff8eace091f596df3d953ce63b761ddb9ed3e3a Mon Sep 17 00:00:00 2001 From: Christopher Dignam Date: Mon, 16 Oct 2023 22:53:26 -0400 Subject: [PATCH] bump version with github actions (#202) --- .github/workflows/bump_version.yml | 49 ++++++++++++++++++++++++++++++ .python-version | 1 + poetry.lock | 15 +++++++-- pyproject.toml | 1 + s/update-version | 44 +++++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/bump_version.yml create mode 100644 .python-version create mode 100755 s/update-version diff --git a/.github/workflows/bump_version.yml b/.github/workflows/bump_version.yml new file mode 100644 index 000000000..05cf237f3 --- /dev/null +++ b/.github/workflows/bump_version.yml @@ -0,0 +1,49 @@ +on: + workflow_dispatch: + inputs: + version: + description: "Version level to increase" + required: true + default: "minor" + type: choice + options: + - major + - minor + - patch + +jobs: + # https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ + update-version: + name: "Publish Python 🐍 distribution 📦 to PyPI" + runs-on: ubuntu-latest + permissions: + id-token: write + steps: + - uses: actions/checkout@v3 + + - name: Install poetry + run: | + pipx install poetry + poetry config virtualenvs.create true + poetry config virtualenvs.in-project true + + - uses: actions/setup-python@v4 + with: + python-version: "3.7" + cache: "poetry" + + - name: Update version + run: ./s/update-version ${{ inputs.version }} + + - name: Build + run: poetry build + + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + + - name: Push changes + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git commit -am 'Increment version: ${{ inputs.version }}' + git push diff --git a/.python-version b/.python-version new file mode 100644 index 000000000..214b521fe --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.7.13 diff --git a/poetry.lock b/poetry.lock index 7e951200a..e04b26209 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. [[package]] name = "asgiref" @@ -533,6 +533,17 @@ files = [ {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] +[[package]] +name = "tomlkit" +version = "0.12.1" +description = "Style preserving TOML library" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tomlkit-0.12.1-py3-none-any.whl", hash = "sha256:712cbd236609acc6a3e2e97253dfc52d4c2082982a88f61b640ecf0817eab899"}, + {file = "tomlkit-0.12.1.tar.gz", hash = "sha256:38e1ff8edb991273ec9f6181244a6a391ac30e9f5098e7535640ea6be97a7c86"}, +] + [[package]] name = "typed-ast" version = "1.5.4" @@ -642,4 +653,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.7" -content-hash = "71293af57fb7853bb135fb07b16a2d1c509fa23de7fd19bc5e7d862e1bf5dc64" +content-hash = "9d3c207ff83a060bdf98a25f2eba5dc1b36113fce165b3c05c4b72e5ebd3accd" diff --git a/pyproject.toml b/pyproject.toml index bbd0dbb24..7ba916ba1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ types-PyYAML = "^6.0.1" types-pytz = "^2021.3.0" psycopg2-binary = "^2.9.3" ruff = "^0.0.286" +tomlkit = "^0.12.1" [tool.black] line-length = 88 diff --git a/s/update-version b/s/update-version new file mode 100755 index 000000000..129056bb5 --- /dev/null +++ b/s/update-version @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# This script requires fastmod to be installed +# fastmod: https://github.com/facebookincubator/fastmod + +from pathlib import Path +import re +import argparse +import tomlkit + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("version_increment", choices=["major", "minor", "patch"]) + args = parser.parse_args() + + pyproject_path = Path(".").parent.parent / "pyproject.toml" + pyproject = pyproject_path.read_text() + + current_version = tomlkit.loads(pyproject)["tool"]["poetry"]["version"] + + major, minor, patch = [int(x) for x in current_version.split(".")] + + if args.version_increment == "major": + major += 1 + minor = 0 + patch = 0 + elif args.version_increment == "minor": + minor += 1 + patch = 0 + elif args.version_increment == "patch": + patch += 1 + else: + raise ValueError("Unexpected value") + + new_version = f"{major}.{minor}.{patch}" + + updated_pyproject = re.sub( + r'^version = ".*"', f'version = "{new_version}"', pyproject, flags=re.MULTILINE + ) + pyproject_path.write_text(updated_pyproject) + + +if __name__ == "__main__": + main()