nightly: update Raw URLs to fix breakage and avoid redirects

This commit is contained in:
Hans-Christoph Steiner 2022-08-26 07:18:19 +00:00 committed by Jochen Sprickerhof
parent b352e9a9cc
commit c6cf0468ed
2 changed files with 72 additions and 5 deletions

View File

@ -131,6 +131,17 @@ def _ssh_key_from_debug_keystore(keystore=KEYSTORE_FILE):
return ssh_private_key_file
def get_repo_base_url(clone_url, repo_git_base, force_type=None):
if force_type is None:
force_type = urlparse(clone_url).netloc
if force_type == 'gitlab.com':
return clone_url + '/-/raw/master/fdroid'
if force_type == 'github.com':
return 'https://raw.githubusercontent.com/%s/master/fdroid' % repo_git_base
print(_('ERROR: unsupported git host "%s", patches welcome!') % force_type)
sys.exit(1)
def main():
parser = ArgumentParser()
@ -200,11 +211,12 @@ def main():
cibase = os.getcwd()
os.makedirs(repodir, exist_ok=True)
# the 'master' branch is hardcoded in fdroidserver/deploy.py
if 'CI_PROJECT_PATH' in os.environ and 'CI_PROJECT_URL' in os.environ:
# we are in GitLab CI
repo_git_base = os.getenv('CI_PROJECT_PATH') + NIGHTLY
clone_url = os.getenv('CI_PROJECT_URL') + NIGHTLY
repo_base = clone_url + '/raw/master/fdroid'
repo_base = get_repo_base_url(clone_url, repo_git_base, force_type='gitlab.com')
servergitmirror = 'git@' + urlparse(clone_url).netloc + ':' + repo_git_base
deploy_key_url = clone_url + '/-/settings/repository#js-deploy-keys-settings'
git_user_name = os.getenv('GITLAB_USER_NAME')
@ -213,8 +225,7 @@ def main():
# we are in Travis CI
repo_git_base = os.getenv('TRAVIS_REPO_SLUG') + NIGHTLY
clone_url = 'https://github.com/' + repo_git_base
_branch = os.getenv('TRAVIS_BRANCH')
repo_base = 'https://raw.githubusercontent.com/' + repo_git_base + '/' + _branch + '/fdroid'
repo_base = get_repo_base_url(clone_url, repo_git_base, force_type='github.com')
servergitmirror = 'git@github.com:' + repo_git_base
deploy_key_url = ('https://github.com/' + repo_git_base + '/settings/keys'
+ '\nhttps://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys')
@ -229,7 +240,7 @@ def main():
repo_git_base = (os.getenv('CIRCLE_PROJECT_USERNAME')
+ '/' + os.getenv('CIRCLE_PROJECT_REPONAME') + NIGHTLY)
clone_url = os.getenv('CIRCLE_REPOSITORY_URL') + NIGHTLY
repo_base = clone_url + '/raw/master/fdroid'
repo_base = get_repo_base_url(clone_url, repo_git_base, force_type='github.com')
servergitmirror = 'git@' + urlparse(clone_url).netloc + ':' + repo_git_base
deploy_key_url = ('https://github.com/' + repo_git_base + '/settings/keys'
+ '\nhttps://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys')
@ -239,7 +250,7 @@ def main():
# we are in Github actions
repo_git_base = (os.getenv('GITHUB_REPOSITORY') + NIGHTLY)
clone_url = (os.getenv('GITHUB_SERVER_URL') + '/' + repo_git_base)
repo_base = clone_url + '/raw/master/fdroid'
repo_base = get_repo_base_url(clone_url, repo_git_base, force_type='github.com')
servergitmirror = 'git@' + urlparse(clone_url).netloc + ':' + repo_git_base
deploy_key_url = ('https://github.com/' + repo_git_base + '/settings/keys'
+ '\nhttps://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys')

56
tests/nightly.TestCase Executable file
View File

@ -0,0 +1,56 @@
#!/usr/bin/env python3
import inspect
import optparse
import os
import requests
import sys
import unittest
localmodule = os.path.realpath(
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
)
print('localmodule: ' + localmodule)
if localmodule not in sys.path:
sys.path.insert(0, localmodule)
from fdroidserver import common, nightly
class NightlyTest(unittest.TestCase):
def test_get_repo_base_url(self):
for clone_url, repo_git_base, result in [
(
'https://github.com/onionshare/onionshare-android-nightly',
'onionshare/onionshare-android-nightly',
'https://raw.githubusercontent.com/onionshare/onionshare-android-nightly/master/fdroid',
),
(
'https://gitlab.com/fdroid/fdroidclient-nightly',
'fdroid/fdroidclient-nightly',
'https://gitlab.com/fdroid/fdroidclient-nightly/-/raw/master/fdroid',
),
]:
url = nightly.get_repo_base_url(clone_url, repo_git_base)
self.assertEqual(result, url)
r = requests.head(os.path.join(url, 'repo/index-v1.jar'))
# gitlab.com often returns 403 Forbidden from their cloudflare restrictions
self.assertTrue(r.status_code in (200, 403), 'should not be a redirect')
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__))
parser = optparse.OptionParser()
parser.add_option(
"-v",
"--verbose",
action="store_true",
default=False,
help="Spew out even more information than normal",
)
(common.options, args) = parser.parse_args(['--verbose'])
newSuite = unittest.TestSuite()
newSuite.addTest(unittest.makeSuite(NightlyTest))
unittest.main(failfast=False)