Skip to content

Commit d292841

Browse files
committed
Fix Windows release metadata rewriting
1 parent a7a0566 commit d292841

1 file changed

Lines changed: 35 additions & 4 deletions

File tree

.github/workflows/release.yml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ jobs:
171171
shopt -s nullglob
172172
173173
exe_name=""
174+
blockmap_name=""
174175
for file in release/*.exe; do
175176
dir=$(dirname "$file")
176177
base=$(basename "$file")
@@ -184,6 +185,15 @@ jobs:
184185
fi
185186
186187
exe_name=$(basename "$file")
188+
189+
original_blockmap="$dir/${stem}.${ext}.blockmap"
190+
if [[ -f "$original_blockmap" ]]; then
191+
target_blockmap="$dir/${exe_name}.blockmap"
192+
if [[ "$original_blockmap" != "$target_blockmap" ]]; then
193+
mv "$original_blockmap" "$target_blockmap"
194+
fi
195+
blockmap_name=$(basename "$target_blockmap")
196+
fi
187197
done
188198
189199
latest_file=""
@@ -198,6 +208,7 @@ jobs:
198208
199209
if [[ -n "$exe_name" && -n "$latest_file" ]]; then
200210
export WINDOWS_EXE_NAME="$exe_name"
211+
export WINDOWS_BLOCKMAP_NAME="$blockmap_name"
201212
export WINDOWS_LATEST_FILE="$latest_file"
202213
python - <<'PY'
203214
import os
@@ -207,12 +218,32 @@ from urllib.parse import quote
207218

208219
latest = Path(os.environ["WINDOWS_LATEST_FILE"])
209220
exe_name = os.environ["WINDOWS_EXE_NAME"]
210-
content = latest.read_text(encoding="utf-8")
221+
blockmap_name = os.environ.get("WINDOWS_BLOCKMAP_NAME") or ""
222+
223+
def replace_line(line: str, needle: str, replacement: str) -> str:
224+
prefix, _, _ = line.partition(needle)
225+
return f"{prefix}{needle}{replacement}\n"
226+
227+
lines = latest.read_text(encoding="utf-8").splitlines(keepends=True)
228+
updated = []
229+
for line in lines:
230+
stripped = line.strip()
231+
if stripped.startswith("path:") and ".exe" in stripped:
232+
updated.append(replace_line(line, "path:", f" {exe_name}"))
233+
continue
234+
235+
if stripped.startswith("url:") and ".exe" in stripped:
236+
value = stripped.split(None, 1)[1] if len(stripped.split(None, 1)) == 2 else ""
237+
if value.endswith(".exe.blockmap") and blockmap_name:
238+
updated.append(replace_line(line, "url:", f" {quote(blockmap_name)}"))
239+
continue
240+
if value.endswith(".exe"):
241+
updated.append(replace_line(line, "url:", f" {quote(exe_name)}"))
242+
continue
211243

212-
content = re.sub(r"^(\s*path:\s*).+$", rf"\1{exe_name}", content, flags=re.MULTILINE)
213-
content = re.sub(r"^(\s*url:\s*).+$", rf"\1{quote(exe_name)}", content, flags=re.MULTILINE)
244+
updated.append(line)
214245

215-
latest.write_text(content, encoding="utf-8")
246+
latest.write_text("".join(updated), encoding="utf-8")
216247
PY
217248
fi
218249

0 commit comments

Comments
 (0)