From 90979f82327426da211451d19ce4e34f6f24065b Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Wed, 24 Apr 2024 16:17:30 -0400 Subject: [PATCH] Create releases through Github UI --- .github/workflows/version.yml | 28 ++++++++++++ docs/changelog.md | 1 + increment_version.py | 82 +++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 .github/workflows/version.yml create mode 100644 increment_version.py diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 00000000..e666dc69 --- /dev/null +++ b/.github/workflows/version.yml @@ -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 diff --git a/docs/changelog.md b/docs/changelog.md index 78f39fee..8a487ffd 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -8,6 +8,7 @@ _This project uses semantic versioning_ - Removes ability to set custom default ruleset for egraph. Either just use the empty default ruleset or explicitly set it for every run - Automatically mark Python builtin operators as preserved if they must return a real Python value - Properly pretty print all items (rewrites, actions, exprs, etc) so that expressions are de-duplicated and state is handled correctly. +- Add automatic releases from github manual action ## 6.1.0 (2024-03-06) diff --git a/increment_version.py b/increment_version.py new file mode 100644 index 00000000..c2b19e37 --- /dev/null +++ b/increment_version.py @@ -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