Skip to content

Commit

Permalink
Merge branch 'hotfix/nologin'
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Jul 8, 2024
2 parents 1071a08 + 1e7dbba commit f2a20c3
Show file tree
Hide file tree
Showing 31 changed files with 479 additions and 522 deletions.
2 changes: 0 additions & 2 deletions .github/utils/_get_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ def get_password(
auth_plugin="mysql_native_password",
)

print(f"Generating passwords for version {version_name} ({version_code})")

password = base64.b64encode(secrets.token_bytes(16)).decode()
iv = secrets.token_bytes(16)

Expand Down
4 changes: 3 additions & 1 deletion .github/utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def get_commit_log(project_dir: str, format: str, max_lines: int = None) -> str:
)

log = subprocess.run(
args=f"git log {last_tag}..HEAD --format=%an%x00%at%x00%h%x00%s%x00%D".split(" "),
args=f"git log {last_tag}..HEAD --format=%an%x00%at%x00%h%x00%s%x00%D".split(
" "
),
cwd=project_dir,
stdout=subprocess.PIPE,
)
Expand Down
18 changes: 2 additions & 16 deletions .github/utils/bump_nightly.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import json
import os
import re
import sys
from datetime import datetime, timedelta

import requests

from _utils import (
get_commit_log,
get_project_dir,
Expand All @@ -25,17 +22,6 @@
print("Missing GitHub environment variables.")
exit(-1)

with requests.get(
f"https://api.github.com/repos/{repo}/actions/runs?per_page=5&status=success"
) as r:
data = json.loads(r.text)
runs = [run for run in data["workflow_runs"] if run["head_sha"] == sha]
if runs:
print("::set-output name=hasNewChanges::false")
exit(0)

print("::set-output name=hasNewChanges::true")

project_dir = get_project_dir()

(version_code, version_name) = read_gradle_version(project_dir)
Expand All @@ -48,8 +34,8 @@
date -= timedelta(days=1)
version_name += "+nightly." + date.strftime("%Y%m%d")

print("::set-output name=appVersionName::" + version_name)
print("::set-output name=appVersionCode::" + str(version_code))
print("appVersionName=" + version_name)
print("appVersionCode=" + str(version_code))

write_gradle_version(project_dir, version_code, version_name)

Expand Down
23 changes: 23 additions & 0 deletions .github/utils/check_nightly.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json
import os

import requests

if __name__ == "__main__":
repo = os.getenv("GITHUB_REPOSITORY")
sha = os.getenv("GITHUB_SHA")

if not repo or not sha:
print("Missing GitHub environment variables.")
exit(-1)

with requests.get(
f"https://api.github.com/repos/{repo}/actions/runs?per_page=5&status=success"
) as r:
data = json.loads(r.text)
runs = [run for run in data["workflow_runs"] if run["head_sha"] == sha]
if runs:
print("hasNewChanges=false")
exit(0)

print("hasNewChanges=true")
23 changes: 11 additions & 12 deletions .github/utils/extract_changelogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

(version_code, version_name) = read_gradle_version(project_dir)

print("::set-output name=appVersionName::" + version_name)
print("::set-output name=appVersionCode::" + str(version_code))
print("appVersionName=" + version_name)
print("appVersionCode=" + str(version_code))

dir = f"{project_dir}/app/release/whatsnew-{version_name}/"
os.makedirs(dir, exist_ok=True)

print("::set-output name=changelogDir::" + dir)
print("changelogDir=" + dir)

(title, changelog) = get_changelog(project_dir, format="plain")

Expand All @@ -27,9 +27,9 @@
f.write(title)
f.write("\n")
f.write(changelog)
print("::set-output name=changelogPlainTitledFile::" + dir + "whatsnew_titled.txt")
print("changelogPlainTitledFile=" + dir + "whatsnew_titled.txt")

print("::set-output name=changelogTitle::" + title)
print("changelogTitle=" + title)

# plain text changelog, max 500 chars - Google Play
with open(dir + "whatsnew-pl-PL", "w", encoding="utf-8") as f:
Expand All @@ -41,32 +41,31 @@
changelog = changelog.strip()
f.write(changelog)

print("::set-output name=changelogPlainFile::" + dir + "whatsnew-pl-PL")
print("changelogPlainFile=" + dir + "whatsnew-pl-PL")

# markdown changelog - Discord webhook
(_, changelog) = get_changelog(project_dir, format="markdown")
with open(dir + "whatsnew.md", "w", encoding="utf-8") as f:
f.write(changelog)
print("::set-output name=changelogMarkdownFile::" + dir + "whatsnew.md")
print("changelogMarkdownFile=" + dir + "whatsnew.md")

# html changelog - version info in DB
(_, changelog) = get_changelog(project_dir, format="html")
with open(dir + "whatsnew.html", "w", encoding="utf-8") as f:
f.write(changelog)
print("::set-output name=changelogHtmlFile::" + dir + "whatsnew.html")

print("changelogHtmlFile=" + dir + "whatsnew.html")

changelog = get_commit_log(project_dir, format="plain", max_lines=10)
with open(dir + "commit_log.txt", "w", encoding="utf-8") as f:
f.write(changelog)
print("::set-output name=commitLogPlainFile::" + dir + "commit_log.txt")
print("commitLogPlainFile=" + dir + "commit_log.txt")

changelog = get_commit_log(project_dir, format="markdown", max_lines=10)
with open(dir + "commit_log.md", "w", encoding="utf-8") as f:
f.write(changelog)
print("::set-output name=commitLogMarkdownFile::" + dir + "commit_log.md")
print("commitLogMarkdownFile=" + dir + "commit_log.md")

changelog = get_commit_log(project_dir, format="html", max_lines=10)
with open(dir + "commit_log.html", "w", encoding="utf-8") as f:
f.write(changelog)
print("::set-output name=commitLogHtmlFile::" + dir + "commit_log.html")
print("commitLogHtmlFile=" + dir + "commit_log.html")
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

files = glob.glob(f"{project_dir}/app/release/*.*")
for file in files:
file_relative = file.replace(os.getenv("GITHUB_WORKSPACE") + "/", "")
file_relative = file.replace(project_dir + "/", "")
if "-aligned.apk" in file:
os.unlink(file)
elif "-signed.apk" in file:
Expand All @@ -22,5 +22,5 @@
os.unlink(new_file)
os.rename(file, new_file)
elif ".apk" in file or ".aab" in file:
print("::set-output name=signedReleaseFile::" + file)
print("::set-output name=signedReleaseFileRelative::" + file_relative)
print("signedReleaseFile=" + file)
print("signedReleaseFileRelative=" + file_relative)
19 changes: 17 additions & 2 deletions .github/utils/save_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ def save_version(
if build_type in ["nightly", "daily"]:
download_url = apk_server_nightly + apk_name if apk_name else None
else:
download_url = apk_server_release + apk_name if apk_name else None
# download_url = apk_server_release + apk_name if apk_name else None
download_url = (
f"https://github.com/szkolny-eu/szkolny-android/releases/download/v{version_name}/{apk_name}"
if apk_name
else None
)
if download_url:
print("downloadUrl=" + download_url)

cols = [
"versionCode",
Expand Down Expand Up @@ -119,4 +126,12 @@ def save_version(
APK_SERVER_RELEASE = os.getenv("APK_SERVER_RELEASE")
APK_SERVER_NIGHTLY = os.getenv("APK_SERVER_NIGHTLY")

save_version(project_dir, DB_HOST, DB_USER, DB_PASS, DB_NAME, APK_SERVER_RELEASE, APK_SERVER_NIGHTLY)
save_version(
project_dir,
DB_HOST,
DB_USER,
DB_PASS,
DB_NAME,
APK_SERVER_RELEASE,
APK_SERVER_NIGHTLY,
)
6 changes: 2 additions & 4 deletions .github/utils/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def sign(
SIGNING_FORMAT = "$param1.{}.$param2"
CPP_FORMAT = "/*{}*/\nstatic toys AES_IV[16] = {{\n\t{} }};"

print(f"Writing passwords for version {version_name} ({version_code})")

iv_hex = " ".join(["{:02x}".format(x) for x in iv])
iv_cpp = ", ".join(["0x{:02x}".format(x) for x in iv])

Expand Down Expand Up @@ -71,8 +69,8 @@ def sign(
version_name, version_code, DB_HOST, DB_USER, DB_PASS, DB_NAME
)

print("::set-output name=appVersionName::" + version_name)
print("::set-output name=appVersionCode::" + str(version_code))
print("appVersionName=" + version_name)
print("appVersionCode=" + str(version_code))

sign(
project_dir,
Expand Down
33 changes: 15 additions & 18 deletions .github/utils/webhook_discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
def post_webhook(
project_dir: str,
apk_file: str,
apk_server_release: str,
apk_server_nightly: str,
download_url: str,
webhook_release: str,
webhook_testing: str,
):
Expand All @@ -25,12 +24,6 @@ def post_webhook(
testing = ["dev", "beta", "nightly", "daily"]
testing = build_type in testing

apk_name = os.path.basename(apk_file)
if build_type in ["nightly", "daily"]:
download_url = apk_server_nightly + apk_name
else:
download_url = apk_server_release + apk_name

if testing:
build_date = int(os.stat(apk_file).st_mtime)
if build_date:
Expand All @@ -48,13 +41,17 @@ def post_webhook(
requests.post(url=webhook_testing, json=webhook)
else:
changelog = get_changelog(project_dir, format="markdown")
webhook = get_webhook_release(changelog, download_url)
webhook = get_webhook_release(version_name, changelog, download_url)
requests.post(url=webhook_release, json=webhook)


def get_webhook_release(changelog: str, download_url: str):
def get_webhook_release(version_name: str, changelog: str, download_url: str):
(title, content) = changelog
return {"content": f"__**{title}**__\n{content}\n{download_url}"}
return {
"content": (
f"__**{title}**__\n{content}\n[Szkolny.eu {version_name}]({download_url})"
),
}


def get_webhook_testing(
Expand All @@ -73,9 +70,11 @@ def get_webhook_testing(
"fields": [
{
"name": f"Wersja `{version_name}`",
"value": f"[Pobierz .APK]({download_url})"
if download_url
else "*Pobieranie niedostępne*",
"value": (
f"[Pobierz .APK]({download_url})"
if download_url
else "*Pobieranie niedostępne*"
),
"inline": False,
},
{
Expand Down Expand Up @@ -103,16 +102,14 @@ def get_webhook_testing(

load_dotenv()
APK_FILE = os.getenv("APK_FILE")
APK_SERVER_RELEASE = os.getenv("APK_SERVER_RELEASE")
APK_SERVER_NIGHTLY = os.getenv("APK_SERVER_NIGHTLY")
DOWNLOAD_URL = os.getenv("DOWNLOAD_URL")
WEBHOOK_RELEASE = os.getenv("WEBHOOK_RELEASE")
WEBHOOK_TESTING = os.getenv("WEBHOOK_TESTING")

post_webhook(
project_dir,
APK_FILE,
APK_SERVER_RELEASE,
APK_SERVER_NIGHTLY,
DOWNLOAD_URL,
WEBHOOK_RELEASE,
WEBHOOK_TESTING,
)
Loading

0 comments on commit f2a20c3

Please sign in to comment.