-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use plugin configuration * precommit * banditignore subprocess * precommit * nosec multiline and imports * run publish on changes to version.toml --------- Co-authored-by: Benjamin Morris <[email protected]> Co-authored-by: Benjamin Morris <[email protected]>
- Loading branch information
1 parent
3fecc1b
commit 3cbdd91
Showing
6 changed files
with
197 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# takes the most recent commit on main, bumps version based on | ||
# semver_component input, and PRs change back to main | ||
name: Bump version and PR | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
semver_component: | ||
description: "Semantic versioning component to bump" | ||
required: true | ||
type: choice | ||
default: "patch" | ||
options: | ||
- major | ||
- minor | ||
- patch | ||
- dev | ||
|
||
jobs: | ||
publish: | ||
name: Bump and PR | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
contents: write | ||
pull-requests: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: main | ||
|
||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install bumpver | ||
- name: Bump version | ||
run: | | ||
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 | ||
with: | ||
branch: workflow-release | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# 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 # nosec | ||
import sys | ||
from typing import List, Set | ||
|
||
import toml | ||
|
||
|
||
def main(): | ||
if len(sys.argv) < 2: | ||
raise ValueError("No component specified for bumping version") | ||
|
||
component: str = sys.argv[1].lower() | ||
valid_options: Set[str] = {"major", "minor", "patch", "dev"} | ||
|
||
if component not in valid_options: | ||
raise ValueError(f"Component must be one of {valid_options}") | ||
|
||
version: str = toml.load("pyproject.toml")["project"]["version"] | ||
version_components: List[str] = version.split(".") | ||
|
||
update_output: subprocess.CompletedProcess = None | ||
# 4 components means we currently have a dev version | ||
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"]) # nosec | ||
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"]) # nosec | ||
else: | ||
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( # nosec | ||
["bumpver", "update", "--patch", "--tag=dev", "-n"] | ||
) | ||
else: | ||
update_output = subprocess.run(["bumpver", "update", f"--{component}", "-n"]) # nosec | ||
|
||
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}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# This file is intended to be called by a github workflow | ||
import subprocess # nosec | ||
|
||
import toml | ||
|
||
|
||
def main(): | ||
version: str = toml.load("pyproject.toml")["project"]["version"] | ||
tag_output: subprocess.CompletedProcess = subprocess.run( # nosec | ||
["git", "tag", f"v{version}"] | ||
) | ||
if tag_output.returncode != 0: | ||
raise RuntimeError("failed to tag") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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" |