Skip to content

Commit 32549da

Browse files
committed
[Actions] Refactor build workflows, fix Gradle rename task
1 parent 0823e72 commit 32549da

17 files changed

+348
-499
lines changed

Diff for: .github/utils/_utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ def get_commit_log(project_dir: str, format: str, max_lines: int = None) -> str:
102102
)
103103

104104
log = subprocess.run(
105-
args=f"git log {last_tag}..HEAD --format=%an%x00%at%x00%h%x00%s%x00%D".split(" "),
105+
args=f"git log {last_tag}..HEAD --format=%an%x00%at%x00%h%x00%s%x00%D".split(
106+
" "
107+
),
106108
cwd=project_dir,
107109
stdout=subprocess.PIPE,
108110
)

Diff for: .github/utils/bump_nightly.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import json
21
import os
32
import re
43
import sys
54
from datetime import datetime, timedelta
65

7-
import requests
8-
96
from _utils import (
107
get_commit_log,
118
get_project_dir,
@@ -25,17 +22,6 @@
2522
print("Missing GitHub environment variables.")
2623
exit(-1)
2724

28-
with requests.get(
29-
f"https://api.github.com/repos/{repo}/actions/runs?per_page=5&status=success"
30-
) as r:
31-
data = json.loads(r.text)
32-
runs = [run for run in data["workflow_runs"] if run["head_sha"] == sha]
33-
if runs:
34-
print("::set-output name=hasNewChanges::false")
35-
exit(0)
36-
37-
print("::set-output name=hasNewChanges::true")
38-
3925
project_dir = get_project_dir()
4026

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

51-
print("::set-output name=appVersionName::" + version_name)
52-
print("::set-output name=appVersionCode::" + str(version_code))
37+
print("appVersionName=" + version_name)
38+
print("appVersionCode=" + str(version_code))
5339

5440
write_gradle_version(project_dir, version_code, version_name)
5541

Diff for: .github/utils/check_nightly.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import json
2+
import os
3+
4+
import requests
5+
6+
if __name__ == "__main__":
7+
repo = os.getenv("GITHUB_REPOSITORY")
8+
sha = os.getenv("GITHUB_SHA")
9+
10+
if not repo or not sha:
11+
print("Missing GitHub environment variables.")
12+
exit(-1)
13+
14+
with requests.get(
15+
f"https://api.github.com/repos/{repo}/actions/runs?per_page=5&status=success"
16+
) as r:
17+
data = json.loads(r.text)
18+
runs = [run for run in data["workflow_runs"] if run["head_sha"] == sha]
19+
if runs:
20+
print("hasNewChanges=false")
21+
exit(0)
22+
23+
print("hasNewChanges=true")

Diff for: .github/utils/extract_changelogs.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
(version_code, version_name) = read_gradle_version(project_dir)
1414

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

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

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

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

@@ -27,9 +27,9 @@
2727
f.write(title)
2828
f.write("\n")
2929
f.write(changelog)
30-
print("::set-output name=changelogPlainTitledFile::" + dir + "whatsnew_titled.txt")
30+
print("changelogPlainTitledFile=" + dir + "whatsnew_titled.txt")
3131

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

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

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

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

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

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

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

6968
changelog = get_commit_log(project_dir, format="html", max_lines=10)
7069
with open(dir + "commit_log.html", "w", encoding="utf-8") as f:
7170
f.write(changelog)
72-
print("::set-output name=commitLogHtmlFile::" + dir + "commit_log.html")
71+
print("commitLogHtmlFile=" + dir + "commit_log.html")

Diff for: .github/utils/rename_artifacts.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
files = glob.glob(f"{project_dir}/app/release/*.*")
1515
for file in files:
16-
file_relative = file.replace(os.getenv("GITHUB_WORKSPACE") + "/", "")
16+
file_relative = file.replace(sys.argv[1] + "/", "")
1717
if "-aligned.apk" in file:
1818
os.unlink(file)
1919
elif "-signed.apk" in file:
@@ -22,5 +22,5 @@
2222
os.unlink(new_file)
2323
os.rename(file, new_file)
2424
elif ".apk" in file or ".aab" in file:
25-
print("::set-output name=signedReleaseFile::" + file)
26-
print("::set-output name=signedReleaseFileRelative::" + file_relative)
25+
print("signedReleaseFile=" + file)
26+
print("signedReleaseFileRelative=" + file_relative)

Diff for: .github/utils/save_version.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ def save_version(
6464
if build_type in ["nightly", "daily"]:
6565
download_url = apk_server_nightly + apk_name if apk_name else None
6666
else:
67-
download_url = apk_server_release + apk_name if apk_name else None
67+
# download_url = apk_server_release + apk_name if apk_name else None
68+
download_url = (
69+
f"https://github.com/szkolny-eu/szkolny-android/releases/download/v{version_name}/{apk_name}"
70+
if apk_name
71+
else None
72+
)
73+
if download_url:
74+
print("downloadUrl=" + download_url)
6875

6976
cols = [
7077
"versionCode",
@@ -119,4 +126,12 @@ def save_version(
119126
APK_SERVER_RELEASE = os.getenv("APK_SERVER_RELEASE")
120127
APK_SERVER_NIGHTLY = os.getenv("APK_SERVER_NIGHTLY")
121128

122-
save_version(project_dir, DB_HOST, DB_USER, DB_PASS, DB_NAME, APK_SERVER_RELEASE, APK_SERVER_NIGHTLY)
129+
save_version(
130+
project_dir,
131+
DB_HOST,
132+
DB_USER,
133+
DB_PASS,
134+
DB_NAME,
135+
APK_SERVER_RELEASE,
136+
APK_SERVER_NIGHTLY,
137+
)

Diff for: .github/utils/sign.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def sign(
7171
version_name, version_code, DB_HOST, DB_USER, DB_PASS, DB_NAME
7272
)
7373

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

7777
sign(
7878
project_dir,

Diff for: .github/utils/webhook_discord.py

+15-18
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
def post_webhook(
1212
project_dir: str,
1313
apk_file: str,
14-
apk_server_release: str,
15-
apk_server_nightly: str,
14+
download_url: str,
1615
webhook_release: str,
1716
webhook_testing: str,
1817
):
@@ -25,12 +24,6 @@ def post_webhook(
2524
testing = ["dev", "beta", "nightly", "daily"]
2625
testing = build_type in testing
2726

28-
apk_name = os.path.basename(apk_file)
29-
if build_type in ["nightly", "daily"]:
30-
download_url = apk_server_nightly + apk_name
31-
else:
32-
download_url = apk_server_release + apk_name
33-
3427
if testing:
3528
build_date = int(os.stat(apk_file).st_mtime)
3629
if build_date:
@@ -48,13 +41,17 @@ def post_webhook(
4841
requests.post(url=webhook_testing, json=webhook)
4942
else:
5043
changelog = get_changelog(project_dir, format="markdown")
51-
webhook = get_webhook_release(changelog, download_url)
44+
webhook = get_webhook_release(version_name, changelog, download_url)
5245
requests.post(url=webhook_release, json=webhook)
5346

5447

55-
def get_webhook_release(changelog: str, download_url: str):
48+
def get_webhook_release(version_name: str, changelog: str, download_url: str):
5649
(title, content) = changelog
57-
return {"content": f"__**{title}**__\n{content}\n{download_url}"}
50+
return {
51+
"content": (
52+
f"__**{title}**__\n{content}\n[Szkolny.eu {version_name}]({download_url})"
53+
),
54+
}
5855

5956

6057
def get_webhook_testing(
@@ -73,9 +70,11 @@ def get_webhook_testing(
7370
"fields": [
7471
{
7572
"name": f"Wersja `{version_name}`",
76-
"value": f"[Pobierz .APK]({download_url})"
77-
if download_url
78-
else "*Pobieranie niedostępne*",
73+
"value": (
74+
f"[Pobierz .APK]({download_url})"
75+
if download_url
76+
else "*Pobieranie niedostępne*"
77+
),
7978
"inline": False,
8079
},
8180
{
@@ -103,16 +102,14 @@ def get_webhook_testing(
103102

104103
load_dotenv()
105104
APK_FILE = os.getenv("APK_FILE")
106-
APK_SERVER_RELEASE = os.getenv("APK_SERVER_RELEASE")
107-
APK_SERVER_NIGHTLY = os.getenv("APK_SERVER_NIGHTLY")
105+
DOWNLOAD_URL = os.getenv("DOWNLOAD_URL")
108106
WEBHOOK_RELEASE = os.getenv("WEBHOOK_RELEASE")
109107
WEBHOOK_TESTING = os.getenv("WEBHOOK_TESTING")
110108

111109
post_webhook(
112110
project_dir,
113111
APK_FILE,
114-
APK_SERVER_RELEASE,
115-
APK_SERVER_NIGHTLY,
112+
DOWNLOAD_URL,
116113
WEBHOOK_RELEASE,
117114
WEBHOOK_TESTING,
118115
)

0 commit comments

Comments
 (0)