Commit 9fb257bb authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

CI: Untested release infrastructure

parent 5a347ac4
#!/usr/bin/env bash
#
# Deploy a new version of the fslinstaller script. This script is run
# every time a new tag is added to the fsl/conda/installer gitlab
# repository.
#
# First we copy the installer into the deployment directory, denoted by the
# $FSLINSTALLER_DEPLOY_DIRECTORY environment variable.
# copy the installer to the deploy
# directory, stamping it along the way.
PATTERN="s/^__version__ =.*/__version__ = '$CI_COMMIT_TAG'/g"
DEST=$FSLINSTALLER_DEPLOY_DIRECTORY/fslinstaller.py
cat fslinstaller.py | sed -e "$PATTERN" > $DEST
# Then we call the update_manifest.py script, which opens a merge request
# on the fsl/conda/manifest repository, to update the latest available
# installer version in the manifest.
#
# The update_manifest.py script uses functionality from fsl-ci-rules, so
# we need to install that before running the script.
python -m pip install --upgrade pip
python -m pip install git+git@git.fmrib.ox.ac.uk:/fsl/fsl-ci-rules.git
python ./.ci/update_manifest.py
#!/usr/bin/env bash
pip install --upgrade pip setuptools wheel
pip install pytest coverage pytest-cov mock typing
pytest -v --cov=fslinstaller test
#!/usr/bin/env python
#
# This script is called when a new version of the fslinstaller.py script is
# tagged. It opens a merge request on the GitLab fsl/conda/manifest project,
# to update the FSL release manifest file so that it contains the new installer.
# version string.
#
import os
from fsl_ci import (USERNAME,
EMAIL,
indir,
tempdir,
sprun)
from fsl_ci.gitlab import (open_merge_request,
gen_branch_name)
MANIFEST_PATH = 'fsl/conda/manifest'
COMMIT_MSG = 'MNT: Update fslinstaller version to latest [{tag}] ' \
'in FSL installer manifest'
MERGE_REQUEST_MSG = """
This MR was automatically opened as a result of a new tag being added to
the fsl/installer> project. It updates the installer version in the FSL
release `manifest.json` file to the latest installer version.
""".strip()
def checkout_and_update_manifest(server, token, tag):
manifest_url = f'{server}/{MANIFEST_PATH}'
branch = f'mnt/installer{tag}'
branch = gen_branch_name(branch, MANIFEST_PATH, server, token)
sprun(f'git clone {manifest_url} manifest')
with indir('manifest'):
sprun(f'git config user.name {USERNAME}')
sprun(f'git config user.email {EMAIL}')
sprun(f'git checkout -b {branch} master')
update_manifest()
sprun( 'git add *')
sprun(f'git commit -m "{COMMIT_MSG}"')
sprun(f'git push origin {branch}')
return branch
def main(server=None, token=None, tag=None):
if server is None: server = os.environ['CI_SERVER_URL']
if token is None: token = os.environ['FSL_CI_API_TOKEN']
if tag is None: tag = os.environ['CI_COMMIT_TAG']
branch = checkout_and_update_manifest()
open_merge_request(MANIFEST_PATH,
branch,
MERGE_REQUEST_MSG,
server,
token)
if __name__ == '__main__':
main()
# CI / CD for the fsl/conda/installer project.
#
# Unit tests are run every time commits are
# pushed to the master branch
# pushed to any branch.
#
# Release jobs are run every time a new tag
# is added. Release jobs assume that they
# are running in an environment with a
# directory $FSLINSTALLER_DEPLOY_DIRECTORY
# into which the fslinstaller.py script can
# be copied.
stages:
- test
- release
# These variables should be set as CI/CD variables in
# the fsl/conda/installer project via the GitLab UI.
variables:
# Directory in which new versions of the
# installer script should be copied into.
FSLINSTALLER_DEPLOY_DIRECTORY: "/"
# GitLab API token with enough privileges to push a
# branch to the fsl/conda/manifest repository, and open
# a merge request. Used by the update_manifest.py
# script to update the FSL release manifest file when a
# new fslinstaller version is tagged.
FSL_CI_API_TOKEN: ""
.test-template:
stage: test
......@@ -13,9 +39,7 @@ stages:
rules:
- if: '$CI_COMMIT_TAG == null'
script:
- pip install --upgrade pip setuptools wheel
- pip install pytest coverage pytest-cov mock typing
- pytest -v --cov=fslinstaller test
- bash ./.ci/unit_tests.sh
test:py27:
extends: .test-template
......@@ -47,4 +71,15 @@ test:py38:
test:py39:
extends: .test-template
image: python:3.9
\ No newline at end of file
image: python:3.9
release:
image: python:3.9
tags:
- fsl-ci
- fslconda-channel-host
rules:
- if: '$CI_COMMIT_TAG != null'
script:
- bash ./.ci/new_release.sh
Markdown is supported
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