-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend
build-commit
workflow to also work for ARM builds
- Loading branch information
Raunak Bhagat
committed
Dec 2, 2024
1 parent
b5f60e0
commit 29e0975
Showing
6 changed files
with
142 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
BUCKET_NAME = "github-actions-artifacts-bucket" | ||
WHEEL_SUFFIX = ".whl" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
Given a commit hash and a "platform substring", prints the wheelname of the wheel (if one exists) to stdout. | ||
# Example | ||
```bash | ||
COMMIT_HASH="abcdef0123456789" | ||
PLATFORM_SUBSTRING="x86" | ||
WHEELNAME=$(python get_wheel_name_from_s3.py $COMMIT_HASH $PLATFORM_SUBSTRING) | ||
echo $WHEELNAME | ||
# Will echo the wheelname if a wheel exists that matches the platform substring. | ||
# Otherwise, will echo nothing. | ||
``` | ||
""" | ||
|
||
import sys | ||
from pathlib import Path | ||
|
||
import boto3 | ||
import wheellib | ||
|
||
if __name__ == "__main__": | ||
commit_hash = sys.argv[1] | ||
platform_substring = sys.argv[2] | ||
|
||
s3 = boto3.client("s3") | ||
response = s3.list_objects_v2(Bucket="github-actions-artifacts-bucket", Prefix=f"builds/{commit_hash}/") | ||
matches = [] | ||
for content in response.get("Contents", []): | ||
wheelname = Path(content["Key"]).name | ||
platform_tag = wheellib.get_platform_tag(wheelname) | ||
if platform_substring in platform_tag: | ||
matches.append(wheelname) | ||
|
||
if len(matches) > 1: | ||
raise Exception( | ||
f"Multiple wheels found that match the given platform substring: {platform_substring}; expected just 1" | ||
) | ||
|
||
try: | ||
print(next(iter(matches))) | ||
except StopIteration: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import sys | ||
from pathlib import Path | ||
|
||
import boto3 | ||
import constants | ||
import wheellib | ||
|
||
if __name__ == "__main__": | ||
commit_hash = sys.argv[1] | ||
platform_substring = sys.argv[2] | ||
path_to_wheel_dir = Path(sys.argv[3]) | ||
|
||
assert path_to_wheel_dir.exists(), f"Path to wheel directory does not exist: {path_to_wheel_dir}" | ||
wheelpaths = iter(filepath for filepath in path_to_wheel_dir.iterdir() if filepath.suffix == constants.WHEEL_SUFFIX) | ||
|
||
def f(wheelpath: Path) -> bool: | ||
platform_tag = wheellib.get_platform_tag(wheelpath.name) | ||
return platform_substring in platform_tag | ||
|
||
filtered_wheelpaths: list[Path] = list(filter(f, wheelpaths)) | ||
|
||
length = len(filtered_wheelpaths) | ||
if length == 0: | ||
raise Exception(f"No wheels found that match the given platform substring: {platform_substring}; expected 1") | ||
elif length > 1: | ||
raise Exception( | ||
f"""Multiple wheels found that match the given platform substring: {platform_substring}; expected just 1 | ||
Wheels available: {wheelpaths}""" | ||
) | ||
[wheelpath] = filtered_wheelpaths | ||
s3 = boto3.client("s3") | ||
destination = Path("builds") / commit_hash / wheelpath.name | ||
s3.upload_file(wheelpath, constants.BUCKET_NAME, str(destination)) | ||
print(wheelpath.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from packaging.utils import parse_wheel_filename | ||
|
||
|
||
def get_platform_tag(wheelname: str) -> str: | ||
distribution, version, build_tag, tags = parse_wheel_filename(wheelname) | ||
assert len(tags) == 1, "Multiple tags found" | ||
return next(iter(tags)).platform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters