Added API call to build the Gitea runner debian package

This commit is contained in:
florian committed 2026-10-19 10:56:12 +02:00
1 parent 2ef26af317
commit bd2b0b601e
2 files changed
+40 -2

No files matched your search

+30
View File
@@ -8,6 +8,9 @@ from simple_logger_handler import setup_logger
logger = setup_logger(__name__)
_GITEA_INSTANCE_BASE_URL="https://git.gansejunge.com"
_GITEA_REPOSITORY_OWNER="utility"
def get_rss_feed_data(rss_feed_url: str, max_retries: int = 3) -> feedparser.FeedParserDict:
"""
Fetches information from any RSS feed, with retries on network-related errors.
@@ -92,6 +95,33 @@ def grab_royal_road_chapter_information(rss_feed_url: str) -> Tuple[str, str, st
logger.debug(f"[Feed] Latest chapter for story '{story_title}' (RSS URL {rss_feed_url}): {chapter_title} (ID {chapter_id}) -> {chapter_link}")
return chapter_title, chapter_link, story_title, chapter_id
def build_gitea_runner(version: str, gitea_token: str) -> bool:
url = (
f"{_GITEA_INSTANCE_BASE_URL}/api/v1/repos/{_GITEA_REPOSITORY_OWNER}"
"/deb-gitea-runner/actions/workflows/gitea-runner-release.yaml/dispatches"
)
headers = {"Authorization": f"token {gitea_token}"}
payload = {
"ref": "main",
"inputs": {
"version": version.lstrip("v"),
"revision": "1",
},
}
try:
response = requests.post(url, headers=headers, json=payload, timeout=10)
response.raise_for_status()
return True
except requests.HTTPError as e:
body = e.response.text if e.response is not None else ""
logger.warning(f"[Feed] Gitea-Runner build dispatch failed: {e} {body}")
except requests.RequestException as e:
logger.warning(f"[Feed] Failed to run Gitea-Runner build: {e}")
return False
if __name__ == "__main__":
#rsssss="https://gitea.com/gitea/runner/releases.rss"
#print(get_rss_feed_data(rsssss))
+10 -2
View File
@@ -1,13 +1,14 @@
import asyncio
from contextlib import asynccontextmanager
import os
import uvicorn
from fastapi import Depends, FastAPI, HTTPException, Request
from db_module import close_connection_pool, create_connection_pool, get_db, start_healthcheck_thread
from feed_handler import grab_gitea_release_information, grab_royal_road_chapter_information
from feed_handler import grab_gitea_release_information, grab_royal_road_chapter_information, build_gitea_runner
from metrics_server import REQUEST_COUNTER, metrics_api
from secret_manager import cleanup_secret_files
from secret_manager import cleanup_secret_files, get_secret
from send_notifications import NotificationClient
from simple_logger_handler import LOG_LEVEL, setup_logger
@@ -18,6 +19,8 @@ logger = setup_logger(__name__)
async def lifespan(app: FastAPI):
logger.info("[FastAPI] Starting application...")
app.state.notifier = NotificationClient()
app.state.gitea_token = get_secret(os.getenv("GITEA_TOKEN",""),"/etc/secrets/gitea_token")
logger.info("[FastAPI] Creating MySQL connection pool...")
create_connection_pool("royalRoadPool")
@@ -25,6 +28,7 @@ async def lifespan(app: FastAPI):
logger.info("[FastAPI] MySQL healthcheck thread started.")
SECRET_PATHS = frozenset({
"/etc/secrets/gitea_token",
"/etc/secrets/api_key",
"/etc/secrets/db_username",
"/etc/secrets/db_password"
@@ -110,6 +114,10 @@ def get_release_information(request: Request, db = Depends(get_db)):
logger.debug(f"[FastAPI] Notification sent and database updated for Gitea feed ID {feed_id}")
results["new"] += 1
if link.startswith("https://gitea.com/gitea/runner/releases/tag/v"):
gitea_build_success = build_gitea_runner(release_title, request.app.state.gitea_token)
logger.info(f"[FastAPI] Gitea build ran successfully:{gitea_build_success}")
except Exception as e:
db.rollback()
results["errors"] += 1