Skip to content

Commit

Permalink
Merge pull request #134 from egraphs-good/upgrade-pyo3
Browse files Browse the repository at this point in the history
Create releases through Github UI
  • Loading branch information
saulshanabrook authored Apr 24, 2024
2 parents 773bd59 + 90979f8 commit 8a888b5
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/version.yml
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
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
82 changes: 82 additions & 0 deletions increment_version.py
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

0 comments on commit 8a888b5

Please sign in to comment.