Commit 00d25036 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: Refactorings to allow update_conda_recipe to be called on a repo, keeping

version number the same, but incrementing the build number. Returns MR url
parent a5352654
......@@ -8,6 +8,8 @@
import os.path as op
import os
import io
import sys
import errno
import shlex
import string
......@@ -118,6 +120,41 @@ def lockdir(dirname):
os.unlink(lockfile)
class CaptureStdout:
"""Context manager which captures stdout and stderr. """
def __init__(self):
self.reset()
def reset(self):
self.__mock_stdout = io.StringIO('')
self.__mock_stderr = io.StringIO('')
self.__mock_stdout.mode = 'w'
self.__mock_stderr.mode = 'w'
return self
def __enter__(self):
self.__real_stdout = sys.stdout
self.__real_stderr = sys.stderr
sys.stdout = self.__mock_stdout
sys.stderr = self.__mock_stderr
def __exit__(self, *args, **kwargs):
sys.stdout = self.__real_stdout
sys.stderr = self.__real_stderr
@property
def stdout(self):
self.__mock_stdout.seek(0)
return self.__mock_stdout.read()
@property
def stderr(self):
self.__mock_stderr.seek(0)
return self.__mock_stderr.read()
def health_check():
"""Rudimentary health check of the fsl-ci-rules codebase. """
print(f'fsl-ci-rules version {__version__}')
......
......@@ -117,9 +117,10 @@ def load_meta_yaml(filename):
def get_project_repository_and_revision(filename, ignore_env=False):
"""Returns a tuple containing the project git repository URL and git
revision listed in the given meta.yaml file. If either repository
or revision are missing, the respective returned value will be None.
"""Returns a tuple containing the project git repository URL, git
revision, and build number listed in the given meta.yaml file. If
repository, revision, or build are not in the metadata, the
respective returned value will be None.
If ignore_env is True, the FSLCONDA_REPOSITORY and FSLCONDA_variables
are ignored, if set.
......@@ -142,16 +143,20 @@ def get_project_repository_and_revision(filename, ignore_env=False):
meta = load_meta_yaml(filename)
source = meta.get('source', {})
source = meta .get('source', {})
build = meta .get('build', {})
repo = source.get('git_url', None)
rev = source.get('git_rev', None)
build = build .get('number', None)
if repo is not None: repo = repo.strip()
if rev is not None: rev = rev .strip()
if repo == '': repo = None
if rev == '': rev = None
if repo is not None: repo = repo .strip()
if rev is not None: rev = rev .strip()
if build is not None: build = build.strip()
if repo == '': repo = None
if rev == '': rev = None
if build == '': build = None
return repo, rev
return repo, rev, build
@dataclasses.dataclass
......
......@@ -459,7 +459,7 @@ def open_merge_request(project_path,
'title' : f'WIP: {source_branch}',
'description' : message,
}
http_request(url, token, data=data)
return http_request(url, token, data=data)
def trigger_pipeline(project_path,
......
......@@ -23,7 +23,7 @@ def checkout_project_repository_shortcut_if_no_tests(project_dir):
of the project unit tests/data.
"""
# The FSLCONDA_REPOSITORY/REVISION vars are honoured if set
repo, rev = get_project_repository_and_revision('meta.yaml')
repo, rev = get_project_repository_and_revision('meta.yaml')[:2]
sprun(f'git clone {repo} {project_dir}')
sprun(f'git checkout {rev}', cwd=project_dir)
......
......@@ -137,6 +137,7 @@ def rerender_recipe(recipe_dir,
project_path,
recipe_path,
newversion,
newbuild,
server,
token):
"""Re-generates the conda recipe for the project, storing the outputs
......@@ -156,7 +157,7 @@ def rerender_recipe(recipe_dir,
recipe_path,
server,
newversion,
0,
newbuild,
fslbase,
exes,
requirements,
......@@ -168,7 +169,7 @@ def rerender_recipe(recipe_dir,
recipe_path,
server,
newversion,
0,
newbuild,
fslbase,
entrypoints,
exes)
......@@ -178,6 +179,7 @@ def checkout_and_rerender_recipe(recipe,
branch,
project_path,
project_version,
build,
server,
token):
......@@ -186,7 +188,7 @@ def checkout_and_rerender_recipe(recipe,
commitmsg = tw.dedent(f"""
MNT: Update {project_path} version number
to {project_version} (automatic fsl-ci-rules)
to {project_version}.{build} (automatic fsl-ci-rules)
""").strip()
with tempdir():
......@@ -199,6 +201,7 @@ def checkout_and_rerender_recipe(recipe,
project_path,
recipe_path,
project_version,
build,
server,
token)
sprun( 'git add *')
......@@ -210,7 +213,9 @@ def main(server=None,
token=None,
project_path=None,
project_name=None,
project_ver=None):
project_ver=None,
build_num=0,
mrmsg=None):
"""Re-generates the conda recipe(s) associated with a FSL project. In
normal execution, all of the arguments are read from the environment.
......@@ -219,6 +224,8 @@ def main(server=None,
:arg project_path: GitLab project path
:arg project_name: Project name
:arg project_ver: New project tag
:arg build_num: Build number
:arg mrmsg: Message to use for the merge request
"""
if server is None: server = os.environ['CI_SERVER_URL']
......@@ -229,21 +236,21 @@ def main(server=None,
skip = os.environ.get('FSLCONDA_SKIP_RECIPE_UPDATE', None)
mrmsg = tw.dedent(f"""
This merge request was triggered by a new tag being added to
the {project_path} project.
if mrmsg is None:
mrmsg = tw.dedent(f"""
This merge request was triggered by a new tag being added to
the {project_path} project.
Accepting this merge request will cause the conda recipe for
{project_path} to be updated to version {project_ver}.
Accepting this merge request will cause the conda recipe for
{project_path} to be updated to version {project_ver}.
If all goes well, a new conda package will built for
{project_path} ({project_ver}), and will be uploaded to
the FSL production conda channel.
(MR automatically generated by fsl-ci-rules running on the
{project_path} repository).
""").strip()
If all goes well, a new conda package will built for
{project_path} ({project_ver}), and will be uploaded to
the FSL production conda channel.
(MR automatically generated by fsl-ci-rules running on the
{project_path} repository).
""").strip()
recipes = get_recipe_urls(project_name, server)
......@@ -273,14 +280,15 @@ def main(server=None,
branch,
project_path,
project_ver,
build_num,
server,
token)
open_merge_request(recipe["path"],
branch,
mrmsg,
server,
token)
return open_merge_request(recipe["path"],
branch,
mrmsg,
server,
token)
if __name__ == '__main__':
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment