Commit b9379490 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

ENH: Patch version number of staging builds so that they can be differentiated

from, and ordered correctly, w.r.t. stable releases.
parent 81273886
......@@ -75,8 +75,10 @@ def sprun(cmd, **kwargs):
# we set stdout/stderr for compatibility
# with CaptureStdout (see below)
if 'check' not in kwargs: kwargs['check'] = True
if 'stdout' not in kwargs: kwargs['stdout'] = sys.stdout
if 'stderr' not in kwargs: kwargs['stderr'] = sys.stderr
if 'capture_output' not in kwargs:
if 'stdout' not in kwargs: kwargs['stdout'] = sys.stdout
if 'stderr' not in kwargs: kwargs['stderr'] = sys.stderr
return sp.run(cmd, **kwargs)
......
......@@ -11,8 +11,12 @@ import os
import os.path as op
import re
import sys
import datetime
from fsl_ci import sprun, fprint
from fsl_ci import (sprun,
indir,
fprint,
dumpyaml)
from fsl_ci.conda import (load_meta_yaml,
get_platform_shortcut_if_not_applicable)
......@@ -34,6 +38,33 @@ def build_recipe(recipe_dir, repo, ref, output_dir, *channels):
sprun(f'{cmd} --output-folder={output_dir} {recipe_dir}', env=env)
def patch_recipe_version(recipe_dir):
"""Patches the package version number in the recipe metadata.
For staging builds, a development suffix is added to the project version
number.
"""
date = datetime,date.today().strftime('%Y%m%d')
with indir(recipe_dir):
meta = load_meta_yaml('meta.yaml')
ver = meta['package']['version']
commit = sprun('git rev-parse --short HEAD', capture_output=True)
commit = commit.stdout.decode().strip()
# Use a PEP440-compliant versioning scheme (assuming
# that the original package version is compliant).
# Also use a post-release identifier so that staging
# builds will be ordered after (deemed newewr than)
# the last stable release.
meta['package']['version'] = f'{ver}.post0.dev{date}+{commit}'
with open('meta.yaml', 'wt') as f:
f.write(dumpyaml(meta))
def main():
"""Build a conda package from a FSL recipe repository.
......@@ -60,7 +91,7 @@ def main():
recipe_url = os.environ['CI_PROJECT_URL']
recipe_ref = os.environ['CI_COMMIT_REF_NAME']
job_name = os.environ['CI_JOB_NAME']
staging = os.environ['STAGING']
staging = os.environ['STAGING'].lower() == 'true'
skip_platforms = os.environ.get('FSLCONDA_SKIP_PLATFORM', '')
skip_platforms = skip_platforms.split()
......@@ -87,7 +118,7 @@ def main():
# we output to _platform_, rather thah platform.
output_dir = op.join(os.getcwd(), 'conda_build', f'_{platform}_')
if staging == 'true':
if staging:
channel_url = os.environ['FSLCONDA_STAGING_CHANNEL_URL']
else:
channel_url = os.environ['FSLCONDA_PRODUCTION_CHANNEL_URL']
......@@ -108,6 +139,9 @@ def main():
if project_repo == '': project_repo = None
if project_ref == '': project_ref = None
if staging:
patch_recipe_version('.')
build_recipe('.',
project_repo,
project_ref,
......
......@@ -68,7 +68,7 @@
# If running on docker, install fsl-ci-rules
# directly into the miniconda base environment.
# Otherwise reate a conda env, and install
# Otherwise create a conda env, and install
# fsl-ci-rules into it
- if [ "$DOCKER" == "0" ]; then
conda create -y -p ${FSL_CI_CONFIG_DIR}/env -c conda-forge python=$(python -V | cut -d ' ' -f 2);
......@@ -81,7 +81,7 @@
echo "Installing CI rules from git (attempt $i / 5)...";
(python -m pip install --no-cache git+${CI_RULES_REPOSITORY} && touch success) || true;
if [ -f success ]; then break; fi;
sleep 2;
sleep 5;
done;
if [ ! -f success ]; then exit 1; fi;
fi
......
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