Publish a build on every push to main
Publish plugin / publish (push) Successful in 4s

Trigger the release workflow on pushes to main, not just on v* tags, so
every push leaves a downloadable .plugin attached to the current version.

The version in plugin.json decides what happens: a new version creates
tag v<version> and a new release, while an unchanged version rebuilds the
existing release and replaces its attachment. The tag is never moved, so
it keeps pointing at the commit that first introduced that version, but
the release notes are refreshed to name the commit the build came from.

Hand-pushed v* tags and manual runs are unaffected and still use the tag
verbatim.
This commit is contained in:
lyuksovannyy committed 2026-09-12 23:57:43 +02:00
1 parent 196da742de
commit aec9f9376f
3 files changed
+56 -21

No files matched your search

+28 -6
View File
@@ -67,6 +67,7 @@ def find_release(api: str, tag: str, token: str) -> Optional[dict]:
def create_release(api: str, tag: str, token: str, commitish: str, notes: str) -> dict:
"""Creates the release, which also creates the tag if it does not exist."""
body = json.dumps(
{
"tag_name": tag,
@@ -83,6 +84,22 @@ def create_release(api: str, tag: str, token: str, commitish: str, notes: str) -
return json.loads(payload)
def update_release(api: str, release_id: int, token: str, commitish: str, notes: str) -> dict:
"""Refreshes an existing release so a rebuild reports the commit it came from.
target_commitish is deliberately not changed: the tag already points at the
commit that first introduced this version, and moving it would silently
rewrite history for anyone who already fetched it.
"""
body = json.dumps({"body": notes}).encode()
status, payload = request(
"PATCH", f"{api}/releases/{release_id}", token, body, "application/json"
)
if status != 200:
fail(f"updating release {release_id} returned HTTP {status}: {payload[:400]!r}")
return json.loads(payload)
def delete_existing_assets(api: str, release_id: int, name: str, token: str) -> int:
"""Removes same-named assets, since Gitea keeps duplicates side by side."""
status, payload = request("GET", f"{api}/releases/{release_id}/assets", token)
@@ -144,16 +161,21 @@ def main(argv: Optional[list] = None) -> int:
api = args.api.rstrip("/")
version = json.loads((REPO_ROOT / "plugin.json").read_text(encoding="utf-8"))["version"]
notes = [f"Automated build of version {version}."]
if args.commitish:
notes.append(f"Built from `{args.commitish[:12]}`.")
notes.append("Install by opening the attached `.plugin` file in exteraGram.")
notes_text = "\n\n".join(notes)
release = find_release(api, args.tag, token)
if release is None:
notes = (
f"Automated build of version {version}.\n\n"
"Install by opening the attached `.plugin` file in exteraGram."
)
release = create_release(api, args.tag, token, args.commitish, notes)
release = create_release(api, args.tag, token, args.commitish, notes_text)
print(f"created release {args.tag}")
else:
print(f"reusing existing release {args.tag}")
# Version unchanged since the last push: keep the same tag and refresh
# it in place so the attachment always matches the newest commit.
release = update_release(api, int(release["id"]), token, args.commitish, notes_text)
print(f"rebuilding existing release {args.tag}")
release_id = int(release["id"])
removed = delete_existing_assets(api, release_id, asset_name, token)