-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from egraphs-good/upgrade-pyo3
Create releases through Github UI
- Loading branch information
Showing
3 changed files
with
111 additions
and
0 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,28 @@ | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
type: | ||
description: "Release type" | ||
required: true | ||
default: "major" | ||
type: choice | ||
options: | ||
- major | ||
- minor | ||
- patch | ||
|
||
jobs: | ||
bump-version: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- run: | | ||
git config user.name github-actions | ||
git config user.email github-actions@github.com | ||
- run: python increment_version.py $type | ||
env: | ||
TYPE: ${{ inputs.type }} | ||
- run: git push | ||
- run: git push --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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
""" | ||
Version Bumper for Cargo.toml and Changelog.md | ||
This script automates the process of version bumping for Rust projects managed with Cargo. It reads the version | ||
from the cargo.toml file, increments it based on the specified component (major, minor, or patch), and updates | ||
both the cargo.toml and changelog.md files accordingly. | ||
It will also add a git commit with the changes and tag it with the new version. | ||
Usage: | ||
Run the script from the command line, specifying the type of version increment as an argument: | ||
$ python bump_version.py [major|minor|patch] | ||
Arguments: | ||
--------- | ||
major - Increments the major component of the version, sets minor and patch to 0 | ||
minor - Increments the minor component of the version, sets patch to 0 | ||
patch - Increments the patch component of the version | ||
https://chat.openai.com/share/6b08906d-23a3-4193-9f4e-87076ce56ddb | ||
""" | ||
|
||
import datetime | ||
import re | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
|
||
def bump_version(major: int, minor: int, patch: int, part: str) -> str: | ||
if part == "major": | ||
major += 1 | ||
minor = 0 | ||
patch = 0 | ||
elif part == "minor": | ||
minor += 1 | ||
patch = 0 | ||
elif part == "patch": | ||
patch += 1 | ||
return f"{major}.{minor}.{patch}" | ||
|
||
|
||
def update_cargo_toml(file_path: Path, new_version: str) -> None: | ||
content = file_path.read_text() | ||
content = re.sub(r'version = "(\d+\.\d+\.\d+)"', f'version = "{new_version}"', content) | ||
file_path.write_text(content) | ||
|
||
|
||
def update_changelog(file_path: Path, new_version: str) -> None: | ||
today = datetime.datetime.now(tz=datetime.timezone.utc).strftime("%Y-%m-%d") | ||
content = file_path.read_text() | ||
new_section = f"## UNRELEASED\n\n## {new_version} ({today})" | ||
content = content.replace("## UNRELEASED", new_section) | ||
file_path.write_text(content) | ||
|
||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 2 or sys.argv[1] not in ("major", "minor", "patch"): | ||
print("Usage: python bump_version.py [major|minor|patch]") | ||
sys.exit(1) | ||
|
||
part = sys.argv[1] | ||
cargo_path = Path("cargo.toml") | ||
changelog_path = Path("docs/changelog.md") | ||
|
||
cargo_content = cargo_path.read_text() | ||
version_match = re.search(r'version = "(\d+)\.(\d+)\.(\d+)"', cargo_content) | ||
if version_match: | ||
major, minor, patch = map(int, version_match.groups()) | ||
else: | ||
print("Current version not found in cargo.toml.") | ||
sys.exit(1) | ||
|
||
new_version = bump_version(major, minor, patch, part) | ||
old_version = f"{major}.{minor}.{patch}" | ||
update_cargo_toml(cargo_path, new_version) | ||
update_changelog(changelog_path, new_version) | ||
|
||
subprocess.run(["git", "commit", "-am", f"Version {new_version}"], check=True) # noqa: S607 | ||
subprocess.run(["git", "tag", f"v{new_version}"], check=True) # noqa: S607 |