Skip to content

Commit

Permalink
bump version with github actions (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
chdsbd authored Oct 17, 2023
1 parent f0b1900 commit fff8eac
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 2 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.7.13
15 changes: 13 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions s/update-version
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit fff8eac

Please sign in to comment.