Skip to content

Commit

Permalink
Harmonize scripts to compute versions
Browse files Browse the repository at this point in the history
Harmonizes the scripts to compute the versions. JSON files are only
written if `--write-json` is passed. Furthermore, `--version-suffix`
can no longer be combined with other release types and gives full
control over defining a suffix to the user. Similar changes are applied
to the scripts used in IREE.
  • Loading branch information
marbre committed Dec 11, 2024
1 parent 63edf36 commit ede04d1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ jobs:
id: version_local
run: |
echo "version_suffix=${version_suffix}" >> $GITHUB_OUTPUT
python3 build_tools/python_deploy/compute_local_version.py --version-suffix=${version_suffix} sharktank
python3 build_tools/python_deploy/compute_local_version.py --version-suffix=${version_suffix} shortfin
python3 build_tools/python_deploy/compute_common_version.py -rc --version-suffix=${version_suffix} --write-json
python3 build_tools/python_deploy/compute_local_version.py --version-suffix=${version_suffix} --write-json sharktank
python3 build_tools/python_deploy/compute_local_version.py --version-suffix=${version_suffix} --write-json shortfin
python3 build_tools/python_deploy/compute_common_version.py --version-suffix=${version_suffix} --write-json
- name: Upload version_local.json files
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
Expand Down
29 changes: 11 additions & 18 deletions build_tools/python_deploy/compute_common_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,22 @@
from pathlib import Path
import json
from datetime import datetime
import sys
import subprocess

from packaging.version import Version


parser = argparse.ArgumentParser()
parser.add_argument("--write-json", action="store_true")
parser.add_argument("--version-suffix", action="store", type=str)

release_type = parser.add_mutually_exclusive_group()
release_type.add_argument("-stable", "--stable-release", action="store_true") # default
release_type.add_argument("-rc", "--nightly-release", action="store_true")

release_type.add_argument("-dev", "--development-release", action="store_true")
release_type.add_argument("--version-suffix", action="store", type=str)

args = parser.parse_args()

if not (args.stable_release or args.nightly_release):
parser.print_usage(sys.stderr)
sys.stderr.write("error: A release type is required\n")
sys.exit(1)

if args.stable_release and args.version_suffix:
sys.stderr.write("error: A version suffix is only supported for stable releases\n")
sys.exit(1)

THIS_DIR = Path(__file__).parent.resolve()
REPO_ROOT = THIS_DIR.parent.parent

Expand Down Expand Up @@ -75,12 +66,14 @@ def write_version_info():
COMMON_VERSION = SHORTFIN_BASE_VERSION

if args.nightly_release:
if args.version_suffix:
VERSION_SUFFIX = args.version_suffix
else:
VERSION_SUFFIX = "rc" + datetime.today().strftime("%Y%m%d")

COMMON_VERSION += VERSION_SUFFIX
COMMON_VERSION += "rc" + datetime.today().strftime("%Y%m%d")
elif args.development_release:
COMMON_VERSION += (
".dev0+"
+ subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip()
)
elif args.version_suffix:
COMMON_VERSION += args.version_suffix

if args.write_json:
version_local = {"package-version": COMMON_VERSION}
Expand Down
39 changes: 26 additions & 13 deletions build_tools/python_deploy/compute_local_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# This scripts grabs the X.Y.Z[.dev]` version identifier from a
# `version.json` and writes the corresponding
# `version.json` and writes a version identifier for a stable,
# nightly or development release, or a release with an arbitrary
# `X.Y.ZrcYYYYMMDD` version identifier to `version_local.json`.

import argparse
from pathlib import Path
import json
from datetime import datetime
import subprocess

from packaging.version import Version


parser = argparse.ArgumentParser()
parser.add_argument("path", type=Path)
parser.add_argument("--version-suffix", action="store", type=str)
parser.add_argument("--write-json", action="store_true")

release_type = parser.add_mutually_exclusive_group()
release_type.add_argument("-stable", "--stable-release", action="store_true") # default
release_type.add_argument("-rc", "--nightly-release", action="store_true")
release_type.add_argument("-dev", "--development-release", action="store_true")
release_type.add_argument("--version-suffix", action="store", type=str)

args = parser.parse_args()

VERSION_FILE = args.path / "version.json"
Expand All @@ -39,17 +48,21 @@ def write_version_info():

version_info = load_version_info()

if args.version_suffix:
VERSION_SUFFIX = args.version_suffix
else:
VERSION_SUFFIX = "rc" + datetime.today().strftime("%Y%m%d")

PACKAGE_VERSION = version_info.get("package-version")
PACKAGE_BASE_VERSION = Version(PACKAGE_VERSION).base_version
PACKAGE_LOCAL_VERSION = PACKAGE_BASE_VERSION + VERSION_SUFFIX

version_local = {"package-version": PACKAGE_LOCAL_VERSION}

write_version_info()
PACKAGE_LOCAL_VERSION = Version(PACKAGE_VERSION).base_version

if args.nightly_release:
PACKAGE_LOCAL_VERSION += "rc" + datetime.today().strftime("%Y%m%d")
elif args.development_release:
PACKAGE_LOCAL_VERSION += (
".dev0+"
+ subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip()
)
elif args.version_suffix:
PACKAGE_LOCAL_VERSION += args.version_suffix

if args.write_json:
version_local = {"package-version": PACKAGE_LOCAL_VERSION}
write_version_info()

print(PACKAGE_LOCAL_VERSION)

0 comments on commit ede04d1

Please sign in to comment.