Skip to content

Commit a1361f4

Browse files
committed
Add build_packages.yml action and populate package version.
1 parent 9223811 commit a1361f4

File tree

3 files changed

+151
-6
lines changed

3 files changed

+151
-6
lines changed

.github/workflows/build_packages.yml

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Copyright 2024 Advanced Micro Devices, Inc.
2+
#
3+
# Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
name: Build packages
8+
9+
on:
10+
workflow_dispatch:
11+
schedule:
12+
# Runs at 11:00 AM UTC, which is 3:00 AM PST (UTC-8)
13+
- cron: '0 11 * * *'
14+
15+
jobs:
16+
# Note: metadata generation could happen in a separate trigger/schedule
17+
# workflow. For cross platform builds, it's useful to just generate the
18+
# metadata on Linux and pass that to later jobs using artifacts.
19+
setup_metadata:
20+
runs-on: ubuntu-24.04
21+
outputs:
22+
shark_package_version: ${{ steps.version.outputs.shark_package_version }}
23+
steps:
24+
# For now the version is just a calendar date + an automatically
25+
# incrementing value. We may want different versions for nightly/dev
26+
# builds and stable releases published to official places like pypi.
27+
- name: Compute version
28+
id: version
29+
run: |
30+
shark_package_version="$(printf '%(%Y%m%d)T.${{ github.run_number }}')"
31+
echo "shark_package_version=${shark_package_version}" >> $GITHUB_OUTPUT
32+
cat << EOF > ./version_info.json
33+
{
34+
"package-version": "${shark_package_version}"
35+
}
36+
EOF
37+
cat ./version_info.json
38+
- name: Upload version_info.json
39+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
40+
with:
41+
name: version_info
42+
path: version_info.json
43+
44+
build_packages:
45+
name: "${{ matrix.package }} :: ${{ matrix.platform }} :: ${{ matrix.python-version }}"
46+
runs-on: ${{ matrix.runs-on }}
47+
needs: [setup_metadata]
48+
strategy:
49+
fail-fast: false
50+
matrix:
51+
include:
52+
# Ubuntu packages.
53+
- runs-on: ubuntu-24.04
54+
platform: linux-x86_64
55+
package: shortfin
56+
python-version: cp312-cp312
57+
- runs-on: ubuntu-24.04
58+
platform: linux-x86_64
59+
package: shortfin
60+
python-version: cp313-cp313
61+
62+
# TODO(#130): macOS platform
63+
# TODO(#130): Windows platform
64+
# TODO(#130): sharktank packages
65+
# TODO(#130): free-threaded python
66+
67+
steps:
68+
- name: Checkout repository
69+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
70+
with:
71+
path: "c" # Windows can hit path length limits, so use a short path.
72+
submodules: false
73+
74+
- name: Download version_info.json
75+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
76+
with:
77+
name: version_info
78+
path: ./c/shortfin/
79+
merge-multiple: true
80+
81+
- name: Build shortfin (Linux x86_64, ${{ matrix.python-version }})
82+
if: "matrix.package == 'shortfin' && matrix.platform == 'linux-x86_64'"
83+
env:
84+
OUTPUT_DIR: "${{ github.workspace }}/bindist"
85+
OVERRIDE_PYTHON_VERSIONS: "${{ matrix.python-version }}"
86+
run: |
87+
[ -e ./bindist/* ] && rm ./bindist/*
88+
./c/shortfin/build_tools/build_linux_package.sh
89+
90+
- name: Upload python wheels
91+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
92+
with:
93+
if-no-files-found: error
94+
name: snapshot-${{ matrix.package }}-${{ matrix.platform }}-${{ matrix.python-version }}
95+
path: bindist
96+
97+
- name: Release python wheels
98+
uses: ncipollo/[email protected]
99+
with:
100+
artifacts: bindist/*.whl
101+
token: "${{ secrets.GITHUB_TOKEN }}"
102+
tag: "dev-wheels"
103+
name: "dev-wheels"
104+
body: "Automatic snapshot release of SHARK-Platform python wheels."
105+
removeArtifacts: false
106+
allowUpdates: true
107+
replacesArtifacts: true
108+
makeLatest: false

shortfin/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Local-only config options
2+
version_info.json

shortfin/setup.py

+41-6
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:
@@ -133,6 +134,40 @@ def copy_extensions_to_source(self, *args, **kwargs):
133134
...
134135

135136

137+
# Setup and get version information.
138+
VERSION_INFO_FILE = os.path.join(SOURCE_DIR, "version_info.json")
139+
140+
141+
def load_version_info():
142+
with open(VERSION_INFO_FILE, "rt") as f:
143+
return json.load(f)
144+
145+
146+
def find_git_version():
147+
try:
148+
return (
149+
subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=SOURCE_DIR)
150+
.decode("utf-8")
151+
.strip()
152+
)
153+
except subprocess.SubprocessError as e:
154+
print(f"ERROR: Could not get git revision: {e}", file=sys.stderr)
155+
return None
156+
157+
158+
try:
159+
version_info = load_version_info()
160+
except FileNotFoundError:
161+
print("version_info.json not found. Using defaults", file=sys.stderr)
162+
version_info = {}
163+
git_version = find_git_version()
164+
165+
PACKAGE_VERSION = version_info.get("package-version")
166+
if not PACKAGE_VERSION:
167+
PACKAGE_VERSION = f"0.dev0+{git_version or '0'}"
168+
print(f"Using PACKAGE_VERSION: '{PACKAGE_VERSION}'")
169+
170+
136171
def maybe_nuke_cmake_cache(cmake_build_dir):
137172
# From run to run under pip, we can end up with different paths to ninja,
138173
# which isn't great and will confuse cmake. Detect if the location of
@@ -324,7 +359,7 @@ def populate_built_package(abs_dir):
324359

325360
setup(
326361
name="shortfin",
327-
version="0.9",
362+
version=f"{PACKAGE_VERSION}",
328363
description="Shortfin native library implementation",
329364
author="SHARK Authors",
330365
packages=packages,

0 commit comments

Comments
 (0)