rewrite release_from_yaml.py as bash script

We need our top-level entry scripts to be written in bash so they can
set up the virtualenv for the dependencies of the python scripts.

Change-Id: Ib363839f24463c3beb8815bdfae1ee93abc75a3c
This commit is contained in:
Doug Hellmann 2015-11-30 20:21:03 +00:00
parent 8f7a6a3b08
commit d4b7bdb749
3 changed files with 51 additions and 106 deletions

View File

@ -36,12 +36,12 @@ When a release request is ready to be approved, follow these steps:
3. In a local copy of this
``openstack-infra/release-tools`` repository, run
``release_from_yaml.py``, giving the path to the
``release_from_yaml.sh``, giving the path to the
``openstack/releases`` repository.
For example::
$ ./release_from_yaml.py -r ~/repos/openstack/releases
$ ./release_from_yaml.sh ~/repos/openstack/releases
4. As the release script runs, it will prompt you for your GPG key
passphrase before adding the tag. This gives you a last chance to
@ -68,7 +68,7 @@ Top-level scripts
The top-level scripts call the various base tools to get their work done.
release_from_yaml.py
release_from_yaml.sh
--------------------
This script takes YAML files describing deliverables to release (like those
@ -80,12 +80,12 @@ most recent commit).
Examples:
./release_from_yaml ../openstack-releases/deliverables/mitaka/nova.yaml
./release_from_yaml.sh ../openstack-releases deliverables/mitaka/nova.yaml
Call release.sh for all repositories mentioned in the last release added
to ../openstack-releases/deliverables/mitaka/nova.yaml
./release_from_yaml.py -r ../openstack-releases
./release_from_yaml.sh ../openstack-releases
Look into the git repository at ../openstack-releases for deliverable YAML
files modified at the last commit, and call release.sh for all repositories

View File

@ -1,101 +0,0 @@
#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Tags a release as requested in a YAML file in the releases repo.
"""
from __future__ import print_function
import argparse
import os.path
import subprocess
import sys
import yaml
from releasetools import gitutils
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'deliverable_file',
nargs='*',
help='paths to YAML files specifying releases',
)
parser.add_argument(
'--releases-repo', '-r',
default='.',
help='path to the releases repository for automatic scanning',
)
args = parser.parse_args()
tools_dir = os.path.dirname(sys.argv[0])
# Determine which deliverable files to process by taking our
# command line arguments or by scanning the git repository
# for the most recent change.
deliverable_files = args.deliverable_file
if not deliverable_files:
deliverable_files = gitutils.find_modified_deliverable_files(
args.releases_repo,
)
errors = []
for basename in deliverable_files:
filename = os.path.join(args.releases_repo, basename)
with open(filename, 'r') as f:
deliverable_data = yaml.load(f.read())
# The series name is part of the filename, rather than the file
# body. That causes release.sh to be called with series="_independent"
# for release:independent projects, and release.sh to use master branch
# to evaluate fixed bugs.
series_name = os.path.basename(
os.path.dirname(os.path.abspath(filename))
)
deliverable_name = os.path.splitext(os.path.basename(filename))[0]
all_versions = {
rel['version']: rel for rel in deliverable_data['releases']
}
version = deliverable_data['releases'][-1]['version']
print('Deliverable %s Series %s Version %s' %
(deliverable_name, series_name, version))
this_version = all_versions[version]
for project in this_version['projects']:
cmd = [
os.path.join(tools_dir, 'release.sh'),
project['repo'],
series_name,
version,
project['hash'],
]
try:
subprocess.check_call(cmd)
except (OSError, subprocess.CalledProcessError) as err:
print('ERROR: %s' % err)
errors.append((project['repo'], err, cmd))
if errors:
print('\nRepeating errors:')
for repo, err, cmd in errors:
print('Error running "%s" for %s: %s' % (' '.join(cmd), repo, err))
return 1
return 0
if __name__ == '__main__':
main()

46
release_from_yaml.sh Executable file
View File

@ -0,0 +1,46 @@
#!/bin/bash
#
# Script to release projects based on changes to the deliverables
# files in the openstack/releases repository.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
set -e
if [ $# -lt 1 ]; then
echo "Usage: $0 releases_repository [deliverable_files]"
echo
echo "Example: $0 ~/repos/openstack/releases"
exit 2
fi
TOOLSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $TOOLSDIR/functions
RELEASES_REPO="$1"
shift
DELIVERABLES="$@"
if [[ -z "$VIRTUAL_ENV" ]]; then
(cd $TOOLSDIR && tox -e venv --notest)
source $TOOLSDIR/.tox/venv/bin/activate
fi
list-deliverable-changes -r $RELEASES_REPO $DELIVERABLES \
| while read deliverable series version repo hash; do
$TOOLSDIR/release.sh $repo $series $version $hash
done
exit 0