From aca98c1355e7bc38601d33d9c20f9d327fa76a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Wed, 24 Apr 2024 11:51:34 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=8F=20incorporate=20review=20feedback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/config.yml | 8 ++--- fdroidserver/deploy.py | 72 ++++++++++++++++++++++++++++-------------- tests/deploy.TestCase | 3 -- 3 files changed, 52 insertions(+), 31 deletions(-) diff --git a/examples/config.yml b/examples/config.yml index 3cfc17c5..45c9a2f7 100644 --- a/examples/config.yml +++ b/examples/config.yml @@ -212,19 +212,19 @@ # index_only: true -# These settings allows using `fdroid deploy` for publishing APK files from +# These settings allow using `fdroid deploy` for publishing APK files from # your repository to GitHub Releases. (You should also run `fdroid update` # every time before deploying to GitHub releases to update index files.) Here's # an example for this deployment automation: # https://github.com/f-droid/fdroidclient/releases/ # -# Currently versions which are assigned to a release channel (e.g. alpha or +# Currently, versions which are assigned to a release channel (e.g. alpha or # beta releases) are ignored. # -# In the examble below tokens are read from environment variables. Putting +# In the example below, tokens are read from environment variables. Putting # tokens directly into the config file is also supported but discouraged. It is # highly recommended to use a "Fine-grained personal access token", which is -# restriced to the minimum required permissions, which are: +# restricted to the minimum required permissions, which are: # * Metadata - read # * Contents - read/write # (https://github.com/settings/personal-access-tokens/new) diff --git a/fdroidserver/deploy.py b/fdroidserver/deploy.py index b8c0d711..4ca7dca9 100644 --- a/fdroidserver/deploy.py +++ b/fdroidserver/deploy.py @@ -1117,8 +1117,7 @@ def push_binary_transparency(git_repo_path, git_remote): def find_release_infos(index_v2_path, repo_dir, package_names): - """ - Find files, texts, etc. for uploading to a release page in index-v2.json. + """Find files, texts, etc. for uploading to a release page in index-v2.json. This function parses index-v2.json for file-paths elegible for deployment to release pages. (e.g. GitHub releases) It also groups these files by @@ -1137,19 +1136,16 @@ def find_release_infos(index_v2_path, repo_dir, package_names): for version in package.get('versions', {}).values(): if package_name not in release_infos: release_infos[package_name] = {} - ver_name = version['manifest']['versionName'] - apk_path = version['file']['name'] - if apk_path.startswith('/'): - apk_path = apk_path[1:] - apk_path = repo_dir / apk_path - files = [apk_path] - asc_path = pathlib.Path(str(apk_path) + '.asc') + version_name = version['manifest']['versionName'] + version_path = repo_dir / version['file']['name'].lstrip("/") + files = [version_path] + asc_path = pathlib.Path(str(version_path) + '.asc') if asc_path.is_file(): files.append(asc_path) - idsig_path = pathlib.Path(str(apk_path) + '.idsig') - if idsig_path.is_file(): - files.append(idsig_path) - release_infos[package_name][ver_name] = { + sig_path = pathlib.Path(str(version_path) + '.sig') + if sig_path.is_file(): + files.append(sig_path) + release_infos[package_name][version_name] = { 'files': files, 'whatsNew': version.get('whatsNew', {}).get("en-US"), 'hasReleaseChannels': len(version.get('releaseChannels', [])) > 0, @@ -1174,24 +1170,41 @@ def upload_to_github_releases(repo_section, gh_config, global_gh_token): for package_name in repo_conf.get('packages', []): package_names.append(package_name) - release_infos = fdroidserver.deploy.find_release_infos(index_v2_path, repo_dir, package_names) + release_infos = fdroidserver.deploy.find_release_infos( + index_v2_path, repo_dir, package_names + ) for repo_conf in gh_config: upload_to_github_releases_repo(repo_conf, release_infos, global_gh_token) def upload_to_github_releases_repo(repo_conf, release_infos, global_gh_token): - repo = repo_conf.get('repo') + repo = repo_conf.get("repo") if not repo: - logging.warning(_("One of the 'github_releases' config items is missing the 'repo' value. skipping ...")) + logging.warning( + _( + "One of the 'github_releases' config items is missing the " + "'repo' value. skipping ..." + ) + ) return - token = repo_conf.get('token') or global_gh_token + token = repo_conf.get("token") or global_gh_token if not token: - logging.warning(_("One of the 'github_releases' config itmes is missing the 'token' value. skipping ...")) + logging.warning( + _( + "One of the 'github_releases' config itmes is missing the " + "'token' value. skipping ..." + ) + ) return - packages = repo_conf.get('packages', []) + packages = repo_conf.get("packages", []) if not packages: - logging.warning(_("One of the 'github_releases' config itmes is missing the 'packages' value. skipping ...")) + logging.warning( + _( + "One of the 'github_releases' config itmes is missing the " + "'packages' value. skipping ..." + ) + ) return # lookup all versionNames (git tags) for all packages available in the @@ -1209,14 +1222,23 @@ def upload_to_github_releases_repo(repo_conf, release_infos, global_gh_token): # Making sure we're not uploading this version when releaseChannels # is set. (releaseChannels usually mean it's e.g. an alpha or beta # version) - if not release_infos.get(packages[0], {}).get(version, {}).get('hasReleaseChannels'): + if ( + not release_infos.get(packages[0], {}) + .get(version, {}) + .get('hasReleaseChannels') + ): # collect files associated with this github release files = [] for package in packages: - files.extend(release_infos.get(package, {}).get(version, {}).get('files', [])) + files.extend( + release_infos.get(package, {}).get(version, {}).get('files', []) + ) # always use the whatsNew text from the first app listed in # config.qml github_releases.packages - text = release_infos.get(packages[0], {}).get(version, {}).get('whatsNew') or '' + text = ( + release_infos.get(packages[0], {}).get(version, {}).get('whatsNew') + or '' + ) if 'release_notes_prepend' in repo_conf: text = repo_conf['release_notes_prepend'] + "\n\n" + text # create new release on github and upload all associated files @@ -1346,7 +1368,9 @@ def main(): if config.get('virustotal_apikey'): upload_to_virustotal(repo_section, config.get('virustotal_apikey')) if config.get('github_releases'): - upload_to_github_releases(repo_section, config.get('github_releases'), config.get('github_token')) + upload_to_github_releases( + repo_section, config.get('github_releases'), config.get('github_token') + ) binary_transparency_remote = config.get('binary_transparency_remote') if binary_transparency_remote: diff --git a/tests/deploy.TestCase b/tests/deploy.TestCase index 041f0eaf..2db73a02 100755 --- a/tests/deploy.TestCase +++ b/tests/deploy.TestCase @@ -1211,7 +1211,6 @@ class DeployTest(unittest.TestCase): class GitHubReleasesTest(unittest.TestCase): - def test_find_release_infos(self): self.maxDiff = None @@ -1331,7 +1330,6 @@ class GitHubReleasesTest(unittest.TestCase): ), unittest.mock.patch( "fdroidserver.deploy.upload_to_github_releases_repo", urr_mock ), tempfile.TemporaryDirectory() as tmpdir: - with open(Path(tmpdir) / "index-v2.json", "w") as f: f.write("") @@ -1370,7 +1368,6 @@ class GitHubReleasesTest(unittest.TestCase): class Test_UploadToGithubReleasesRepo(unittest.TestCase): - def setUp(self): self.repo_conf = { "repo": "example/app",