Files
app/create_release.py
Renato97 fb32fc4052 chore: remove sensitive data and clean repo for CV
- Remove .env file with exposed tokens

- Replace hardcoded Gitea token with environment variable in create_release.py

- Replace hardcoded token with BuildConfig reference in UpdateManager.java
2026-03-31 01:16:12 -03:00

86 lines
2.7 KiB
Python

import json
import urllib.request
import urllib.parse
import urllib.error
import os
import sys
# Configuration
GITEA_URL = "https://gitea.cbcren.online/api/v1"
REPO_OWNER = "renato97"
REPO_NAME = "app"
TOKEN = os.getenv("GITEA_TOKEN", "")
if not TOKEN:
print("Error: GITEA_TOKEN environment variable not set")
sys.exit(1)
TAG_NAME = "v10.1.7"
RELEASE_NAME = "StreamPlayer v10.1.7"
CHANGELOG_FILE = "CHANGELOG-v10.1.7.md"
APK_FILE = "StreamPlayer-10.1.7-debug.apk"
def create_release():
try:
with open(CHANGELOG_FILE, "r") as f:
body = f.read()
except FileNotFoundError:
print(f"Error: {CHANGELOG_FILE} not found.")
sys.exit(1)
url = f"{GITEA_URL}/repos/{REPO_OWNER}/{REPO_NAME}/releases"
headers = {
"Authorization": f"token {TOKEN}",
"Content-Type": "application/json",
"Accept": "application/json",
}
data = {
"tag_name": TAG_NAME,
"target_commitish": "main",
"name": RELEASE_NAME,
"body": body,
"draft": False,
"prerelease": False,
}
req = urllib.request.Request(
url, data=json.dumps(data).encode("utf-8"), headers=headers, method="POST"
)
try:
with urllib.request.urlopen(req) as response:
result = json.loads(response.read().decode("utf-8"))
print(f"Release created successfully. ID: {result['id']}")
return result["id"]
except urllib.error.HTTPError as e:
print(f"HTTP Error creating release: {e.code} {e.reason}")
print(e.read().decode("utf-8"))
sys.exit(1)
except Exception as e:
print(f"Error creating release: {e}")
sys.exit(1)
def upload_asset(release_id):
if not os.path.exists(APK_FILE):
print(f"Error: APK file {APK_FILE} not found.")
sys.exit(1)
url = f"{GITEA_URL}/repos/{REPO_OWNER}/{REPO_NAME}/releases/{release_id}/assets"
# Simple multipart upload via python is tricky without requests library.
# However, Gitea API usually accepts raw binary in body if Content-Type is set,
# but Gitea's API for assets usually requires multipart/form-data.
# Let's check Gitea API docs...
# The standard Gitea API uses POST /repos/{owner}/{repo}/releases/{id}/assets with name query parameter and file content in body
# Wait, looking at Gitea API docs (swagger usually available at /api/swagger),
# POST /repos/{owner}/{repo}/releases/{id}/assets takes 'attachment' as form-data.
# Implementing multipart/form-data with urllib is painful.
# Instead, I will use curl to upload the asset, using the release ID obtained from Python.
return release_id
if __name__ == "__main__":
release_id = create_release()
print(f"RELEASE_ID={release_id}")