chore(release): publier les releases avec GoReleaser
La chaîne de release garde ses constructions (binaire, AppImage, libvpx, PipeWire) et confie la publication à GoReleaser: release Gitea créée ou remplacée, pièces jointes, SHA256SUMS, notes de docs/releases quand elles existent, sinon les commits depuis l'étiquette précédente. GoReleaser ne compile rien (build Rust déclaré et sauté): ses constructeurs ne savent pas lier libvpx ni PipeWire. Il publie ce qui est rassemblé dans dist/release, épinglé en 2.17.1 avec son condensat sur le runner. scripts/publish-release.py disparaît. Vérifié en local avec --snapshot: SHA256SUMS conforme, dist/windows intact. La publication réelle sur Gitea reste à vérifier sur une étiquette. Refs #97 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
222099d0ed
commit
41e2bb5a92
5 files changed
+123
-169
No files matched your search
@@ -3,7 +3,8 @@
|
||||
# Nothing else triggers this pipeline: no button, no command typed on a laptop,
|
||||
# and no version number written by hand in a file. The git tag is the single
|
||||
# source of the version; the binary and the AppImage follow from it, and the
|
||||
# release states what it contains.
|
||||
# release states what it contains. GoReleaser publishes it (#97); the builds
|
||||
# stay in the scripts, which know libvpx and PipeWire.
|
||||
#
|
||||
# It first checks that the tag matches the version declared in `Cargo.toml`: a
|
||||
# `v0.2.0` release built from a `Cargo.toml` at `0.1.0` would lie about its
|
||||
@@ -101,22 +102,41 @@ jobs:
|
||||
set -euo pipefail
|
||||
./scripts/build-appimage.sh
|
||||
|
||||
- name: GoReleaser
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# Pinned with its checksum, like appimagetool: the runner has neither
|
||||
# Nix nor a package for it, and a "latest" URL would change
|
||||
# underneath us.
|
||||
version=2.17.1
|
||||
sum=a99bbc7ae0d8d897b07c4c497a9b62f222558804715ef219d1af05a7e417bc80
|
||||
dir="${RUSTSCREEN_CACHE_DIR:-$HOME/.cache/rustscreen-ci}/goreleaser-$version"
|
||||
if [ ! -x "$dir/goreleaser" ]; then
|
||||
mkdir -p "$dir"
|
||||
curl -fsSL -o "$dir/goreleaser.tar.gz" \
|
||||
"https://github.com/goreleaser/goreleaser/releases/download/v$version/goreleaser_Linux_x86_64.tar.gz"
|
||||
echo "$sum $dir/goreleaser.tar.gz" | sha256sum -c -
|
||||
tar -xzf "$dir/goreleaser.tar.gz" -C "$dir" goreleaser
|
||||
rm "$dir/goreleaser.tar.gz"
|
||||
fi
|
||||
echo "$dir" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Release
|
||||
env:
|
||||
# The pipeline token, with the write permission requested above.
|
||||
GITEA_TOKEN: ${{ github.token }}
|
||||
GITEA_REPO: ${{ github.repository }}
|
||||
GITEA_API: ${{ github.server_url }}/api/v1
|
||||
RELEASE_NOTES: docs/releases/${{ github.ref_name }}.md
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# `RELEASE_NOTES` points to a versioned file when it exists; otherwise
|
||||
# the script writes a minimal note rather than failing.
|
||||
# GoReleaser publishes what was built above (`.goreleaser.yaml`): it
|
||||
# only globs inside the repository, hence `dist/release`.
|
||||
mkdir -p dist/release
|
||||
cp "dist-appimage/rustscreen-${VERSION}-x86_64.AppImage" dist/release/
|
||||
cp "$CARGO_TARGET_DIR/release/rustscreen-cli" dist/release/
|
||||
notes="docs/releases/${GITHUB_REF_NAME}.md"
|
||||
if [ ! -f "$notes" ]; then
|
||||
echo "no notes for ${GITHUB_REF_NAME}, minimal note" >&2
|
||||
export RELEASE_NOTES="$notes.absent"
|
||||
if [ -f "$notes" ]; then
|
||||
goreleaser release --clean --release-notes "$notes"
|
||||
else
|
||||
# Without written notes, the commits since the previous tag.
|
||||
echo "no notes for ${GITHUB_REF_NAME}, changelog from git" >&2
|
||||
goreleaser release --clean
|
||||
fi
|
||||
./scripts/publish-release.py "$GITHUB_REF_NAME" \
|
||||
"dist-appimage/rustscreen-${VERSION}-x86_64.AppImage" \
|
||||
"$CARGO_TARGET_DIR/release/rustscreen-cli"
|
||||
@@ -0,0 +1,64 @@
|
||||
# Release of a `vX.Y.Z` tag (#97), run by `.gitea/workflows/release.yml`.
|
||||
#
|
||||
# GoReleaser does not compile anything here: the Rust stack needs libvpx,
|
||||
# PipeWire and the viewer built first, which the pipeline does with its own
|
||||
# scripts. It takes the finished artifacts and publishes the release: Gitea
|
||||
# release, attachments, SHA256SUMS, notes. A rerun on the same tag replaces
|
||||
# them instead of stacking copies.
|
||||
#
|
||||
# Local check, without publishing:
|
||||
# goreleaser release --snapshot --clean --skip=publish
|
||||
version: 2
|
||||
|
||||
project_name: rustscreen
|
||||
|
||||
# Not `dist/`: `--clean` empties it, and the Windows installer is built there.
|
||||
dist: dist/goreleaser
|
||||
|
||||
# A skipped build, declared Rust so that GoReleaser does not look for a Go
|
||||
# module.
|
||||
builds:
|
||||
- builder: rust
|
||||
skip: true
|
||||
|
||||
gitea_urls:
|
||||
api: https://gitea-nubo.hopledge.com/api/v1
|
||||
download: https://gitea-nubo.hopledge.com
|
||||
|
||||
# The pipeline token is GITEA_TOKEN; a GITHUB_TOKEN set by the runner must not
|
||||
# send GoReleaser to GitHub.
|
||||
force_token: gitea
|
||||
|
||||
# What the release ships, built beforehand and gathered in `dist/release`
|
||||
# (GoReleaser only globs inside the repository). A missing file fails the
|
||||
# release rather than publishing an incomplete one.
|
||||
release:
|
||||
gitea:
|
||||
owner: heap
|
||||
name: rustscreen
|
||||
name_template: "v{{ .Version }}"
|
||||
mode: replace
|
||||
replace_existing_artifacts: true
|
||||
extra_files:
|
||||
- glob: "dist/release/rustscreen-{{ .Version }}-x86_64.AppImage"
|
||||
- glob: "dist/release/rustscreen-cli"
|
||||
|
||||
checksum:
|
||||
name_template: SHA256SUMS
|
||||
algorithm: sha256
|
||||
extra_files:
|
||||
- glob: "dist/release/rustscreen-{{ .Version }}-x86_64.AppImage"
|
||||
- glob: "dist/release/rustscreen-cli"
|
||||
|
||||
# `--snapshot` (local check): the artifacts are named after this version.
|
||||
snapshot:
|
||||
version_template: "{{ .Version }}-snapshot"
|
||||
|
||||
# Used when `docs/releases/vX.Y.Z.md` does not exist; otherwise the pipeline
|
||||
# passes that file with `--release-notes`.
|
||||
changelog:
|
||||
use: git
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- "^chore\\(deps\\)"
|
||||
+27
-2
@@ -90,7 +90,32 @@ le configure de libvpx, pages HTML retirées par le filtre de sources.
|
||||
Les fichiers nouveaux doivent être connus de git (`git add`, ou `git add -N` avant un commit):
|
||||
un flake ne voit que les fichiers suivis.
|
||||
|
||||
## Publier une release
|
||||
|
||||
Une étiquette `vX.Y.Z` poussée lance `.gitea/workflows/release.yml`, et rien d'autre ne publie.
|
||||
La chaîne refuse une étiquette qui ne correspond pas à la version du `Cargo.toml`, construit le
|
||||
binaire et l'AppImage avec les scripts ci-dessus, puis passe la main à **GoReleaser** (#97,
|
||||
`.goreleaser.yaml`), qui crée ou remplace la release Gitea, ses pièces jointes et `SHA256SUMS`.
|
||||
|
||||
GoReleaser ne compile rien: la pile Rust demande libvpx, PipeWire et le viewer déjà construit, ce
|
||||
que ses constructeurs ne savent pas faire. Il publie les fichiers rassemblés dans `dist/release`
|
||||
(il ne cherche que dans le dépôt). Les notes viennent de `docs/releases/vX.Y.Z.md` quand il existe,
|
||||
sinon des commits depuis l'étiquette précédente. Rejouer la chaîne sur la même étiquette remplace
|
||||
les pièces jointes au lieu de les empiler.
|
||||
|
||||
Vérifier la configuration sans rien publier, avec des fichiers dans `dist/release` nommés d'après
|
||||
la version `X.Y.Z-snapshot`:
|
||||
|
||||
```sh
|
||||
nix run nixpkgs#goreleaser -- check
|
||||
nix run nixpkgs#goreleaser -- release --snapshot --clean --skip=publish
|
||||
```
|
||||
|
||||
`dist/goreleaser` reçoit alors `SHA256SUMS` et les métadonnées. L'installateur Windows
|
||||
(`scripts/build-windows-installer.sh`, #96) demande Nix, que le runner n'a pas: il n'est pas encore
|
||||
dans la release.
|
||||
|
||||
## Ce que le paquet ne fait pas encore
|
||||
|
||||
La capture est réelle sous Wayland (portail et PipeWire) et sous X11. Ce qui manque: la coque
|
||||
desktop (#15), la capture Windows (#8), et l'encodage matériel (#57).
|
||||
L'installateur Windows n'est pas publié par la chaîne (voir plus haut), et les paquets `.deb` et
|
||||
`.rpm` n'existent pas (#51).
|
||||
Binary file not shown.
@@ -1,155 +0,0 @@
|
||||
#!/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()
|
||||
Reference in new issue
Block a user