Add automatic build test

This commit is contained in:
jpic 2020-02-16 16:12:12 +01:00
parent 5b11100e0a
commit 8b145e6378
4 changed files with 35 additions and 14 deletions

View File

@ -97,6 +97,16 @@ class Output:
return line return line
def test(self, action):
if self.debug is True:
self(''.join([
self.colors['purplebold'],
'! TEST ',
self.colors['reset'],
action.colorized(),
'\n',
]))
def clean(self, action): def clean(self, action):
if self.debug is True: if self.debug is True:
self(''.join([ self(''.join([

View File

@ -20,7 +20,7 @@ class Buildah(Localhost):
The build script iterates over visitors and runs the build functions, it The build script iterates over visitors and runs the build functions, it
also provides wrappers around the buildah command. also provides wrappers around the buildah command.
""" """
contextualize = Localhost.contextualize + ['mnt', 'ctr', 'mount'] contextualize = Localhost.contextualize + ['mnt', 'ctr', 'mount', 'image']
def __init__(self, base, *args, commit=None, push=False, cmd=None, **kwargs): def __init__(self, base, *args, commit=None, push=False, cmd=None, **kwargs):
if isinstance(base, Action): if isinstance(base, Action):
@ -56,6 +56,18 @@ class Buildah(Localhost):
def __repr__(self): def __repr__(self):
return f'Base({self.base})' return f'Base({self.base})'
async def __call__(self, *args, **kwargs):
result = await super().__call__(*args, **kwargs)
if 'test' in self.kwargs and self.is_runnable():
self.output.test(self)
await self.action('Docker',
*self.kwargs['test'].actions,
image=self.image,
mount={'.': '/app'},
workdir='/app',
)(*args, **kwargs)
return result
async def config(self, line): async def config(self, line):
"""Run buildah config.""" """Run buildah config."""
return await self.exec(f'buildah config {line} {self.ctr}', buildah=False) return await self.exec(f'buildah config {line} {self.ctr}', buildah=False)

View File

@ -10,7 +10,9 @@ class Docker(Localhost):
contextualize = Localhost.contextualize + ['mnt', 'ctr', 'mount'] contextualize = Localhost.contextualize + ['mnt', 'ctr', 'mount']
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.image = Image(kwargs.get('image', 'alpine')) self.image = kwargs.get('image', 'alpine')
if not isinstance(self.image, Image):
self.image = Image(image)
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.context['ctr'] = None self.context['ctr'] = None

View File

@ -3,6 +3,11 @@ from shlax.contrib.gitlab import *
PYTEST = 'py.test -svv tests' PYTEST = 'py.test -svv tests'
test = Script(
Pip('.[test]'),
Run(PYTEST),
)
build = Buildah( build = Buildah(
'quay.io/podman/stable', 'quay.io/podman/stable',
Packages('python38', 'buildah', 'unzip', 'findutils', 'python3-yaml', upgrade=False), Packages('python38', 'buildah', 'unzip', 'findutils', 'python3-yaml', upgrade=False),
@ -14,23 +19,15 @@ build = Buildah(
mkdir -p /usr/local/lib/python3.8/site-packages/ mkdir -p /usr/local/lib/python3.8/site-packages/
sh -c "cd setuptools-* && python3.8 setup.py install" sh -c "cd setuptools-* && python3.8 setup.py install"
easy_install-3.8 pip easy_install-3.8 pip
echo python3.8 -m pip > /usr/bin/pip
chmod +x /usr/bin/pip
'''), '''),
Copy('shlax/', 'setup.py', '/app'), Copy('shlax/', 'setup.py', '/app'),
), ),
Pip('/app', pip='python3.8 -m pip'), Pip('/app'),
commit='yourlabs/shlax', commit='yourlabs/shlax',
workdir='/app', workdir='/app',
) test=test,
test = Script(
Pip('.[test]'),
Run(PYTEST),
)
buildtest = Docker(
*test.actions,
mount={'.': '/app'},
workdir='/app',
) )
pypi = Run( pypi = Run(