mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-04 14:30:30 +03:00
feat: add servergitmirrors as a dict support
This commit is contained in:
parent
12692b76b7
commit
947217549a
10 changed files with 118 additions and 22 deletions
|
|
@ -300,6 +300,86 @@ class DeployTest(unittest.TestCase):
|
|||
name, fdroidserver.deploy.REMOTE_HOSTNAME_REGEX.sub(r'\1', remote_url)
|
||||
)
|
||||
|
||||
def test_update_servergitmirrors(self):
|
||||
# setup parameters for this test run
|
||||
fdroidserver.deploy.options = mock.Mock()
|
||||
fdroidserver.deploy.options.identity_file = None
|
||||
fdroidserver.deploy.options.no_keep_git_mirror_archive = False
|
||||
fdroidserver.deploy.options.verbose = False
|
||||
fdroidserver.deploy.options.quiet = True
|
||||
fdroidserver.deploy.options.index_only = False
|
||||
|
||||
config = {}
|
||||
fdroidserver.common.fill_config_defaults(config)
|
||||
fdroidserver.deploy.config = config
|
||||
fdroidserver.deploy.config["servergitmirrors"] = []
|
||||
|
||||
repo_section = 'repo'
|
||||
|
||||
# setup function for asserting subprocess.call invocations
|
||||
update_servergitmirrors_call_iteration = 0
|
||||
remote_push_call_iteration = 0
|
||||
|
||||
os.chdir(self.testdir)
|
||||
repo = Path('repo')
|
||||
repo.mkdir(parents=True)
|
||||
fake_apk = repo / 'Sym.apk'
|
||||
with fake_apk.open('w') as fp:
|
||||
fp.write('not an APK, but has the right filename')
|
||||
fake_index = repo / fdroidserver.deploy.INDEX_FILES[0]
|
||||
with fake_index.open('w') as fp:
|
||||
fp.write('not an index, but has the right filename')
|
||||
|
||||
def update_servergitmirrors_call(cmd):
|
||||
nonlocal update_servergitmirrors_call_iteration
|
||||
if update_servergitmirrors_call_iteration == 0:
|
||||
self.assertListEqual(
|
||||
cmd,
|
||||
[
|
||||
'rsync',
|
||||
'--recursive',
|
||||
'--safe-links',
|
||||
'--times',
|
||||
'--perms',
|
||||
'--one-file-system',
|
||||
'--delete',
|
||||
'--chmod=Da+rx,Fa-x,a+r,u+w',
|
||||
'--quiet',
|
||||
'repo/',
|
||||
"git-mirror/fdroid/repo/",
|
||||
],
|
||||
)
|
||||
else:
|
||||
self.fail('unexpected subprocess.call invocation')
|
||||
update_servergitmirrors_call_iteration += 1
|
||||
return 0
|
||||
|
||||
def remote_push_call(ref, force=False, set_upstream=False, **_args):
|
||||
nonlocal remote_push_call_iteration
|
||||
if remote_push_call_iteration == 0:
|
||||
self.assertEqual([ref, force, set_upstream], ['master', True, True])
|
||||
else:
|
||||
self.fail('unexpected git.Remote.push invocation')
|
||||
remote_push_call_iteration += 1
|
||||
return []
|
||||
|
||||
with mock.patch('subprocess.call', side_effect=update_servergitmirrors_call):
|
||||
with mock.patch(
|
||||
'git.Remote.push', side_effect=remote_push_call
|
||||
) as mock_remote_push:
|
||||
mock_remote_push.return_value = []
|
||||
fdroidserver.deploy.update_servergitmirrors(
|
||||
[{'url': 'https://github.com/user/repo'}], repo_section
|
||||
)
|
||||
self.assertEqual(
|
||||
update_servergitmirrors_call_iteration,
|
||||
1,
|
||||
'expected 1 invocations of subprocess.call',
|
||||
)
|
||||
self.assertEqual(
|
||||
remote_push_call_iteration, 1, 'expected 1 invocations of git.Remote.push'
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.chdir(os.path.dirname(__file__))
|
||||
|
|
|
|||
|
|
@ -575,7 +575,7 @@ class IndexTest(unittest.TestCase):
|
|||
]:
|
||||
self.assertEqual(
|
||||
['https://raw.githubusercontent.com/foo/bar/master/fdroid'],
|
||||
index.get_mirror_service_urls(url),
|
||||
index.get_mirror_service_urls({"url": url}),
|
||||
)
|
||||
|
||||
@patch.dict(os.environ, clear=True)
|
||||
|
|
@ -603,13 +603,13 @@ class IndexTest(unittest.TestCase):
|
|||
]
|
||||
self.assertEqual(
|
||||
expected,
|
||||
index.get_mirror_service_urls(url),
|
||||
index.get_mirror_service_urls({"url": url}),
|
||||
)
|
||||
with patch.dict(os.environ, clear=True):
|
||||
os.environ['CI_JOB_ID'] = ci_job_id
|
||||
self.assertEqual(
|
||||
expected + [artifacts_url],
|
||||
index.get_mirror_service_urls(url),
|
||||
index.get_mirror_service_urls({"url": url}),
|
||||
)
|
||||
with patch('fdroidserver.common.GITLAB_COM_PAGES_MAX_SIZE', 10):
|
||||
expected = [
|
||||
|
|
@ -617,13 +617,13 @@ class IndexTest(unittest.TestCase):
|
|||
]
|
||||
self.assertEqual(
|
||||
expected,
|
||||
index.get_mirror_service_urls(url),
|
||||
index.get_mirror_service_urls({"url": url}),
|
||||
)
|
||||
with patch.dict(os.environ, clear=True):
|
||||
os.environ['CI_JOB_ID'] = ci_job_id
|
||||
self.assertEqual(
|
||||
expected + [artifacts_url],
|
||||
index.get_mirror_service_urls(url),
|
||||
index.get_mirror_service_urls({"url": url}),
|
||||
)
|
||||
|
||||
def test_make_website(self):
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ class NightlyTest(unittest.TestCase):
|
|||
self.assertEqual(called, [['ssh', '-Tvi'], ['fdroid', 'deploy']])
|
||||
self.assertFalse(os.path.exists('config.py'))
|
||||
git_url = 'git@github.com:f-droid/test-nightly'
|
||||
mirror_url = index.get_mirror_service_urls(git_url)[0]
|
||||
mirror_url = index.get_mirror_service_urls({"url": git_url})[0]
|
||||
expected = {
|
||||
'archive_description': 'Old nightly builds that have been archived.',
|
||||
'archive_name': 'f-droid/test-nightly archive',
|
||||
|
|
@ -271,7 +271,7 @@ class NightlyTest(unittest.TestCase):
|
|||
'repo_keyalias': 'androiddebugkey',
|
||||
'repo_name': 'f-droid/test-nightly',
|
||||
'repo_url': mirror_url + '/repo',
|
||||
'servergitmirrors': git_url,
|
||||
'servergitmirrors': [{"url": git_url}],
|
||||
'update_stats': True,
|
||||
}
|
||||
with open('config.yml') as fp:
|
||||
|
|
@ -344,7 +344,7 @@ class NightlyTest(unittest.TestCase):
|
|||
'repo_keyalias': 'androiddebugkey',
|
||||
'repo_name': 'fdroid/test-nightly',
|
||||
'repo_url': 'https://gitlab.com/fdroid/test-nightly/-/raw/master/fdroid/repo',
|
||||
'servergitmirrors': 'git@gitlab.com:fdroid/test-nightly',
|
||||
'servergitmirrors': [{"url": 'git@gitlab.com:fdroid/test-nightly'}],
|
||||
'update_stats': True,
|
||||
}
|
||||
with open('config.yml') as fp:
|
||||
|
|
|
|||
|
|
@ -1154,7 +1154,7 @@ GIT_MIRROR=$REPOROOT/git-mirror
|
|||
cd $REPOROOT
|
||||
fdroid_init_with_prebuilt_keystore
|
||||
printf '\narchive_older: 3\n' >> config.yml
|
||||
echo "servergitmirrors: $SERVER_GIT_MIRROR" >> config.yml
|
||||
printf "servergitmirrors: $SERVER_GIT_MIRROR\n" >> config.yml
|
||||
|
||||
cp $WORKSPACE/tests/repo/com.politedroid_[345].apk repo/
|
||||
$fdroid update --create-metadata
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue