Skip to content

πŸŒ€ RR Version Check #4061

πŸŒ€ RR Version Check

πŸŒ€ RR Version Check #4061

Workflow file for this run

name: "πŸŒ€ RR Version Check"
on:
schedule:
- cron: '*/5 * * * *'
workflow_dispatch:
permissions:
contents: write
jobs:
update-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: pip install requests
- name: Process Version and Changelog
env:
RR_DC_CHID: ${{ secrets.RR_DC_CHID }}
RR_DCBOT_KEY: ${{ secrets.RR_DCBOT_KEY }}
run: |
python -c '
import os, requests, json, re
CHID = os.getenv("RR_DC_CHID")
TOKEN = os.getenv("RR_DCBOT_KEY")
# Fetch remote version
try:
v_resp = requests.get("http://update.rwfc.net:8000/RetroRewind/RetroRewindVersion.txt", timeout=10)
v_resp.raise_for_status()
v_text = v_resp.text
new_v = v_text.strip().split("\n")[-1].split(" ")[0]
except Exception as e:
print(f"Error fetching version: {e}")
exit(1)
# Read local state
old_v, old_c = "", ""
if os.path.exists("latest.json"):
try:
with open("latest.json", "r") as f:
data = json.load(f)
old_v, old_c = data.get("version", ""), data.get("changelog", "")
except: pass
final_c = old_c
# Search Discord if version is new or changelog is missing
if new_v != old_v or old_c == "No changelog released yet":
print("Searching Discord messages...")
d_url = f"https://discord.com/api/v10/channels/{CHID}/messages?limit=10"
d_headers = {"Authorization": f"Bot {TOKEN}"}
try:
d_resp = requests.get(d_url, headers=d_headers, timeout=10)
if d_resp.status_code == 200:
messages = d_resp.json()
found = False
for msg in messages:
# Check primary content or message snapshots
content = msg.get("content") or ""
if not content and msg.get("message_snapshots"):
content = msg["message_snapshots"][0].get("message", {}).get("content") or ""
# Identify release message and extract full content
if str(new_v) in content or "change log" in content.lower() or "changelog" in content.lower():
# Remove download links
content = re.sub(r"Main Download:\s*https?://\S+\n?", "", content, flags=re.IGNORECASE)
content = re.sub(r"New files since[^\n:]+:\s*https?://\S+\n?", "", content, flags=re.IGNORECASE)
# Clean up whitespaces
final_c = content.strip()
found = True
break
if not found and new_v != old_v:
final_c = "No changelog released yet"
else:
if new_v != old_v: final_c = "No changelog released yet"
except:
if new_v != old_v: final_c = "No changelog released yet"
# Write results
with open("latest.json", "w") as f:
json.dump({"version": new_v, "changelog": final_c}, f, indent=2)
with open("versions.txt", "w") as f:
f.write(v_text)
'
- name: Check and Push Changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add versions.txt latest.json
if ! git diff --staged --quiet; then
git commit -m "🏎️ RR Version+Changelog updated"
git push
fi