Skip to content

Commit 03d8051

Browse files
committed
improve built repository action to be usable from filesystem directly
1 parent 3643569 commit 03d8051

File tree

3 files changed

+72
-18
lines changed

3 files changed

+72
-18
lines changed

.github/workflows/build-repository.yml

+33-11
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,54 @@ jobs:
44
build-repo:
55
runs-on: ubuntu-latest
66
steps:
7+
- name: Checkout
8+
uses: actions/checkout@v4
79
- name: Download artifacts for linux-amd64
8-
uses: dawidd6/action-download-artifact@v2
10+
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e
11+
continue-on-error: true
912
with:
10-
workflow: build-linux-amd64-wheels
13+
workflow: build-linux-amd64-wheels.yml
14+
workflow_conclusion: ''
15+
if_no_artifact_found: warn
16+
allow_forks: 'false'
1117
- name: Download artifacts for linux-aarch64
12-
uses: dawidd6/action-download-artifact@v2
18+
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e
19+
continue-on-error: true
1320
with:
14-
workflow: build-linux-aarch64-wheels
21+
workflow: build-linux-aarch64-wheels.yml
22+
workflow_conclusion: ''
23+
if_no_artifact_found: warn
24+
allow_forks: 'false'
1525
- name: Download artifacts for macos-amd64
16-
uses: dawidd6/action-download-artifact@v2
26+
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e
27+
continue-on-error: true
1728
with:
18-
workflow: build-macos-amd64-wheels
29+
workflow: build-macos-amd64-wheels.yml
30+
workflow_conclusion: ''
31+
if_no_artifact_found: warn
32+
allow_forks: 'false'
1933
- name: Download artifacts for macos-aarch64
20-
uses: dawidd6/action-download-artifact@v2
34+
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e
35+
continue-on-error: true
2136
with:
22-
workflow: build-macos-aarch64-wheels
37+
workflow: build-macos-aarch64-wheels.yml
38+
workflow_conclusion: ''
39+
if_no_artifact_found: warn
40+
allow_forks: 'false'
2341
- name: Download artifacts for windows-amd64
24-
uses: dawidd6/action-download-artifact@v2
42+
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e
43+
continue-on-error: true
2544
with:
26-
workflow: build-windows-amd64-wheels
45+
workflow: build-windows-amd64-wheels.yml
46+
workflow_conclusion: ''
47+
if_no_artifact_found: warn
48+
allow_forks: 'false'
2749
- name: Set up Python
2850
uses: actions/setup-python@v4
2951
with:
3052
python-version: '3.10'
3153
- name: Create repository
32-
run: python ${GITHUB_WORKSPACE}/generate_repository.py
54+
run: python ${GITHUB_WORKSPACE}/scripts/wheelbuilder/generate_repository.py
3355
- name: Store repository
3456
uses: umutozd/upload-artifact@5c459179e7745e2c730c50b10a6459da0b6f25db
3557
with:

scripts/wheelbuilder/generate_repository.py

+26-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import re
4949
import shutil
5050
import sys
51+
import html
5152

5253

5354
def normalize(name):
@@ -67,28 +68,49 @@ def normalize(name):
6768
wheels = glob.glob(os.path.join(workspace, "**/*.whl")) or glob.glob(
6869
os.path.join(workspace, "**/**/*.whl.gz__")
6970
)
70-
repo = os.path.join(workspace, "repository")
71+
repo = os.path.join(workspace, "repository", "simple")
7172
os.makedirs(repo, exist_ok=True)
73+
pkg_index = [
74+
"<html><head><title>Simple Index</title>",
75+
"<meta name='api-version' value='2' /></head><body>",
76+
]
77+
processed_wheels = set()
7278
for wheel in wheels:
7379
print("Processing", wheel)
74-
parts = os.path.basename(wheel).split("-")
80+
basename = os.path.basename(wheel)
81+
parts = basename.split("-")
7582
for idx, part in enumerate(parts):
76-
if part.startswith("graalpy3") or part.startswith("py3"):
83+
if part.startswith("graalpy3") or part.startswith("py2") or part.startswith("py3"):
7784
version_idx = idx - 1
7885
break
86+
else:
87+
continue
7988
wheel_name = normalize("-".join(parts[:version_idx]))
8089
target_dir = os.path.join(repo, wheel_name)
8190
os.makedirs(target_dir, exist_ok=True)
8291
if wheel.endswith(".gz__"):
8392
with gzip.open(wheel, "rb") as f_in:
8493
with open(
8594
os.path.join(
86-
target_dir, os.path.basename(wheel).replace(".gz__", "")
95+
target_dir, basename.replace(".gz__", "")
8796
),
8897
"wb",
8998
) as f_out:
9099
shutil.copyfileobj(f_in, f_out)
91100
else:
92101
shutil.copy(wheel, target_dir)
93102

103+
if wheel_name not in processed_wheels:
104+
processed_wheels.add(wheel_name)
105+
wheel_name = html.escape(wheel_name)
106+
pkg_index.append(f"<a href='{wheel_name}/'>{wheel_name}</a><br />")
107+
108+
with open(os.path.join(target_dir, "index.html"), "a") as f:
109+
basename = html.escape(basename)
110+
f.write(f"<a href='{basename}'>{basename}</a><br />\n")
111+
112+
pkg_index.append("</body></html>")
113+
with open(os.path.join(repo, "index.html"), "w") as f:
114+
f.write("\n".join(pkg_index))
115+
94116
shutil.make_archive(f"{workspace}/repository", "zip", repo)

scripts/wheelbuilder/wheelbuilder/generator.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,21 @@ def generate(workflow_directory):
117117
"build-repo": {
118118
"runs-on": "ubuntu-latest",
119119
"steps": [
120+
{
121+
"name": "Checkout",
122+
"uses": "actions/checkout@v4",
123+
},
124+
]
125+
+ [
120126
{
121127
"name": f"Download artifacts for {p.name}-{p.arch}",
122-
"uses": "dawidd6/action-download-artifact@v2",
128+
"uses": "dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e",
129+
"continue-on-error": True,
123130
"with": {
124-
"workflow": f"build-{p.name}-{p.arch}-wheels",
131+
"workflow": f"build-{p.name}-{p.arch}-wheels.yml",
132+
"workflow_conclusion": "",
133+
"if_no_artifact_found": "warn",
134+
"allow_forks": "false",
125135
},
126136
}
127137
for p in PLATFORMS
@@ -136,7 +146,7 @@ def generate(workflow_directory):
136146
},
137147
{
138148
"name": "Create repository",
139-
"run": "python ${GITHUB_WORKSPACE}/generate_repository.py",
149+
"run": "python ${GITHUB_WORKSPACE}/scripts/wheelbuilder/generate_repository.py",
140150
},
141151
{
142152
"name": "Store repository",

0 commit comments

Comments
 (0)