Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions lib/testmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.

import fnmatch
import itertools
import os.path
from collections.abc import Iterable, Mapping, Sequence

from lib.constants import TEST_OS_DEFAULT
Expand Down Expand Up @@ -331,12 +331,12 @@ def projects() -> Iterable[str]:


def get_default_branch(repo: str) -> str:
"""Get the default branch. Currently this is always 'main' but it might
change if we add repositories with a branch like 'devel' or so."""
branches = REPO_BRANCH_CONTEXT[repo]
if 'main' in branches:
return 'main'
if 'master' in branches:
return 'master'
raise ValueError(f"repo {repo} does not contain main or master branch")
raise ValueError(f"repo {repo} does not contain main branch")


def tests_for_project(project: str) -> Mapping[str, Sequence[str]]:
Expand Down Expand Up @@ -374,6 +374,24 @@ def tests_for_image(image: str) -> Sequence[str]:
return list(tests)


def tests_for_fnmatch(pattern: str) -> Sequence[str]:
"""Return all contexts which match the given pattern."""

# Iterate all scenarios on all repositories, excluding _manual
tests = set()
for repo, branch_contexts in REPO_BRANCH_CONTEXT.items():
for branch, contexts in branch_contexts.items():
if branch.startswith('_'):
continue
for context in contexts:
c = context + '@' + repo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like you say this probably isn't right. I think this should work on the target repository so when I do

./tests-trigger --repo cockpit-project/cockpit 22330 '*/networking'

I'd like to trigger all images that run cockpit tests and their /networking scenario

if branch != get_default_branch(repo):
c += "/" + branch
tests.add(c)

return [test for test in tests if fnmatch.fnmatch(test, pattern)]


def tests_for_po_refresh(project: str) -> Sequence[str]:
# by default, run all tests
contexts = REPO_BRANCH_CONTEXT.get(project, {}).get(get_default_branch(project), [])
Expand Down
7 changes: 5 additions & 2 deletions tests-trigger
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def trigger_pull(api: github.GitHub, opts: argparse.Namespace) -> int:
if opts.context:
contexts = set[str]()
for cntx in opts.context:
if cntx.startswith("image:"):
if '*' or '?' in cntx:
contexts.update(testmap.tests_for_fnmatch(cntx))
elif cntx.startswith("image:"):
contexts.update(testmap.tests_for_image(cntx.split(':', 1)[1]))
elif testmap.is_valid_context(cntx, api.repo):
if opts.bots_pr:
Expand Down Expand Up @@ -99,7 +101,8 @@ def main() -> int:
parser.add_argument('target', help='The pull request number to trigger, '
'or - for the upstream of the current branch')
parser.add_argument('context', nargs='*', help='The github task context(s) to trigger; can also be '
'"image:<imagename>" to trigger all tests related to that image')
'"image:<imagename>" to trigger all tests related to that image '
'or a wildcard pattern to trigger all matching tests')
opts = parser.parse_args()

api = github.GitHub(repo=opts.repo)
Expand Down
Loading