ci: announce releases on Bluesky

Posts the first paragraph of the release notes plus the link. Notes with
<!-- no-social --> are skipped; a manual run defaults to a dry run that only
logs in and prints the post.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Opus 5.5 committed 2026-10-07 18:05:55 +00:00
1 parent 51d7e107e5
commit 3a91a8db07
2 files changed
+125

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
"""Post a short release announcement to Bluesky.
Reads the release (tag, url, body) as JSON from stdin, e.g. from
`gh release view <tag> --json tagName,url,body`. The post is the first
paragraph of the release notes plus the link. Notes containing
<!-- no-social --> are skipped. DRY_RUN=true logs in (if credentials are set)
and prints the post without publishing it.
"""
import json
import os
import re
import sys
import urllib.request
from datetime import datetime, timezone
BLUESKY_LIMIT = 300
def build_post(release: dict) -> str | None:
body = release.get("body") or ""
if "<!-- no-social -->" in body:
return None
summary = body.strip().split("\n\n")[0].strip()
if summary.startswith("#"):
summary = ""
summary = re.sub(r"\[([^\]]+)\]\([^)]+\)", r"\1", summary)
summary = " ".join(re.sub(r"[`*_]", "", summary).split())
head = f"WebSpeak3 {release['tagName']}"
tail = f"\n\n{release['url']}"
room = BLUESKY_LIMIT - len(head) - len(tail) - 2
if len(summary) > room:
# Prefer dropping whole sentences over cutting one off mid-word.
cut = summary[:room].rfind(". ")
summary = summary[: cut + 1] if cut > 0 else summary[: room - 1].rstrip() + "…"
return f"{head}: {summary}{tail}" if summary else head + tail
def xrpc(method: str, payload: dict, token: str | None = None) -> dict:
req = urllib.request.Request(
f"https://bsky.social/xrpc/{method}",
data=json.dumps(payload).encode(),
headers={"Content-Type": "application/json", **({"Authorization": f"Bearer {token}"} if token else {})},
)
with urllib.request.urlopen(req, timeout=30) as res:
return json.load(res)
def main() -> None:
release = json.load(sys.stdin)
text = build_post(release)
if text is None:
print("Release notes contain <!-- no-social -->, skipping.")
return
print(text)
dry_run = os.environ.get("DRY_RUN") == "true"
handle, password = os.environ.get("BLUESKY_HANDLE"), os.environ.get("BLUESKY_APP_PASSWORD")
if not password:
sys.exit(0 if dry_run else "BLUESKY_APP_PASSWORD is not set.")
session = xrpc("com.atproto.server.createSession", {"identifier": handle, "password": password})
print(f"Logged in as {session['handle']}.")
if dry_run:
print("Dry run, not posting.")
return
# Bluesky doesn't auto-link URLs in API posts; the link needs a facet with UTF-8 byte offsets.
url = release["url"]
start = len(text[: text.rindex(url)].encode())
record = {
"$type": "app.bsky.feed.post",
"text": text,
"langs": ["en"],
"createdAt": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"),
"facets": [{
"index": {"byteStart": start, "byteEnd": start + len(url.encode())},
"features": [{"$type": "app.bsky.richtext.facet#link", "uri": url}],
}],
}
post = xrpc("com.atproto.repo.createRecord",
{"repo": session["did"], "collection": "app.bsky.feed.post", "record": record},
session["accessJwt"])
print(f"Posted: {post['uri']}")
if __name__ == "__main__":
main()
+39
View File
@@ -0,0 +1,39 @@
name: Announce release
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: Release tag to announce
required: true
dry_run:
description: Only log in and print the post, don't publish it
type: boolean
default: true
permissions:
contents: read
jobs:
bluesky:
name: Post to Bluesky
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Check out repository
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
- name: Post release
# Tag passed via env, never spliced into the script (user-controlled text).
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.event.release.tag_name || inputs.tag }}
DRY_RUN: ${{ inputs.dry_run && 'true' || 'false' }}
BLUESKY_HANDLE: moepchi.bsky.social
BLUESKY_APP_PASSWORD: ${{ secrets.BLUESKY_APP_PASSWORD }}
run: |
gh release view "$TAG" -R "$GITHUB_REPOSITORY" --json tagName,url,body \
| python3 .github/scripts/announce-release.py