Skip to content
Snippets Groups Projects
Unverified Commit 77bfb534 authored by Max Gautier's avatar Max Gautier
Browse files

Fix ci-matrix pre-commit hook

- Remove dependency of pydblite which fails to setup on recent pythons
- Discard shell script and put everything into pre-commit
parent 0e449ca7
No related branches found
No related tags found
No related merge requests found
...@@ -123,4 +123,5 @@ ci-matrix: ...@@ -123,4 +123,5 @@ ci-matrix:
tags: [light] tags: [light]
image: python:3 image: python:3
script: script:
- tests/scripts/md-table/test.sh - tests/scripts/md-table/main.py
- git diff --exit-code
...@@ -77,9 +77,13 @@ repos: ...@@ -77,9 +77,13 @@ repos:
- id: ci-matrix - id: ci-matrix
name: ci-matrix name: ci-matrix
entry: tests/scripts/md-table/test.sh entry: tests/scripts/md-table/main.py
language: script language: python
pass_filenames: false pass_filenames: false
additional_dependencies:
- jinja2
- pathlib
- pyaml
- id: jinja-syntax-check - id: jinja-syntax-check
name: jinja-syntax-check name: jinja-syntax-check
......
...@@ -4,7 +4,6 @@ import sys ...@@ -4,7 +4,6 @@ import sys
import glob import glob
from pathlib import Path from pathlib import Path
import yaml import yaml
from pydblite import Base
import re import re
import jinja2 import jinja2
import sys import sys
...@@ -14,6 +13,7 @@ from pprint import pprint ...@@ -14,6 +13,7 @@ from pprint import pprint
parser = argparse.ArgumentParser(description='Generate a Markdown table representing the CI test coverage') parser = argparse.ArgumentParser(description='Generate a Markdown table representing the CI test coverage')
parser.add_argument('--dir', default='tests/files/', help='folder with test yml files') parser.add_argument('--dir', default='tests/files/', help='folder with test yml files')
parser.add_argument('--output', default='docs/developers/ci.md', help='output file')
args = parser.parse_args() args = parser.parse_args()
...@@ -24,25 +24,26 @@ env = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath=sys.path[0])) ...@@ -24,25 +24,26 @@ env = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath=sys.path[0]))
# Data represents CI coverage data matrix # Data represents CI coverage data matrix
class Data: class Data:
def __init__(self): def __init__(self):
self.db = Base(':memory:') self.container_managers = set()
self.db.create('container_manager', 'network_plugin', 'operating_system') self.network_plugins = set()
self.os = set()
self.combination = set()
def set(self, container_manager, network_plugin, operating_system): def set(self, container_manager, network_plugin, os):
self.db.insert(container_manager=container_manager, network_plugin=network_plugin, operating_system=operating_system) self.container_managers.add(container_manager)
self.db.commit() self.network_plugins.add(network_plugin)
def exists(self, container_manager, network_plugin, operating_system): self.os.add(os)
return len((self.db("container_manager") == container_manager) & (self.db("network_plugin") == network_plugin) & (self.db("operating_system") == operating_system)) > 0 self.combination.add(container_manager+network_plugin+os)
def exists(self, container_manager, network_plugin, os):
return (container_manager+network_plugin+os) in self.combination
def jinja(self): def jinja(self):
template = env.get_template('table.md.j2') template = env.get_template('table.md.j2')
container_engines = list(self.db.get_unique_ids('container_manager')) container_engines = sorted(self.container_managers)
network_plugins = list(self.db.get_unique_ids("network_plugin")) network_plugins = sorted(self.network_plugins)
operating_systems = list(self.db.get_unique_ids("operating_system")) operating_systems = sorted(self.os)
container_engines.sort()
network_plugins.sort()
operating_systems.sort()
return template.render( return template.render(
container_engines=container_engines, container_engines=container_engines,
...@@ -91,6 +92,5 @@ for f in files: ...@@ -91,6 +92,5 @@ for f in files:
network_plugin = y.get('kube_network_plugin', 'calico') network_plugin = y.get('kube_network_plugin', 'calico')
x = re.match(r"^[a-z-]+_([a-z0-9]+).*", f.name) x = re.match(r"^[a-z-]+_([a-z0-9]+).*", f.name)
operating_system = x.group(1) operating_system = x.group(1)
data.set(container_manager=container_manager, network_plugin=network_plugin, operating_system=operating_system) data.set(container_manager=container_manager, network_plugin=network_plugin, os=operating_system)
#print(data.markdown()) print(data.jinja(), file=open(args.output, 'w'))
print(data.jinja())
jinja2
pathlib ; python_version < '3.10'
pyaml
pydblite
#!/bin/bash
set -euxo pipefail
echo "Install requirements..."
pip install -r ./tests/scripts/md-table/requirements.txt
echo "Generate current file..."
./tests/scripts/md-table/main.py > tmp.md
echo "Compare docs/developers/ci.md with actual tests in tests/files/*.yml ..."
cmp docs/developers/ci.md tmp.md
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment