@@ -32,14 +32,55 @@ jobs:
3232 GH_TOKEN : ${{ secrets.GIST_TOKEN }}
3333 GIST_ID : " d2e6016b8d7a90f813a582078208e9bd"
3434 GIST_FILENAME : " announcement.json" # ← set this to the actual filename in your Gist
35- PACSEA_REPO : " Firstp1ck/Pacsea "
35+ PACSEA_REPO : ${{ github.repository }}
3636 run : |
3737 pip install feedparser html2text -q
3838
3939 python3 << 'EOF'
40- import feedparser, html2text, json, re, os, urllib.request
40+ import feedparser, html2text, json, re, os, urllib.error, urllib. request
4141 from datetime import datetime
4242
43+ def github_request(url, token):
44+ return urllib.request.Request(
45+ url,
46+ headers={
47+ "Authorization": f"Bearer {token}",
48+ "Accept": "application/vnd.github+json",
49+ "User-Agent": "pacsea-arch-news-watcher",
50+ },
51+ )
52+
53+ def github_json(url, token):
54+ with urllib.request.urlopen(github_request(url, token)) as resp:
55+ return json.loads(resp.read())
56+
57+ def resolve_version_tag(repo, token):
58+ override = os.environ.get("PACSEA_VERSION", "").strip()
59+ if override:
60+ return override.lstrip("v")
61+
62+ base = f"https://api.github.com/repos/{repo}"
63+ try:
64+ rel = github_json(f"{base}/releases/latest", token)
65+ return rel["tag_name"].lstrip("v")
66+ except urllib.error.HTTPError as e:
67+ if e.code != 404:
68+ raise
69+
70+ releases = github_json(f"{base}/releases?per_page=30", token)
71+ for rel in releases:
72+ if rel.get("draft"):
73+ continue
74+ return rel["tag_name"].lstrip("v")
75+
76+ tags = github_json(f"{base}/tags?per_page=30", token)
77+ if not tags:
78+ raise SystemExit(
79+ f"No releases or tags for {repo}; "
80+ "publish a release/tag or set PACSEA_VERSION."
81+ )
82+ return tags[0]["name"].lstrip("v")
83+
4384 # ── 1. Parse latest RSS entry ──────────────────────────────────────
4485 feed = feedparser.parse("current.xml")
4586 entry = feed.entries[0]
@@ -59,23 +100,15 @@ jobs:
59100 title_slug = re.sub(r'[^a-z0-9]+', '-', title.lower()).strip('-')[:40]
60101 news_id = f"{date_str}-{title_slug}"
61102
62- # ── 4. Fetch latest Pacsea release from GitHub API ───────── ────────
103+ # ── 4. Resolve current version ( release tag) from GitHub API ────────
63104 repo = os.environ["PACSEA_REPO"]
64105 token = os.environ["GH_TOKEN"]
65- api_url = f"https://api.github.com/repos/{repo}/releases/latest"
66- req = urllib.request.Request(
67- api_url,
68- headers={"Authorization": f"Bearer {token}",
69- "Accept": "application/vnd.github+json"}
70- )
71- with urllib.request.urlopen(req) as r:
72- release = json.loads(r.read())
73-
74- version = release["tag_name"].lstrip("v") # e.g. "0.8.5"
106+ version = resolve_version_tag(repo, token)
75107 parts = version.split(".")
76108
77109 # ── 5. min_version = current major.minor-1.0 ──────────────────────
78- min_ver = f"{parts[0]}.{int(parts[1]) - 1}.0" # 0.8.5 → 0.7.0
110+ minor = max(0, int(parts[1]) - 1)
111+ min_ver = f"{parts[0]}.{minor}.0" # 0.8.5 → 0.7.0
79112
80113 # ── 6. Assemble final JSON payload ────────────────────────────────
81114 payload = {
0 commit comments