Skip to content

Commit 04f68d6

Browse files
committed
Set rolling package version based on date and github run number.
1 parent f8f0f83 commit 04f68d6

File tree

2 files changed

+76
-14
lines changed

2 files changed

+76
-14
lines changed

.github/workflows/build_packages.yml

+33-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,32 @@ on:
1313
- cron: '0 11 * * *'
1414

1515
jobs:
16+
setup_metadata:
17+
runs-on: ubuntu-24.04
18+
outputs:
19+
shark_package_version: ${{ steps.version.outputs.shark_package_version }}
20+
steps:
21+
- name: Compute version
22+
id: version
23+
run: |
24+
shark_package_version="$(printf '%(%Y%m%d)T.${{ github.run_number }}')"
25+
echo "shark_package_version=${shark_package_version}" >> $GITHUB_OUTPUT
26+
cat << EOF > ./version_info.json
27+
{
28+
"package-version": "${shark_package_version}",
29+
}
30+
EOF
31+
cat ./version_info.json
32+
- name: Upload version_info.json
33+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
34+
with:
35+
name: version_info.json
36+
path: version_info.json
37+
1638
build_packages:
17-
name: "${{ matrix.build-family }} :: ${{ matrix.package }} :: ${{ matrix.python-version }}"
39+
name: "${{ matrix.package }} :: ${{ matrix.build-family }} :: ${{ matrix.python-version }}"
1840
runs-on: ${{ matrix.runs-on }}
41+
needs: [setup_metadata]
1942
strategy:
2043
fail-fast: false
2144
matrix:
@@ -29,7 +52,9 @@ jobs:
2952
build-family: linux-x86_64
3053
package: shortfin
3154
python-version: cp313-cp313
55+
3256
# TODO(#130): macOS
57+
3358
# TODO(#130): Windows
3459

3560
steps:
@@ -39,10 +64,14 @@ jobs:
3964
path: "c" # Windows can hit path length limits, so use a short path.
4065
submodules: false
4166

67+
- name: Download version_info.json
68+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
69+
with:
70+
name: version_info.json
71+
path: version_info.json
4272

4373
- name: Build shortfin (Linux x86_64, ${{ matrix.python-version }})
4474
if: "matrix.package == 'shortfin' && matrix.build-family == 'linux-x86_64'"
45-
shell: bash
4675
env:
4776
OUTPUT_DIR: "${{ github.workspace }}/bindist"
4877
OVERRIDE_PYTHON_VERSIONS: "${{ matrix.python-version }}"
@@ -51,7 +80,7 @@ jobs:
5180
./c/shortfin/build_tools/build_linux_package.sh
5281
5382
- name: Upload python wheels
54-
uses: actions/upload-artifact@v4
83+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
5584
with:
5685
if-no-files-found: error
5786
name: snapshot-${{ matrix.package }}-${{ matrix.build-family }}-${{ matrix.python-version }}
@@ -68,4 +97,4 @@ jobs:
6897
removeArtifacts: false
6998
allowUpdates: true
7099
replacesArtifacts: true
71-
makeLatest: true
100+
makeLatest: false

shortfin/setup.py

+43-10
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
from distutils.core import setup, Extension
8-
import sys
7+
import json
8+
import os
99
import shutil
1010
import subprocess
11-
import os
12-
from pathlib import Path
11+
import sys
1312
from distutils.command.build import build as _build
13+
from distutils.core import setup, Extension
14+
from pathlib import Path
1415
from setuptools import find_namespace_packages
15-
from setuptools.command.build_ext import build_ext as _build_ext
1616
from setuptools.command.build_py import build_py as _build_py
17+
from setuptools.command.build_ext import build_ext as _build_ext
1718

1819

1920
def get_env_boolean(name: str, default_value: bool = False) -> bool:
@@ -126,11 +127,43 @@ def run(self):
126127

127128

128129
class NoopBuildExtension(_build_ext):
129-
def build_extension(self, ext):
130-
...
130+
def build_extension(self, ext): ...
131+
132+
def copy_extensions_to_source(self, *args, **kwargs): ...
133+
134+
135+
# Setup and get version information.
136+
VERSION_INFO_FILE = os.path.join(SOURCE_DIR, "version_info.json")
137+
138+
139+
def load_version_info():
140+
with open(VERSION_INFO_FILE, "rt") as f:
141+
return json.load(f)
142+
143+
144+
def find_git_version():
145+
try:
146+
return (
147+
subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=SOURCE_DIR)
148+
.decode("utf-8")
149+
.strip()
150+
)
151+
except subprocess.SubprocessError as e:
152+
print(f"ERROR: Could not get git revision: {e}", file=sys.stderr)
153+
return None
154+
155+
156+
try:
157+
version_info = load_version_info()
158+
except FileNotFoundError:
159+
print("version_info.json not found. Using defaults", file=sys.stderr)
160+
version_info = {}
161+
git_version = find_git_version()
131162

132-
def copy_extensions_to_source(self, *args, **kwargs):
133-
...
163+
PACKAGE_SUFFIX = version_info.get("package-suffix") or ""
164+
PACKAGE_VERSION = version_info.get("package-version")
165+
if not PACKAGE_VERSION:
166+
PACKAGE_VERSION = f"0.dev0+{git_version or '0'}"
134167

135168

136169
def maybe_nuke_cmake_cache(cmake_build_dir):
@@ -324,7 +357,7 @@ def populate_built_package(abs_dir):
324357

325358
setup(
326359
name="shortfin",
327-
version="0.9",
360+
version=f"{PACKAGE_VERSION}",
328361
description="Shortfin native library implementation",
329362
author="SHARK Authors",
330363
packages=packages,

0 commit comments

Comments
 (0)