diff --git a/.github/workflows/build_packages.yml b/.github/workflows/build_packages.yml index 75f12b7fe..f9e902059 100644 --- a/.github/workflows/build_packages.yml +++ b/.github/workflows/build_packages.yml @@ -21,25 +21,31 @@ jobs: outputs: shark_package_version: ${{ steps.version.outputs.shark_package_version }} steps: - # For now the version is just a calendar date + an automatically - # incrementing value. We may want different versions for nightly/dev - # builds and stable releases published to official places like pypi. - - name: Compute version - id: version + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + submodules: false + - name: Setup Python + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.3 + with: + python-version: 3.12 + cache: "pip" + - name: Install Python packages + run: | + pip install packaging + pip freeze + - name: Generate release candidate versions + id: version_rc run: | - shark_package_version="$(printf '%(%Y%m%d)T.${{ github.run_number }}')" - echo "shark_package_version=${shark_package_version}" >> $GITHUB_OUTPUT - cat << EOF > ./version_info.json - { - "package-version": "${shark_package_version}" - } - EOF - cat ./version_info.json - - name: Upload version_info.json + sharktank_package_version=$(python3 build_tools/gen_version_info_rc.py sharktank) + shortfin_package_version=$(python3 build_tools/gen_version_info_rc.py shortfin) + - name: Upload version_info_rc.json uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: - name: version_info - path: version_info.json + name: version_info_rc + path: | + sharktank/version_info_rc.json + shortfin/version_info_rc.json build_packages: name: "${{ matrix.package }} :: ${{ matrix.platform }} :: ${{ matrix.python-version }}" @@ -74,11 +80,11 @@ jobs: path: "c" # Windows can hit path length limits, so use a short path. submodules: false - - name: Download version_info.json + - name: Download version_info_rc.json uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 with: - name: version_info - path: ./c/shortfin/ + name: version_info_rc + path: ./c/ merge-multiple: true - name: Build shortfin (Linux x86_64, ${{ matrix.python-version }}) diff --git a/build_tools/gen_version_info_rc.py b/build_tools/gen_version_info_rc.py new file mode 100644 index 000000000..9399053b0 --- /dev/null +++ b/build_tools/gen_version_info_rc.py @@ -0,0 +1,48 @@ +# Copyright 2024 Advanced Micro Devices, Inc. +# +# Licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# This scripts grabs the X.Y.Z[.dev]` version identifier from a +# `version_info.json` and writes the corresponding +# `X.Y.ZrcYYYYMMDD` version identifier to `version_rc_info.json`. + +import argparse +from pathlib import Path +import json +from datetime import datetime + +from packaging.version import Version + + +parser = argparse.ArgumentParser() +parser.add_argument("path", type=Path) +args = parser.parse_args() + +VERSION_INFO_FILE = args.path / "version_info.json" +VERSION_INFO_RC_FILE = args.path / "version_info_rc.json" + + +def load_version_info(): + with open(VERSION_INFO_FILE, "rt") as f: + return json.load(f) + + +def write_version_info(): + with open(VERSION_INFO_RC_FILE, "w") as f: + json.dump(version_info_rc, f, indent=2) + f.write("\n") + + +version_info = load_version_info() + +PACKAGE_VERSION = version_info.get("package-version") +PACKAGE_BASE_VERSION = Version(PACKAGE_VERSION).base_version +PACKAGE_RC_VERSION = PACKAGE_BASE_VERSION + "rc" + datetime.today().strftime("%Y%m%d") + +version_info_rc = {"package-version": PACKAGE_RC_VERSION} + +write_version_info() + +print(PACKAGE_RC_VERSION) diff --git a/sharktank/.gitignore b/sharktank/.gitignore new file mode 100644 index 000000000..000e575d5 --- /dev/null +++ b/sharktank/.gitignore @@ -0,0 +1,2 @@ +# Local-only config options +version_info_rc.json diff --git a/sharktank/setup.py b/sharktank/setup.py index 186e172ff..aca5c63d0 100644 --- a/sharktank/setup.py +++ b/sharktank/setup.py @@ -14,15 +14,22 @@ # Setup and get version information. VERSION_INFO_FILE = os.path.join(SETUPPY_DIR, "version_info.json") +VERSION_INFO_RC_FILE = os.path.join(SETUPPY_DIR, "version_info_rc.json") -def load_version_info(): - with open(VERSION_INFO_FILE, "rt") as f: +def load_version_info(version_file): + with open(version_file, "rt") as f: return json.load(f) -version_info = load_version_info() -PACKAGE_VERSION = version_info["package-version"] +try: + version_info = load_version_info(VERSION_INFO_RC_FILE) +except FileNotFoundError: + print("version_info_rc.json not found. Default to dev build") + version_info = load_version_info(VERSION_INFO_FILE) + +PACKAGE_VERSION = version_info.get("package-version") +print(f"Using PACKAGE_VERSION: '{PACKAGE_VERSION}'") setup( version=f"{PACKAGE_VERSION}", diff --git a/sharktank/version_info.json b/sharktank/version_info.json index 2d8f19afb..85afb41ed 100644 --- a/sharktank/version_info.json +++ b/sharktank/version_info.json @@ -1,3 +1,3 @@ { - "package-version": "0.1.dev3" + "package-version": "3.0.0.dev" } diff --git a/shortfin/.gitignore b/shortfin/.gitignore index 5469650d5..000e575d5 100644 --- a/shortfin/.gitignore +++ b/shortfin/.gitignore @@ -1,2 +1,2 @@ # Local-only config options -version_info.json +version_info_rc.json diff --git a/shortfin/setup.py b/shortfin/setup.py index 9ba5b6140..62ef77d58 100644 --- a/shortfin/setup.py +++ b/shortfin/setup.py @@ -141,36 +141,22 @@ def copy_extensions_to_source(self, *args, **kwargs): # Setup and get version information. -VERSION_INFO_FILE = os.path.join(SOURCE_DIR, "version_info.json") +VERSION_INFO_FILE = os.path.join(REL_SOURCE_DIR, "version_info.json") +VERSION_INFO_RC_FILE = os.path.join(REL_SOURCE_DIR, "version_info_rc.json") -def load_version_info(): - with open(VERSION_INFO_FILE, "rt") as f: +def load_version_info(version_file): + with open(version_file, "rt") as f: return json.load(f) -def find_git_version(): - try: - return ( - subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=SOURCE_DIR) - .decode("utf-8") - .strip() - ) - except subprocess.SubprocessError as e: - print(f"ERROR: Could not get git revision: {e}", file=sys.stderr) - return None - - try: - version_info = load_version_info() + version_info = load_version_info(VERSION_INFO_RC_FILE) except FileNotFoundError: - print("version_info.json not found. Using defaults", file=sys.stderr) - version_info = {} -git_version = find_git_version() + print("version_info_rc.json not found. Default to dev build") + version_info = load_version_info(VERSION_INFO_FILE) PACKAGE_VERSION = version_info.get("package-version") -if not PACKAGE_VERSION: - PACKAGE_VERSION = f"0.dev0+{git_version or '0'}" print(f"Using PACKAGE_VERSION: '{PACKAGE_VERSION}'") diff --git a/shortfin/version_info.json b/shortfin/version_info.json new file mode 100644 index 000000000..85afb41ed --- /dev/null +++ b/shortfin/version_info.json @@ -0,0 +1,3 @@ +{ + "package-version": "3.0.0.dev" +}