Skip to content

Commit

Permalink
precommit
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Morris committed Jul 1, 2024
1 parent e2fb00c commit 2427360
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 68 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/create_publish_pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
git config --global user.name 'aicsgithub'
git config --global user.email '[email protected]'
python scripts/publish_bumpver_handler.py ${{ inputs.semver_component }}
# takes the commit from the last step, pushes to new branch, release, and creates PR
- name: Create pull request
uses: peter-evans/create-pull-request@v6
Expand All @@ -54,11 +54,9 @@ jobs:
base: main
title: Bump version and publish
body: See commit message or diff for new version number

- name: Tag version
run: |
git checkout workflow-release
python scripts/tag_with_current_version.py
git push origin --tags
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ push = false
[tool.bumpver.file_patterns]
"pyproject.toml" = ['current_version = "{version}"', 'version = "{version}"']
"version.toml" = ['version = "{version}"']
"cyto_dl/__init__.py" = ['__version__ = "{version}"']
"cyto_dl/__init__.py" = ['__version__ = "{version}"']
106 changes: 48 additions & 58 deletions scripts/publish_bumpver_handler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
# this file is intended to be called by a github workflow (.github/workflows/publish_to_pypi.yaml)
# it makes decisions based on the current version and the component specified for bumping,
# which the workflow cannot do

"""
TESTING:
- add and commit any changes (keep track of this commit hash)
- bumpver update --set-version 1.0.0
- python publish_bumpver_handler.py
- expect: ValueError
- python publish_bumpver_handler.py fake
- expect: ValueError
- python publish_bumpver_handler.py major
- expect: version updated to 2.0.0
- python publish_bumpver_handler.py minor
- expect: version updated to 2.1.0
- python publish_bumpver_handler.py patch
- expect: version updated to 2.1.1
- python publish_bumpver_handler.py dev
- expect: version updated to 2.1.2.dev0
- python publish_bumpver_handler.py dev
- expect: version updated to 2.1.2.dev1
- python publish_bumpver_handler.py major
- expect: ValueError
- python publish_bumpver_handler.py minor
- expect: ValueError
- python publish_bumpver_handler.py patch
- expect: version updated to 2.1.2
- git reset --hard {hash of the commit made at the beginning}
- git tag --delete 1.0.0 2.0.0 2.1.0 2.1.1 2.1.2 2.1.2.dev0 2.1.2.dev1
"""

import subprocess
import sys
from typing import Set, List
from typing import List, Set

import toml


Expand All @@ -25,79 +66,28 @@ def main():
if len(version_components) == 4:
if component == "dev":
# increment the dev tag (e.g. 1.0.0.dev0 -> 1.0.0.dev1)
update_output = subprocess.run(
["bumpver", "update", "--tag-num", "-n"]
)
update_output = subprocess.run(["bumpver", "update", "--tag-num", "-n"])
elif component == "patch":
# finalize the patch by removing dev tag (e.g. 1.0.0.dev1 -> 1.0.0)
update_output = subprocess.run(
["bumpver", "update", "--tag=final", "-n"]
)
update_output = subprocess.run(["bumpver", "update", "--tag=final", "-n"])
else:
raise ValueError(
"Cannot update major or minor version while dev version is current"
)
raise ValueError("Cannot update major or minor version while dev version is current")

elif len(version_components) == 3:
if component == "dev":
# increment patch and begin at dev0 (e.g. 1.0.0 -> 1.0.1.dev0)
update_output = subprocess.run(
["bumpver", "update", "--patch", "--tag=dev", "-n"]
)
update_output = subprocess.run(["bumpver", "update", "--patch", "--tag=dev", "-n"])
else:
update_output = subprocess.run(
["bumpver", "update", f"--{component}", "-n"]
)
update_output = subprocess.run(["bumpver", "update", f"--{component}", "-n"])

else:
raise ValueError(
f"Unknown version format: {version}. Expected MAJOR.MINOR.PATCH[.PYTAGNUM]"
)

if update_output.returncode != 0:
raise RuntimeError(
f"bumpver exited with code {update_output.returncode}"
)
raise RuntimeError(f"bumpver exited with code {update_output.returncode}")


if __name__ == "__main__":
main()

"""
TESTING:
- add and commit any changes (keep track of this commit hash)
- bumpver update --set-version 1.0.0
- python publish_bumpver_handler.py
- expect: ValueError
- python publish_bumpver_handler.py fake
- expect: ValueError
- python publish_bumpver_handler.py major
- expect: version updated to 2.0.0
- python publish_bumpver_handler.py minor
- expect: version updated to 2.1.0
- python publish_bumpver_handler.py patch
- expect: version updated to 2.1.1
- python publish_bumpver_handler.py dev
- expect: version updated to 2.1.2.dev0
- python publish_bumpver_handler.py dev
- expect: version updated to 2.1.2.dev1
- python publish_bumpver_handler.py major
- expect: ValueError
- python publish_bumpver_handler.py minor
- expect: ValueError
- python publish_bumpver_handler.py patch
- expect: version updated to 2.1.2
- git reset --hard {hash of the commit made at the beginning}
- git tag --delete 1.0.0 2.0.0 2.1.0 2.1.1 2.1.2 2.1.2.dev0 2.1.2.dev1
"""
7 changes: 3 additions & 4 deletions scripts/tag_with_current_version.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# This file is intended to be called by a github workflow
import subprocess

import toml


def main():
version: str = toml.load("pyproject.toml")["project"]["version"]
tag_output: subprocess.CompletedProcess = subprocess.run(
["git", "tag", f"v{version}"]
)
tag_output: subprocess.CompletedProcess = subprocess.run(["git", "tag", f"v{version}"])
if tag_output.returncode != 0:
raise RuntimeError("failed to tag")


if __name__ == "__main__":
main()
main()
2 changes: 1 addition & 1 deletion version.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -----DO NOT MODIFY THIS FILE-----
# This file should only be modified by bumpver, which should in turn only be ran
# via a GH Action
version = "0.1.7"
version = "0.1.7"

0 comments on commit 2427360

Please sign in to comment.