Skip to content
Snippets Groups Projects
Commit 5f485eb6 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[scripts.ci] Fix package privacy tests on nightlies; Add integration tests for this new feature

parent 0ec480b6
No related branches found
No related tags found
1 merge request!221Fix package privacy tests on nightlies
Pipeline #51303 failed
...@@ -40,6 +40,43 @@ def is_master(refname, tag, repodir): ...@@ -40,6 +40,43 @@ def is_master(refname, tag, repodir):
return refname == "master" return refname == "master"
def is_private(baseurl, package):
"""Tells if a given package (with a namespace) is public or private
This function checks if a fully qualified package in the format
``<namespace>/<name>`` is publicly accessible. It does this by trying to
access ``info/refs?service=git-upload-pack`` from the package in question.
This method does **not** rely on the fact the user has access to Gitlab.
.. warning::
This method only works for fully qualified package names (i.e.,
containing at least one forward-slash ``/``).
Args:
baseurl: The base URL for the gitlab service to consult
package: Fully qualified (i.e., with a namespace) package name. For
example: ``bob/bob.extension``.
Returns: a boolean, indicating if the package is private (``True``) or not
(``False``).
"""
from urllib.error import HTTPError
from urllib.request import urlopen
private = True
try:
r = urlopen(baseurl + "/" + package + "/info/refs?service=git-upload-pack")
private = r.getcode() != 200
except HTTPError as e:
private = e.getcode() == 401
return private
def is_stable(package, refname, tag, repodir): def is_stable(package, refname, tag, repodir):
"""Determines if the package being published is stable. """Determines if the package being published is stable.
......
...@@ -14,6 +14,7 @@ from click_plugins import with_plugins ...@@ -14,6 +14,7 @@ from click_plugins import with_plugins
from ..build import comment_cleanup from ..build import comment_cleanup
from ..build import load_order_file from ..build import load_order_file
from ..ci import cleanup from ..ci import cleanup
from ..ci import is_private
from ..ci import read_packages from ..ci import read_packages
from ..ci import select_conda_build_config from ..ci import select_conda_build_config
from ..ci import select_conda_recipe_append from ..ci import select_conda_recipe_append
...@@ -667,8 +668,6 @@ def nightlies(ctx, order, dry_run): ...@@ -667,8 +668,6 @@ def nightlies(ctx, order, dry_run):
token = os.environ["CI_JOB_TOKEN"] token = os.environ["CI_JOB_TOKEN"]
from urllib.request import urlopen
import git import git
from .build import build from .build import build
...@@ -698,7 +697,10 @@ def nightlies(ctx, order, dry_run): ...@@ -698,7 +697,10 @@ def nightlies(ctx, order, dry_run):
) )
# determine package visibility # determine package visibility
private = urlopen("https://gitlab.idiap.ch/%s" % package).getcode() != 200 private = is_private("https://gitlab.idiap.ch", package)
private_str = "PRIVATE" if private else "PUBLIC"
logger.info('Package "%s" is %s', package, private_str)
stable = "STABLE" in os.environ stable = "STABLE" in os.environ
# Use custom variants and append files if available on recipe-dir # Use custom variants and append files if available on recipe-dir
......
#!/usr/bin/env python
# coding=utf-8
from .ci import is_private
def test_is_private():
base_url = "https://gitlab.idiap.ch"
assert not is_private(base_url, "bob/bob.extension")
assert is_private(base_url, "bob/private")
...@@ -55,6 +55,8 @@ requirements: ...@@ -55,6 +55,8 @@ requirements:
test: test:
requires: requires:
- sphinx_rtd_theme - sphinx_rtd_theme
- pytest
- pytest-cov
imports: imports:
- {{ name }} - {{ name }}
commands: commands:
...@@ -113,6 +115,7 @@ test: ...@@ -113,6 +115,7 @@ test:
- bdt sphinx --help - bdt sphinx --help
- bdt sphinx migrate-autodoc-flags --help - bdt sphinx migrate-autodoc-flags --help
- bdt gitlab alt-nightlies --help - bdt gitlab alt-nightlies --help
- pytest --capture=no --verbose --cov {{ name }} --cov-report term-missing --cov-report html:{{ project_dir }}/sphinx/coverage --cov-report xml:{{ project_dir }}/coverage.xml --pyargs {{ name }}
- sphinx-build -aEW ${PREFIX}/share/doc/{{ name }}/doc sphinx - sphinx-build -aEW ${PREFIX}/share/doc/{{ name }}/doc sphinx
{% if not os.path.exists('sphinx') %} {% if not os.path.exists('sphinx') %}
- if [ -n "${CI_PROJECT_DIR}" ]; then mv sphinx "${CI_PROJECT_DIR}/"; fi - if [ -n "${CI_PROJECT_DIR}" ]; then mv sphinx "${CI_PROJECT_DIR}/"; fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment