CI / Formatting, tests and builds (push) Successful in 3m19s
Code en anglais (#83): identifiants, noms de fichiers et de modules, commentaires, journal (champ event, noms d'événements anglais), messages d'erreur, commandes Tauri, types générés, clés de traduction, sorties de rustscreen-cli, scripts, Nix et CI. Les textes affichés passent toujours par locales/ (français et anglais); la documentation et les commits restent en français. AGENTS.md porte la règle. Ce qui est déjà écrit chez l'utilisateur se relit: anciens noms de champs des réglages (alias serde), reglages.json à défaut de settings.json, anciennes clés localStorage dont l'identifiant d'appareil, jeton de restauration du portail, anciennes options de la ligne de commande, ancien argument du démarrage automatique. rustscreen ouvre l'application de bureau (#84): la ligne de commande devient rustscreen-cli. Le paquet Nix par défaut construit l'application (interface pnpm, Tauri avec WebKitGTK et PipeWire, icône de barre système), avec rustscreen-cli et le viewer. Début du jalon 0.6.0, pas encore essayé en vrai: miroir du viewer (#29), barres qui s'effacent en fenêtre et en plein écran (#31, #81), confirmation avant de quitter pendant un partage (#43), démarrage automatique caché dans la barre système et fichier .desktop réparé au lancement (#32). Closes #83, #84 Refs #29, #31, #32, #43, #81 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
156 lines
5.6 KiB
Python
Executable File
156 lines
5.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Publishes a Gitea release with its artifacts.
|
|
|
|
./scripts/publish-release.py v0.1.0 dist-appimage/*.AppImage target/release/rustscreen-cli
|
|
|
|
The script is idempotent: running it again on the same tag updates the notes
|
|
and replaces the attachments instead of stacking copies. A pipeline that
|
|
reruns must not produce a duplicate release, nor the same file twice with
|
|
different checksums.
|
|
|
|
No dependency outside the standard library: the pipeline runner only has
|
|
python3, git and the build tools.
|
|
"""
|
|
|
|
import hashlib
|
|
import json
|
|
import mimetypes
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
import urllib.error
|
|
import urllib.request
|
|
import uuid
|
|
from pathlib import Path
|
|
|
|
API = os.environ.get("GITEA_API", "https://gitea-nubo.hopledge.com/api/v1")
|
|
REPO = os.environ.get("GITEA_REPO", "heap/rustscreen")
|
|
TOKEN = os.environ.get("GITEA_TOKEN") or os.environ.get("GITHUB_TOKEN")
|
|
|
|
|
|
def call(method, path, body=None, headers=None):
|
|
"""JSON API call, with an error message that says what to fix."""
|
|
headers = dict(headers or {})
|
|
headers["Authorization"] = f"token {TOKEN}"
|
|
if body is not None:
|
|
body = json.dumps(body).encode()
|
|
headers["Content-Type"] = "application/json"
|
|
request = urllib.request.Request(f"{API}{path}", data=body, method=method, headers=headers)
|
|
try:
|
|
with urllib.request.urlopen(request, timeout=120) as response:
|
|
raw = response.read()
|
|
return json.loads(raw) if raw else None
|
|
except urllib.error.HTTPError as error:
|
|
detail = error.read().decode("utf-8", "replace")[:400]
|
|
raise SystemExit(f"{method} {path} -> {error.code}: {detail}") from error
|
|
|
|
|
|
def send_raw(method, path, body, content_type):
|
|
"""Non-JSON request: the upload API expects multipart, not JSON."""
|
|
request = urllib.request.Request(
|
|
f"{API}{path}",
|
|
data=body,
|
|
method=method,
|
|
headers={"Authorization": f"token {TOKEN}", "Content-Type": content_type},
|
|
)
|
|
try:
|
|
with urllib.request.urlopen(request, timeout=300) as response:
|
|
raw = response.read()
|
|
return json.loads(raw) if raw else None
|
|
except urllib.error.HTTPError as error:
|
|
detail = error.read().decode("utf-8", "replace")[:400]
|
|
raise SystemExit(f"{method} {path} -> {error.code}: {detail}") from error
|
|
|
|
|
|
def existing_release(tag):
|
|
"""Returns the tag's release, or None if it does not exist yet."""
|
|
try:
|
|
return call("GET", f"/repos/{REPO}/releases/tags/{tag}")
|
|
except SystemExit:
|
|
return None
|
|
|
|
|
|
def upload(release_id, file):
|
|
"""Uploads an attachment, replacing the one with the same name."""
|
|
name = file.name
|
|
existing = call("GET", f"/repos/{REPO}/releases/{release_id}/assets")
|
|
for asset in existing or []:
|
|
if asset.get("name") == name:
|
|
# A different checksum under the same name would make the release
|
|
# ambiguous: the old one is removed before the new one is added.
|
|
call("DELETE", f"/repos/{REPO}/releases/{release_id}/assets/{asset['id']}")
|
|
print(f" replaced: {name}")
|
|
|
|
boundary = uuid.uuid4().hex
|
|
content = file.read_bytes()
|
|
mime_type = mimetypes.guess_type(name)[0] or "application/octet-stream"
|
|
body = b"".join(
|
|
[
|
|
f"--{boundary}\r\n".encode(),
|
|
f'Content-Disposition: form-data; name="attachment"; filename="{name}"\r\n'.encode(),
|
|
f"Content-Type: {mime_type}\r\n\r\n".encode(),
|
|
content,
|
|
f"\r\n--{boundary}--\r\n".encode(),
|
|
]
|
|
)
|
|
send_raw(
|
|
"POST",
|
|
f"/repos/{REPO}/releases/{release_id}/assets?name={name}",
|
|
body,
|
|
f"multipart/form-data; boundary={boundary}",
|
|
)
|
|
digest = hashlib.sha256(content).hexdigest()
|
|
print(f" added: {name} ({len(content) / 1e6:.1f} MB, sha256 {digest[:16]}...)")
|
|
return name, digest
|
|
|
|
|
|
def main():
|
|
if not TOKEN:
|
|
raise SystemExit("GITEA_TOKEN (or GITHUB_TOKEN) is required")
|
|
if len(sys.argv) < 3:
|
|
raise SystemExit(__doc__)
|
|
|
|
tag = sys.argv[1]
|
|
files = [Path(argument) for argument in sys.argv[2:]]
|
|
for file in files:
|
|
if not file.is_file():
|
|
raise SystemExit(f"artifact not found: {file}")
|
|
|
|
notes = Path(os.environ.get("RELEASE_NOTES", "release-notes.md"))
|
|
body = notes.read_text() if notes.is_file() else f"Publication {tag}."
|
|
|
|
existing = existing_release(tag)
|
|
if existing:
|
|
print(f"release {tag} already exists (id {existing['id']}), updating")
|
|
# The tag is named explicitly: Gitea otherwise rejects a body without a tag.
|
|
release = call(
|
|
"PATCH",
|
|
f"/repos/{REPO}/releases/{existing['id']}",
|
|
{"tag_name": tag, "name": tag, "body": body, "draft": False, "prerelease": False},
|
|
)
|
|
else:
|
|
print(f"creating release {tag}")
|
|
release = call(
|
|
"POST",
|
|
f"/repos/{REPO}/releases",
|
|
{"tag_name": tag, "name": tag, "body": body, "draft": False, "prerelease": False},
|
|
)
|
|
|
|
digests = [upload(release["id"], file) for file in files]
|
|
|
|
# A separate checksum file: without it, every artifact has to be hashed by
|
|
# hand to check what was downloaded.
|
|
summary = "".join(f"{digest} {name}\n" for name, digest in digests)
|
|
# A temporary directory, not the current one: a local run must not leave a
|
|
# release artifact in the working tree.
|
|
directory = Path(tempfile.mkdtemp(prefix="rustscreen-release-"))
|
|
path = directory / "SHA256SUMS"
|
|
path.write_text(summary)
|
|
upload(release["id"], path)
|
|
|
|
print(f"\nrelease published: {release['html_url']}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|