1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-19 21:30:10 +01:00

deploy: support GitLab Job Artifacts as a mirror

This commit is contained in:
Hans-Christoph Steiner 2022-11-15 14:37:08 +01:00
parent d0976a3684
commit 947d94e0a9
No known key found for this signature in database
GPG Key ID: 3E177817BA1B9BFA
2 changed files with 47 additions and 7 deletions

View File

@ -1453,6 +1453,26 @@ def get_mirror_service_urls(url):
# GitLab Raw "https://gitlab.com/user/repo/-/raw/branch/folder" # GitLab Raw "https://gitlab.com/user/repo/-/raw/branch/folder"
gitlab_raw = segments + ['-', 'raw', branch, folder] gitlab_raw = segments + ['-', 'raw', branch, folder]
urls.append('/'.join(gitlab_raw)) urls.append('/'.join(gitlab_raw))
# GitLab Artifacts "https://user.gitlab.io/-/repo/-/jobs/job_id/artifacts/public/folder"
job_id = os.getenv('CI_JOB_ID')
try:
int(job_id)
gitlab_artifacts = [
"https:",
"",
user + ".gitlab.io",
'-',
repo,
'-',
'jobs',
job_id,
'artifacts',
'public',
folder,
]
urls.append('/'.join(gitlab_artifacts))
except (TypeError, ValueError):
pass # no Job ID to use, ignore
return urls return urls

View File

@ -414,10 +414,16 @@ class IndexTest(unittest.TestCase):
fdroidserver.index.get_mirror_service_urls(url), fdroidserver.index.get_mirror_service_urls(url),
) )
@patch.dict(os.environ, clear=True)
def test_gitlab_get_mirror_service_urls(self): def test_gitlab_get_mirror_service_urls(self):
with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir): with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
git_mirror_path = Path('git-mirror/fdroid') git_mirror_path = Path('git-mirror/fdroid')
git_mirror_path.mkdir(parents=True) git_mirror_path.mkdir(parents=True)
ci_job_id = '12345678'
artifacts_url = (
'https://group.gitlab.io/-/project/-/jobs/%s/artifacts/public/fdroid'
% ci_job_id
)
with (git_mirror_path / 'placeholder').open('w') as fp: with (git_mirror_path / 'placeholder').open('w') as fp:
fp.write(' ') fp.write(' ')
for url in [ for url in [
@ -427,18 +433,32 @@ class IndexTest(unittest.TestCase):
'https://gitlab.com/group/project.git', 'https://gitlab.com/group/project.git',
]: ]:
with patch('fdroidserver.common.GITLAB_COM_PAGES_MAX_SIZE', 1000): with patch('fdroidserver.common.GITLAB_COM_PAGES_MAX_SIZE', 1000):
self.assertEqual( expected = [
[
'https://group.gitlab.io/project/fdroid', 'https://group.gitlab.io/project/fdroid',
'https://gitlab.com/group/project/-/raw/master/fdroid', 'https://gitlab.com/group/project/-/raw/master/fdroid',
], ]
self.assertEqual(
expected,
fdroidserver.index.get_mirror_service_urls(url),
)
with patch.dict(os.environ, clear=True):
os.environ['CI_JOB_ID'] = ci_job_id
self.assertEqual(
expected + [artifacts_url],
fdroidserver.index.get_mirror_service_urls(url), fdroidserver.index.get_mirror_service_urls(url),
) )
with patch('fdroidserver.common.GITLAB_COM_PAGES_MAX_SIZE', 10): with patch('fdroidserver.common.GITLAB_COM_PAGES_MAX_SIZE', 10):
self.assertEqual( expected = [
[
'https://gitlab.com/group/project/-/raw/master/fdroid', 'https://gitlab.com/group/project/-/raw/master/fdroid',
], ]
self.assertEqual(
expected,
fdroidserver.index.get_mirror_service_urls(url),
)
with patch.dict(os.environ, clear=True):
os.environ['CI_JOB_ID'] = ci_job_id
self.assertEqual(
expected + [artifacts_url],
fdroidserver.index.get_mirror_service_urls(url), fdroidserver.index.get_mirror_service_urls(url),
) )