Skip to content
Snippets Groups Projects

Add initial version of ci-flatdeb-builder

Merged Ryan Gonzalez requested to merge wip/refi64/ci-flatdeb-builder into main
All threads resolved!
Files
7
+ 71
15
@@ -102,18 +102,51 @@ TestRepoBranch.__test__ = False # type: ignore
TestRepo.__test__ = False # type: ignore
def _ci_commit_ref_slug():
def _get_ci_commit_ref_slug():
ref_name = subprocess.run(
['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
stdout=subprocess.PIPE,
check=True,
text=True,
)
return re.sub('[^0-9A-Za-z]', '-', ref_name.stdout[:63])
).stdout.strip()
return re.sub('[^0-9A-Za-z]', '-', ref_name[:63])
def _get_origin_repo() -> yarl.URL:
SSH_RE = re.compile('(?P<user>[^@]+)@(?P<host>[^:]+):(?P<path>.*)')
url = subprocess.run(
['git', 'config', '--get', 'remote.origin.url'],
stdout=subprocess.PIPE,
check=True,
text=True,
).stdout.strip()
# Since we're building paths to the GitLab repo interface via this URL, make sure
# there's no .git suffix.
url = url.removesuffix('.git')
if match := SSH_RE.match(url):
return yarl.URL.build(
scheme='https',
host=match.group('host'),
path='/' + match.group('path'),
)
else:
return yarl.URL(url)
def _get_active_git_branch() -> str:
return subprocess.run(
['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
stdout=subprocess.PIPE,
check=True,
text=True,
).stdout.strip()
def pytest_addoption(parser: pytest.Parser):
slug = _ci_commit_ref_slug()
slug = _get_ci_commit_ref_slug()
parser.addoption(
'--gitlab-instance',
@@ -124,7 +157,6 @@ def pytest_addoption(parser: pytest.Parser):
parser.addoption(
'--gitlab-instance-url',
help='the GitLab instance URL to connect to (overrides --gitlab-instance)',
default='apertis',
)
parser.addoption(
'--gitlab-instance-token',
@@ -140,24 +172,29 @@ def pytest_addoption(parser: pytest.Parser):
parser.addoption(
'--runtimes-test-project',
help='the test repository containing flatdeb runtimes & apps',
default='refi64/ci-flatdeb-builder-runtimes',
default='tests/ci-flatdeb-builder-runtimes',
)
parser.addoption(
'--apps-test-project',
help='the test repository containing normal flatpak-builder apps',
default='refi64/ci-flatdeb-builder-apps',
default='tests/ci-flatdeb-builder-apps',
)
parser.addoption(
'--ci-config-url',
help='the URL to the CI config to test',
default='https://gitlab.apertis.org/refi64/ci-flatdeb-builder-test/-/raw/main/ci-flatdeb-builder.yaml',
'--ci-config-repo-url',
help='the GitLab URL to repository with the CI config to test',
default=_get_origin_repo(),
type=yarl.URL,
)
parser.addoption(
'--authenticate-ci-config-url',
help='authenticate ci-config-url for accessing private repos',
'--ci-config-repo-use-authentication',
help='authenticate access to ci-config-repo (use this if it is private)',
action='store_true',
)
parser.addoption(
'--ci-config-repo-revision',
help='the revision of ci-config-repo to use',
default=_get_active_git_branch(),
)
parser.addoption(
'--remote-url',
help='URL where build artifacts will be downloaded from',
@@ -205,16 +242,35 @@ def apps_test_project(request) -> str:
@pytest.fixture(scope='session')
def ci_config_url(request) -> yarl.URL:
url: yarl.URL = request.config.option.ci_config_url
def ci_config_repo_url(request) -> yarl.URL:
url: yarl.URL = request.config.option.ci_config_repo_url
if request.config.option.authenticate_ci_config_url:
if request.config.option.ci_config_repo_use_authentication:
token = request.config.option.gitlab_instance_token
url = url.with_user('oauth2').with_password(token)
return url
@pytest.fixture(scope='session')
def ci_config_repo_revision(request) -> str:
return request.config.option.ci_config_repo_revision
@pytest.fixture(scope='session')
def ci_config_file_url(
ci_config_repo_url: yarl.URL,
ci_config_repo_revision: str,
) -> yarl.URL:
return (
ci_config_repo_url
/ '-'
/ 'raw'
/ ci_config_repo_revision
/ 'ci-flatdeb-builder.yaml'
)
@pytest.fixture(scope='session')
def remote_url(request) -> yarl.URL:
print(request.config.option.remote_url)
Loading