diff options
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | ick2/actions.py | 18 |
2 files changed, 21 insertions, 1 deletions
@@ -31,6 +31,10 @@ Version 0.52.1+git, not yet released * Icktool now looks for credentials using both the controller URL, and the authentication URL. +* The `archive: workspace` action now takes an optional `glob` field, + which is a list of Unix filename globs, for what to include in the + artifact. + Version 0.52.1, released 2018-06-12 ---------------------------------- diff --git a/ick2/actions.py b/ick2/actions.py index 8c52475..7c968c9 100644 --- a/ick2/actions.py +++ b/ick2/actions.py @@ -15,6 +15,7 @@ import base64 import copy +import glob import json import os import tempfile @@ -265,17 +266,23 @@ class ArchiveWorkspaceAction(Action): # pragma: no cover def execute(self, params, step): env = self.get_env() + dirname = env.get_workspace_directory() blob_name = params.get('artifact_name') if not blob_name: env.report(1, 'No artifact_name parameter\n') return 1 - dirname = env.get_workspace_directory() + globs = step.get('globs') + if globs is None: + names = ['.'] + else: + names = self.match_globs(dirname, globs) url = self.get_blob_upload_url(blob_name) headers = self.get_authz_headers() + self._env.report(None, 'Creating tarball from workspace\n') fd, tarball = tempfile.mkstemp() os.close(fd) tar = ['sudo', 'tar', '-zcf', tarball, '-C', dirname, '.'] @@ -286,6 +293,7 @@ class ArchiveWorkspaceAction(Action): # pragma: no cover return exit_code self._env.report(None, 'tarball generation finished\n') + self._env.report(None, 'Uploading tarball to artifact store\n') curl = ['curl', '-sk', '-T', tarball] + [ '-H{}:{}'.format(name, value) for name, value in headers.items() @@ -296,6 +304,14 @@ class ArchiveWorkspaceAction(Action): # pragma: no cover os.remove(tarball) return exit_code + def match_globs(self, workspace, globs): + names = [] + for pat in globs: + abspat = os.path.join(workspace, './' + pat) + for name in glob.glob(abspat): + names.append(os.path.normpath(name)) + return names + class PopulateActionBase(Action): # pragma: no cover |