-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgradle-release-checksums.py
More file actions
executable file
·137 lines (125 loc) · 4.78 KB
/
gradle-release-checksums.py
File metadata and controls
executable file
·137 lines (125 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
#
# Create a merge request to fdroid/fdroidserver with new
# version/checksum info. This assumes that the transparency log process
# ran and found new info.
import git
import json
import os
import re
from colorama import Fore, Style
from packaging.version import Version
with open('../checksums.json', encoding='utf8') as fp:
checksums = json.load(fp)
versions = dict()
gradle_bin_pat = re.compile(r'gradle-([0-9][0-9.]+[0-9])-bin.zip')
for url, d in checksums.items():
m = gradle_bin_pat.search(url)
if m:
versions[m.group(1)] = d[0]['sha256']
errors = 0
makebuildserver = os.path.join(os.getcwd(), 'makebuildserver')
with open(makebuildserver, encoding='utf8') as fp:
makebuildserver_current = fp.read()
to_compile = re.search(r'CACHE_FILES = [^\]]+\]', makebuildserver_current).group()
code = compile(to_compile, makebuildserver, 'exec')
config = {}
exec(code, None, config) # nosec this is just a CI script pylint: disable=exec-used
makebuildserver_versions = []
version_pat = re.compile(r'[0-9]+(\.[0-9]+)+')
for url, checksum in config['CACHE_FILES']:
if 'gradle.org' in url:
m = version_pat.search(url.split('/')[-1])
if m:
makebuildserver_versions.append(m.group())
if checksum != versions[m.group()]:
print(
Fore.RED + 'ERROR: checksum mismatch:',
checksum,
versions[m.group()] + Style.RESET_ALL,
)
errors += 1
# error if makebuildserver is missing the latest version
for version in sorted(versions.keys()):
if version not in makebuildserver_versions and Version(version) > Version(
sorted(makebuildserver_versions)[-1]
):
add_before = """ ('https://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin',"""
new = to_compile.replace(
add_before,
" ('https://services.gradle.org/distributions/gradle-"
+ version
+ "-bin.zip',\n"
" '" + versions[version] + "'),\n" + add_before,
)
makebuildserver_current = makebuildserver_current.replace(to_compile, new)
with open(makebuildserver, 'w', encoding='utf8') as fp:
fp.write(makebuildserver_current)
# write out update to gradlew-fdroid
with open('gradlew-fdroid', encoding='utf8') as fp:
gradlew_fdroid = fp.read()
current = ''
get_sha_pat = re.compile(r""" +'([0-9][0-9.]+[0-9])'\)\s+echo '([0-9a-f]{64})' ;;\n""")
for m in get_sha_pat.finditer(gradlew_fdroid):
current += m.group()
checksum = m.group(2)
if checksum != versions[m.group(1)]:
print(
Fore.RED + 'ERROR: checksum mismatch:',
checksum,
versions[m.group(1)] + Style.RESET_ALL,
)
errors += 1
new = ''
for version in sorted(versions.keys(), key=Version):
sha256 = versions[version]
spaces = ''
for i in range(6 - len(version)):
spaces += ' '
new += f""" '{version}'){spaces} echo '{sha256}' ;;\n"""
gradlew_fdroid = gradlew_fdroid.replace(current, new)
plugin_v = ' '.join(sorted(versions.keys(), key=Version, reverse=True))
plugin_v_pat = re.compile(r'\nplugin_v=\(([0-9. ]+)\)')
with open('gradlew-fdroid', 'w', encoding='utf8') as fp:
fp.write(plugin_v_pat.sub(f'\nplugin_v=({plugin_v})', gradlew_fdroid))
git_repo = git.repo.Repo('.')
branch = git_repo.create_head(os.path.basename(__file__), force=True)
branch.checkout()
git_repo.index.add(['gradlew-fdroid', 'makebuildserver'])
author = git.Actor('fdroid-bot', 'fdroid-bot@f-droid.org')
git_repo.index.commit('gradle v' + version, author=author)
ci_job_id = os.getenv('CI_JOB_ID')
description = (
'see <https://gitlab.com/fdroid/gradle-transparency-log/-/blob/master/checksums.json>'
f"""<br><p><small>generated by <a href="{os.getenv('CI_PROJECT_URL')}/-/jobs/{ci_job_id}">GitLab CI Job #{ci_job_id}</a></small></p>"""
)
push_options = [
'merge_request.create',
'merge_request.remove_source_branch',
f'merge_request.title=bot: update to gradle v{version}',
f'merge_request.description={description}',
]
progress = git.RemoteProgress()
remote = git.remote.Remote(git_repo, 'origin')
pushinfos = remote.push(
branch.name,
progress=progress,
force=True,
set_upstream=True,
push_option=push_options,
)
for pushinfo in pushinfos:
print(pushinfo.summary)
# Show potentially useful messages from git remote
if progress:
for line in progress.other_lines:
print(line)
if pushinfo.flags & (
git.remote.PushInfo.ERROR
| git.remote.PushInfo.REJECTED
| git.remote.PushInfo.REMOTE_FAILURE
| git.remote.PushInfo.REMOTE_REJECTED
):
print(f'{remote.url} push failed: {pushinfo.flags} {pushinfo.summary}')
else:
print(remote.url + ': ' + pushinfo.summary)