Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump version with github actions #202

Merged
merged 3 commits into from
Oct 17, 2023
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
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()