From 6938731988745a1352116654d43fc16125d81b22 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Fri, 26 Jul 2019 18:49:34 +0200 Subject: [PATCH] Add tooling to update python jobs on branch creation Currently, we need to update jobs manually after a branch is created. When a project is branched, the master branch should then be pointing to the new named python3 tests. This should do it. Change-Id: Id58f439052b4ea6b092b87682576a746433dcc27 --- .../release-tools/add_master_python3_jobs.sh | 65 +++++++++++++++++++ .../files/release-tools/make_branch.sh | 6 ++ .../release-tools/process_release_requests.py | 37 +++++++++-- 3 files changed, 102 insertions(+), 6 deletions(-) create mode 100755 roles/copy-release-tools-scripts/files/release-tools/add_master_python3_jobs.sh diff --git a/roles/copy-release-tools-scripts/files/release-tools/add_master_python3_jobs.sh b/roles/copy-release-tools-scripts/files/release-tools/add_master_python3_jobs.sh new file mode 100755 index 0000000000..aa5ab3b9a6 --- /dev/null +++ b/roles/copy-release-tools-scripts/files/release-tools/add_master_python3_jobs.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# +# Script to update the zuul python3 jobs on master branch when a +# new series is created. +# +# 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 -ex + +if [[ $# -lt 3 ]]; then + echo "Usage: $0 oldseries newseriesname repo_dir" + echo + echo "Example: $0 stein train openstack/oslo.config" + exit 2 +fi + +OLDSERIES=$1 +SERIES=$2 +REPO=$3 +TOOLSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +cd $REPO + +commit_msg="Add Python3 ${SERIES} unit tests + +This is an automatically generated patch to ensure unit testing +is in place for all the of the tested runtimes for ${SERIES}. + +See also the PTI in governance [1]. + +[1]: https://governance.openstack.org/tc/reference/project-testing-interface.html +" + +git checkout master +# Find the appropriate files +fnames=$(find . -type f -path '*zuul.d/*'; find . -type f -name '*zuul.yaml') +for fname in $fnames; do + echo "Checking ${fname}" + sed -i \ + "s/openstack-python3-${OLDSERIES}-jobs/openstack-python3-${SERIES}-jobs/g" \ + $fname +done + +# Only submit patch if files were changed +changes=$(git diff-index --name-only HEAD --) +if [ -n "$changes" ]; then + git checkout -b add-${SERIES}-python-jobtemplates + git add . + git diff --cached + git commit -m "$commit_msg" + git show + git review --yes -f +fi diff --git a/roles/copy-release-tools-scripts/files/release-tools/make_branch.sh b/roles/copy-release-tools-scripts/files/release-tools/make_branch.sh index c141a62dd3..6812a8c78a 100755 --- a/roles/copy-release-tools-scripts/files/release-tools/make_branch.sh +++ b/roles/copy-release-tools-scripts/files/release-tools/make_branch.sh @@ -32,6 +32,7 @@ source $TOOLSDIR/functions REPO=$1 NEW_BRANCH=$2 START_POINT=$3 +MASTER_BRANCH_NAME=${4:-} LPROJECT="$PROJECT" PROJECT=$(basename $REPO) @@ -79,4 +80,9 @@ if [[ $NEW_BRANCH =~ stable/ ]]; then else echo "$REPO does not use reno, no update needed" fi + # Now propose master branch changes with the new branchname + # according to PTI. + if [[ ! -z "${MASTER_BRANCH_NAME}" ]]; then + $TOOLSDIR/add_master_python3_jobs.sh ${NEW_BRANCH} ${MASTER_BRANCH_NAME} . + fi fi diff --git a/roles/copy-release-tools-scripts/files/release-tools/process_release_requests.py b/roles/copy-release-tools-scripts/files/release-tools/process_release_requests.py index b2f884f1fd..44861f3236 100755 --- a/roles/copy-release-tools-scripts/files/release-tools/process_release_requests.py +++ b/roles/copy-release-tools-scripts/files/release-tools/process_release_requests.py @@ -12,8 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -"""Process all of the release requests in changed files in the commit. -""" +"""Process all of the release requests in changed files in the commit.""" import argparse import os.path @@ -52,6 +51,17 @@ RELEASE_SCRIPT = os.path.join(BINDIR, 'release.sh') BRANCH_SCRIPT = os.path.join(BINDIR, 'make_branch.sh') +def nextbranchname(branchname, reporoot): + """Returns a string containing the next development branchname.""" + datafile = 'data/series_status.yaml' + with open(os.path.join(reporoot, datafile), 'r') as seriesstatusf: + series = yaml.safe_load(seriesstatusf) + for nextseries, currentseries in zip(series, series[1:]): + if currentseries['name'] == branchname: + return nextseries['name'] + return None + + def find_modified_deliverable_files(reporoot): "Return a list of files modified by the most recent commit." results = subprocess.check_output( @@ -83,10 +93,21 @@ def tag_release(repo, series_name, version, diff_start, hash, return 0 -def make_branch(repo, name, ref): +def make_branch(repo, name, ref, nextbranchname=None): + """Create a branch if needed. + + :param repo: The repo in which to create the branch. + :param name: The name of the branch to create. + :param ref: The point at which to branch. + :param nextbranchname: The name of the expected next series, if known. + """ print('Branching {} in {}'.format(name, repo)) + makebranchargs = [BRANCH_SCRIPT, repo, name, ref] + # nextbranchname can be null if branch not found (feature branch) + if nextbranchname: + makebranchargs.append(nextbranchname) try: - subprocess.check_call([BRANCH_SCRIPT, repo, name, ref]) + subprocess.check_call(makebranchargs) except subprocess.CalledProcessError: # The error output from the script will be # printed to stderr, so we don't need to do @@ -191,13 +212,16 @@ def process_release_requests(reporoot, filenames, meta_data): first_full_release, meta_data, ) - # Create branches. + # Create branches and adapt master for branch in deliverable_data.get('branches', []): + masterbranchname = nextbranchname(branch['name'], reporoot) location = branch['location'] if isinstance(location, dict): for repo, sha in sorted(location.items()): - error_count += make_branch(repo, branch['name'], sha) + error_count += make_branch( + repo, branch['name'], sha, masterbranchname + ) else: # Assume a single location string that is a valid @@ -205,6 +229,7 @@ def process_release_requests(reporoot, filenames, meta_data): for proj in releases_by_version[location]['projects']: error_count += make_branch( proj['repo'], branch['name'], branch['location'], + masterbranchname ) return error_count