Skip to content

Commit 1076e2d

Browse files
committed
try upload llvm binary
1 parent 17dd948 commit 1076e2d

File tree

5 files changed

+144
-28
lines changed

5 files changed

+144
-28
lines changed

.github/workflows/build-llvm.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ name: build llvm
22

33
on:
44
pull_request:
5-
branches: [main]
5+
# if you want to run this workflow, change the branch name to main,
6+
# if you want to turn off it, change it to non existent branch.
7+
branches: [main-turn-off]
68
paths:
79
- ".github/workflows/llvm.yml"
810
- "cmake/build-llvm.cmake"

.github/workflows/upload-llvm.yml

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,15 @@ jobs:
1919
upload:
2020
runs-on: ubuntu-24.04
2121
steps:
22+
- uses: actions/checkout@v4
23+
2224
- name: Download artifacts from workflow
2325
env:
2426
GH_TOKEN: ${{ github.token }}
25-
run: |
26-
mkdir -p artifacts
27-
gh run download "${{ inputs.workflow_id }}" --dir artifacts
28-
echo "Downloaded artifacts:"
29-
find artifacts -maxdepth 4 -type f -print
27+
run: scripts/download-llvm.sh "${{ inputs.workflow_id }}"
3028

3129
- name: Recreate release with artifacts
3230
env:
3331
GH_TOKEN: ${{ secrets.LLVM_UPLOAD }}
3432
TARGET_REPO: clice-io/clice-llvm
35-
run: |
36-
set -euo pipefail
37-
TAG="${{ inputs.version }}"
38-
REPO="${TARGET_REPO}"
39-
40-
if gh release view "${TAG}" --repo "${REPO}" >/dev/null 2>&1; then
41-
echo "Deleting existing release ${TAG} in ${REPO}..."
42-
gh release delete "${TAG}" --repo "${REPO}" -y
43-
fi
44-
45-
mapfile -d '' ASSETS < <(find artifacts -type f -print0)
46-
if [[ ${#ASSETS[@]} -eq 0 ]]; then
47-
echo "No artifacts found to upload." >&2
48-
exit 1
49-
fi
50-
51-
echo "Creating release ${TAG} in ${REPO} with ${#ASSETS[@]} assets..."
52-
gh release create "${TAG}" "${ASSETS[@]}" \
53-
--repo "${REPO}" \
54-
--title "${TAG}" \
55-
--notes "Artifacts from workflow run ${{ inputs.workflow_id }}" \
56-
--latest
33+
run: python3 scripts/upload-llvm.py "${{ inputs.version }}" "${TARGET_REPO}" "${{ inputs.workflow_id }}"

pixi.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ authors = ["ykiko <ykikoykikoykiko@gmail.com>"]
66

77
license = "Apache-2.0"
88
license-file = "LICENSE"
9+
readme = "README"
10+
documentation = "https://clice.io"
11+
repository = "https://github.com/clice-io/clice"
912

1013
channels = ["conda-forge"]
1114
platforms = ["win-64", "linux-64", "osx-arm64"]

scripts/download-llvm.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if [[ $# -ne 1 ]]; then
6+
echo "Usage: $0 <workflow_id>" >&2
7+
exit 1
8+
fi
9+
10+
WORKFLOW_ID="$1"
11+
12+
mkdir -p artifacts
13+
gh run download "${WORKFLOW_ID}" --dir artifacts
14+
15+
echo "Downloaded artifacts:"
16+
find artifacts -maxdepth 4 -type f -print

scripts/upload-llvm.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env python3
2+
3+
import hashlib
4+
import json
5+
import os
6+
import subprocess
7+
import sys
8+
from pathlib import Path
9+
10+
11+
def sha256sum(path: Path) -> str:
12+
digest = hashlib.sha256()
13+
with path.open("rb") as handle:
14+
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
15+
digest.update(chunk)
16+
return digest.hexdigest()
17+
18+
19+
def parse_platform(name: str) -> str:
20+
lowered = name.lower()
21+
if "windows" in lowered:
22+
return "windows"
23+
if "linux" in lowered:
24+
return "linux"
25+
if "macos" in lowered:
26+
return "macosx"
27+
raise ValueError(f"Unable to determine platform from filename: {name}")
28+
29+
30+
def parse_build_type(name: str) -> str:
31+
lowered = name.lower()
32+
if "debug" in lowered:
33+
return "Debug"
34+
return "RelWithDebInfo"
35+
36+
37+
def build_metadata_entry(path: Path, version: str) -> dict:
38+
filename = path.name
39+
return {
40+
"platform": parse_platform(filename),
41+
"build_type": parse_build_type(filename),
42+
"is_lto": "-lto" in filename.lower(),
43+
"filename": filename,
44+
"version": version,
45+
"sha256": sha256sum(path),
46+
}
47+
48+
49+
def main() -> None:
50+
if len(sys.argv) != 4:
51+
print(
52+
"Usage: upload-llvm.py <tag> <target_repo> <workflow_id>", file=sys.stderr
53+
)
54+
sys.exit(1)
55+
56+
tag, target_repo, workflow_id = sys.argv[1:]
57+
artifacts_dir = Path("artifacts")
58+
59+
if not artifacts_dir.is_dir():
60+
print(f"Artifacts directory not found: {artifacts_dir}", file=sys.stderr)
61+
sys.exit(1)
62+
63+
artifact_files = sorted(
64+
p
65+
for p in artifacts_dir.rglob("*")
66+
if p.is_file() and p.suffix.lower() != ".json"
67+
)
68+
69+
if not artifact_files:
70+
print("No artifacts found to upload.", file=sys.stderr)
71+
sys.exit(1)
72+
73+
version_without_prefix = tag.lstrip("vV")
74+
metadata = [
75+
build_metadata_entry(path, version_without_prefix) for path in artifact_files
76+
]
77+
78+
json_path = artifacts_dir / "prebuilt-llvm.json"
79+
with json_path.open("w", encoding="utf-8") as handle:
80+
json.dump(metadata, handle, indent=2)
81+
handle.write("\n")
82+
83+
assets = [str(path) for path in artifact_files]
84+
assets.append(str(json_path))
85+
86+
env = os.environ.copy()
87+
88+
print(f"Checking for existing release {tag} in {target_repo}...")
89+
view_result = subprocess.run(
90+
["gh", "release", "view", tag, "--repo", target_repo],
91+
env=env,
92+
stdout=subprocess.DEVNULL,
93+
stderr=subprocess.DEVNULL,
94+
)
95+
96+
if view_result.returncode == 0:
97+
print(f"Deleting existing release {tag} in {target_repo}...")
98+
subprocess.run(
99+
["gh", "release", "delete", tag, "--repo", target_repo, "-y"],
100+
env=env,
101+
check=True,
102+
)
103+
104+
print(f"Creating release {tag} in {target_repo} with {len(assets)} assets...")
105+
# fmt: off
106+
args = [
107+
"gh", "release", "create", tag, *assets,
108+
"--repo", target_repo,
109+
"--title", tag,
110+
"--notes", f"Artifacts from workflow run {workflow_id}",
111+
"--latest",
112+
]
113+
# fmt: on
114+
subprocess.run(args, env=env, check=True)
115+
116+
117+
if __name__ == "__main__":
118+
main()

0 commit comments

Comments
 (0)