-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·144 lines (118 loc) · 4.23 KB
/
release.sh
File metadata and controls
executable file
·144 lines (118 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
cd "$ROOT_DIR"
REPO=commaai/dependencies
echo
echo "Publishing wheels to GitHub Releases ($REPO)"
shopt -s nullglob
for toml in */pyproject.toml; do
pkg="$(dirname "$toml")"
module="${pkg//-/_}"
version="$(python3 -c "import tomllib; print(tomllib.load(open('$toml', 'rb'))['project']['version'])")"
tag="${pkg}/v${version}"
wheels=("dist/${module}-${version}-"*.whl)
if [[ ${#wheels[@]} -eq 0 ]]; then
echo "missing wheel for $pkg ($module-$version) in dist" >&2
exit 1
fi
echo "[$pkg] Uploading ${#wheels[@]} wheel(s) to $tag"
gh release create "$tag" "${wheels[@]}" --repo "$REPO" --title "$pkg v$version" --notes "Platform wheels for $pkg $version" 2>/dev/null ||
gh release upload "$tag" "${wheels[@]}" --repo "$REPO" --clobber
done
shopt -u nullglob
TOKEN="$(gh auth token 2>/dev/null)" || { echo "set GH_TOKEN to publish shim branches" >&2; exit 1; }
TMP_DIR="$(mktemp -d)"
python3 - "$TMP_DIR" "$REPO" <<'PY'
import json
import pathlib
import shutil
import tomllib
import sys
tmp_dir = pathlib.Path(sys.argv[1])
repo = sys.argv[2]
repo_url = f"https://github.com/{repo}"
shim_setup = pathlib.Path("_shim_setup.py")
for toml in sorted(pathlib.Path(".").glob("*/pyproject.toml")):
pkg = toml.parent.name
module = pkg.replace("-", "_")
data = tomllib.load(toml.open("rb"))
version = str(data["project"]["version"])
tag = f"{pkg}/v{version}"
description = data["project"]["description"]
patterns = data.get("tool", {}).get("setuptools", {}).get("package-data", {}).get(module, [""])
datadir = patterns[0].split("/", 1)[0] if patterns and patterns[0] else ""
scripts = data.get("project", {}).get("scripts", {}) or {}
repo_dir = tmp_dir / pkg
pkg_dir = repo_dir / pkg
mod_dir = pkg_dir / module
mod_dir.mkdir(parents=True, exist_ok=True)
# copy all .py files from the main module
src_mod = pathlib.Path(pkg) / module
for py_file in src_mod.glob("*.py"):
shutil.copy2(py_file, mod_dir / py_file.name)
# copy extra packages (e.g. pyray for raylib)
pkgs_val = data.get("tool", {}).get("setuptools", {}).get("packages", {})
include_patterns = pkgs_val.get("find", {}).get("include", []) if isinstance(pkgs_val, dict) else []
extra_packages = []
for pattern in include_patterns:
p = pattern.rstrip("*")
if p and p != module and p != f"{module}/":
src_extra = pathlib.Path(pkg) / p
if src_extra.is_dir():
dst_extra = pkg_dir / p
shutil.copytree(src_extra, dst_extra, dirs_exist_ok=True)
extra_packages.append(pattern)
shutil.copy2(shim_setup, pkg_dir / "setup.py")
deps = data.get("project", {}).get("dependencies", [])
lines = [
"[build-system]",
'requires = ["setuptools>=64", "wheel", \'tomli; python_version < \"3.11\"\']',
'build-backend = "setuptools.build_meta"',
"",
"[project]",
f'name = "{pkg}"',
f'version = "{version}"',
f"description = {json.dumps(description + ' (pre-built)')}",
'requires-python = ">=3.8"',
]
if deps:
lines.append(f"dependencies = {json.dumps(deps)}")
if scripts:
lines += ["", "[project.scripts]"]
for name, target in scripts.items():
lines.append(f'"{name}" = {json.dumps(target)}')
find_include = [f"{module}*"] + extra_packages
lines += [
"",
"[tool.setuptools.packages.find]",
f"include = {json.dumps(find_include)}",
"",
"[tool.setuptools.package-data]",
f'{module} = ["{datadir}/**/*", "*.so"]',
"",
"[tool.shim]",
f'repo_url = "{repo_url}"',
f'tag = "{tag}"',
f'datadir = "{datadir}"',
]
(pkg_dir / "pyproject.toml").write_text("\n".join(lines) + "\n")
PY
shopt -s nullglob
for repo_dir in "$TMP_DIR"/*; do
[[ -d "$repo_dir" ]] || continue
pkg="$(basename "$repo_dir")"
branch="release-$pkg"
echo "[$pkg] Publishing shim branch $branch"
(
cd "$repo_dir"
git init
git checkout -b "$branch"
git add "$pkg"
git -c user.name="github-actions[bot]" -c user.email="github-actions[bot]@users.noreply.github.com" commit -m "update $pkg shim"
git remote add origin "https://x-access-token:${TOKEN}@github.com/${REPO}.git"
git push -f origin "$branch"
)
done
shopt -u nullglob
rm -rf "$TMP_DIR"