-
Notifications
You must be signed in to change notification settings - Fork 7
145 lines (122 loc) · 4.45 KB
/
Copy pathbuild-wheel.yml
File metadata and controls
145 lines (122 loc) · 4.45 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
145
name: Build Wheel
on:
push:
branches:
- main
paths:
- ".github/actions/**"
- ".github/workflows/build-wheel.yml"
- "native/**"
- "pixi.lock"
- "pixi.toml"
- "python/**"
- "scripts/build.sh"
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
build-wheel:
if: github.repository == 'intelligent-control-lab/BrickSim'
name: cp311_amd64_linux
runs-on: ubuntu-22.04
env:
CLOUDSMITH_NAMESPACE: bricksim
CLOUDSMITH_REPOSITORY: bricksim
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Free disk space
uses: ./.github/actions/free-disk-space
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install pixi
uses: prefix-dev/setup-pixi@v0.9.3
with:
pixi-version: v0.67.0
cache: true
frozen: true
activate-environment: true
- name: Cache BrickSim artifacts
uses: ./.github/actions/cache-bricksim-artifacts
- name: Build native extension
run: pixi run build-native
- name: Compute wheel version
id: version
run: |
base_version=$(
python - <<'PY'
from pathlib import Path
import tomllib
data = tomllib.loads(Path("python/pyproject.toml").read_text())
print(data["project"]["version"])
PY
)
sequence=$(git rev-list --count --first-parent HEAD)
short_sha=$(git rev-parse --short HEAD)
wheel_version="${base_version}.dev${sequence}+g${short_sha}"
echo "wheel_version=$wheel_version" >> "$GITHUB_OUTPUT"
- name: Apply wheel version
env:
WHEEL_VERSION: ${{ steps.version.outputs.wheel_version }}
run: |
python - <<'PY'
import os
import re
from pathlib import Path
path = Path("python/pyproject.toml")
lines = path.read_text().splitlines()
wheel_version = os.environ["WHEEL_VERSION"]
in_project = False
updated = False
for index, line in enumerate(lines):
stripped = line.strip()
if stripped == "[project]":
in_project = True
continue
if in_project and stripped.startswith("["):
break
if in_project and re.match(r"version\s*=", stripped):
lines[index] = f'version = "{wheel_version}"'
updated = True
break
if not updated:
raise SystemExit("Failed to update [project].version in python/pyproject.toml")
path.write_text("\n".join(lines) + "\n")
PY
- name: Build wheel
working-directory: python
run: uv build --wheel
- name: Upload wheel artifact to GitHub Actions
uses: actions/upload-artifact@v4
with:
name: wheel
path: python/dist/*.whl
if-no-files-found: error
- name: Authenticate with Cloudsmith via OIDC
uses: cloudsmith-io/cloudsmith-cli-action@v2
with:
oidc-namespace: ${{ env.CLOUDSMITH_NAMESPACE }}
oidc-service-slug: bricksim-github-actions
- name: Upload wheel to Cloudsmith
working-directory: python
run: |
cloudsmith push python "$CLOUDSMITH_NAMESPACE/$CLOUDSMITH_REPOSITORY" dist/*.whl --republish
- name: Upload wheel pointer to Cloudsmith
working-directory: python
run: |
wheel_file=$(basename dist/*.whl)
wheel_url=$(
cloudsmith list packages "$CLOUDSMITH_NAMESPACE/$CLOUDSMITH_REPOSITORY" -F json \
-q "format:python AND filename:^${wheel_file}$" \
| python -c 'import json, sys; payload = json.load(sys.stdin); data = payload["data"] if isinstance(payload, dict) and "data" in payload else payload; len(data) == 1 or (_ for _ in ()).throw(SystemExit(f"Expected exactly one Cloudsmith package match, got {len(data)}")); print(data[0]["cdn_url"])'
)
pointer_dir=$(mktemp -d)
pointer_file="$pointer_dir/wheel-url.txt"
printf '%s\n' "$wheel_url" > "$pointer_file"
cloudsmith push generic "$CLOUDSMITH_NAMESPACE/$CLOUDSMITH_REPOSITORY" "$pointer_file" \
--filepath "commits/${GITHUB_SHA}/wheel-url.txt" \
--republish