Skip to content

Commit faafe2e

Browse files
authored
Merge pull request #11 from antmicro/handle-multiple-links
stdm: add possibility to get multiple urls for a single build
2 parents 43d0535 + 8956b36 commit faafe2e

File tree

4 files changed

+52
-18
lines changed

4 files changed

+52
-18
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v2
1616
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v1
17+
uses: actions/setup-python@v2
1818
with:
1919
python-version: ${{ matrix.python-version }}
2020
- name: Display Python version

bin/symbiflow_get_latest_artifact_url

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
#
1010
# SPDX-License-Identifier: ISC
1111

12-
from stpm import get_latest_artifact_url
12+
from stdm import get_latest_artifact_url
1313

1414
print(get_latest_artifact_url())

stdm/__init__.py

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616

1717
# For now we use only `symbiflow-arch-defs` and download tarballs
1818
def get_latest_artifact_url(
19-
project="symbiflow-arch-defs",
20-
build_name="install",
21-
jobset="continuous",
22-
get_max_int=False,
19+
project="symbiflow-arch-defs", build_name="install", jobset="continuous"
2320
):
2421
# Handle case in which there is build_name is absent
2522
if build_name:
@@ -50,7 +47,13 @@ def get_latest_artifact_url(
5047

5148
for obj in items:
5249
obj_int = int(obj["id"].replace(to_strip, "").split("/")[0])
53-
urls_of_integers[obj_int] = obj["mediaLink"]
50+
if obj_int not in urls_of_integers:
51+
urls_of_integers[obj_int] = list()
52+
53+
artifact_name = obj["selfLink"].split("%2F")[-1]
54+
artifact_link = obj["mediaLink"]
55+
artifact = {"name": artifact_name, "url": obj["mediaLink"]}
56+
urls_of_integers[obj_int].append(artifact)
5457

5558
try:
5659
params["pageToken"] = r.json()["nextPageToken"]
@@ -63,10 +66,7 @@ def get_latest_artifact_url(
6366
print(e)
6467
return ""
6568

66-
if get_max_int:
67-
return urls_of_integers[max_int], max_int
68-
else:
69-
return urls_of_integers[max_int]
69+
return urls_of_integers[max_int], max_int
7070

7171

7272
def main():
@@ -90,18 +90,44 @@ def main():
9090
help="Name of the jobset. Can choose between presubmit and continous",
9191
)
9292
parser.add_argument(
93-
"--get_max_int",
93+
"--get_build_number",
94+
action="store_true",
95+
help="Retrieve the CI build number",
96+
)
97+
parser.add_argument(
98+
"--get_single_url",
9499
action="store_true",
95-
help="Retrieve also the CI build number",
100+
help="Retrieve a single random URL from a given build",
101+
)
102+
parser.add_argument(
103+
"--get_all_urls",
104+
action="store_true",
105+
help="Retrieve all the URLs of a given build",
96106
)
97107

98108
args = parser.parse_args()
99109

100-
print(
101-
get_latest_artifact_url(
102-
args.project, args.build_name, args.jobset, args.get_max_int
110+
# Default to use get_single_url if none of the options is selected
111+
if not (args.get_all_urls or args.get_single_url or args.get_build_number):
112+
args.get_single_url = True
113+
114+
if args.get_build_number:
115+
assert not (args.get_all_urls or args.get_single_url)
116+
_, build_number = get_latest_artifact_url(
117+
args.project, args.build_name, args.jobset
103118
)
104-
)
119+
print(build_number)
120+
121+
elif args.get_all_urls:
122+
assert not (args.get_build_number or args.get_single_url)
123+
urls, _ = get_latest_artifact_url(args.project, args.build_name, args.jobset)
124+
for url in urls:
125+
print(url)
126+
127+
elif args.get_single_url:
128+
assert not (args.get_build_number or args.get_all_urls)
129+
urls, _ = get_latest_artifact_url(args.project, args.build_name, args.jobset)
130+
print(urls[0]["url"])
105131

106132

107133
if __name__ == "__main__":

tests/test_get_symbiflow_arch_defs_tarball.py renamed to tests/test_stdm.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,24 @@
1010
# SPDX-License-Identifier: ISC
1111

1212
import pytest
13+
import argparse
14+
15+
parser = argparse.ArgumentParser(
16+
description="Retrieves the latest artifacts of SymbiFlow-related CIs."
17+
)
1318

1419

1520
def test_get_symbiflow_arch_defs_tarball():
1621
from stdm import get_latest_artifact_url
1722
import requests
1823
import filetype
1924

20-
url = get_latest_artifact_url("symbiflow-arch-defs", "install")
25+
urls, build_number = get_latest_artifact_url("symbiflow-arch-defs", "install")
2126

27+
url = urls[0]["url"]
2228
response = requests.get(url)
2329
ext = filetype.guess_extension(response.content)
2430

2531
assert "xz" is ext
32+
assert urls[0]["name"].endswith("tar.xz")
33+
assert isinstance(build_number, int)

0 commit comments

Comments
 (0)