Added template file for PR commit message plus minor review changes

pull/4531/head
adbridge 2017-06-21 11:50:14 +01:00
parent b4ac0d048d
commit d1f3eb6ba6
2 changed files with 55 additions and 43 deletions

View File

@ -0,0 +1,4 @@
Please test this PR
If successful then merge, otherwise provide a known issue.
Once you get notification of the release being made public then tag Master with {{ tag }} .

View File

@ -14,11 +14,29 @@
# 2) Update a different ARMmbed branch of the specified example # 2) Update a different ARMmbed branch of the specified example
# #
# A branch to update is specified. If it doesn't already exist then it is first created. # A branch to update is specified. If it doesn't already exist then it is first created.
# This branch will be updated and the change automatically pushed. # This branch will be updated and the change automatically pushed. The new branch will
# be created from the specified source branch.
#
# The modes are controlled via configuration data in the json file.
# E.g.
#
# "update-config" : {
# "help" : "Update each example repo with a version of mbed-os identified by the tag",
# "via-fork" : {
# "help" : "-f cmd line option. Update a fork",
# "github-user" : "adbridge"
# },
# "via-branch" : {
# "help" : "-b cmd line option. Update dst branch, created from src branch",
# "src-branch" : "mbed-os-5.5.0-rc1-oob",
# "dst-branch" : "mbed-os-5.5.0-rc2-oob"
# },
# "tag" : "mbed-os-5.5.0-rc2"
#
# #
# Command usage: # Command usage:
# #
# update.py -c <config file> - T <github_token> -l <logging level> -U <github user> -b <branch> <tag> # update.py -c <config file> - T <github_token> -l <logging level> -f -b
# #
# Where: # Where:
# -c <config file> - Optional path to an examples file. # -c <config file> - Optional path to an examples file.
@ -27,16 +45,18 @@
# -l <logging level> - Optional Level for providing logging output. Can be one of, # -l <logging level> - Optional Level for providing logging output. Can be one of,
# CRITICAL, ERROR, WARNING, INFO, DEBUG # CRITICAL, ERROR, WARNING, INFO, DEBUG
# If not provided the default is 'INFO' # If not provided the default is 'INFO'
# -U <github_user> - GitHub user for forked repos # -f - Update forked repos. This will use the 'github-user' parameter in
# -b <branch> - Branch to be updated # the 'via-fork' section.
# -b - Update branched repos. This will use the "src-branch" and
# "dst-branch" parameters in the 'via-branch' section. The destination
# branch is created from the source branch (if it doesn't already exist).
# #
# NOTE only one of -U or -b can be specified. # The options -f and -b are mutually exlusive. Only one can be specified.
# #
# <tag> mbed-os tag to which all examples will be updated
# #
import os import os
from os.path import dirname, abspath, basename from os.path import dirname, abspath, basename, join
import sys import sys
import logging import logging
import argparse import argparse
@ -46,6 +66,8 @@ import shutil
import stat import stat
import re import re
from github import Github, GithubException from github import Github, GithubException
from jinja2 import FileSystemLoader, StrictUndefined
from jinja2.environment import Environment
ROOT = abspath(dirname(dirname(dirname(dirname(__file__))))) ROOT = abspath(dirname(dirname(dirname(dirname(__file__)))))
sys.path.insert(0, ROOT) sys.path.insert(0, ROOT)
@ -216,7 +238,6 @@ def prepare_fork(arm_example):
Args: Args:
arm_example - Full GitHub repo path for original example arm_example - Full GitHub repo path for original example
ret - True if the fork was synchronised successfully, False otherwise
""" """
@ -227,10 +248,7 @@ def prepare_fork(arm_example):
['git', 'fetch', 'armmbed'], ['git', 'fetch', 'armmbed'],
['git', 'reset', '--hard', 'armmbed/master'], ['git', 'reset', '--hard', 'armmbed/master'],
['git', 'push', '-f', 'origin']]: ['git', 'push', '-f', 'origin']]:
if run_cmd(cmd): run_cmd(cmd, exit_on_failure=True)
update_log.error("Fork preparation failed")
return False
return True
def prepare_branch(src, dst): def prepare_branch(src, dst):
""" Set up at branch ready for use in updating examples """ Set up at branch ready for use in updating examples
@ -245,44 +263,30 @@ def prepare_branch(src, dst):
src - branch to create the dst branch from src - branch to create the dst branch from
dst - branch to update dst - branch to update
Return:
ret - True if the fork was synchronised successfully, False otherwise
""" """
update_log.debug("Preparing branch: %s", dst) update_log.debug("Preparing branch: %s", dst)
# Check if branch already exists or not. # Check if branch already exists or not.
cmd = ['git', 'branch'] cmd = ['git', 'branch']
return_code, output = run_cmd_with_output(cmd) _, output = run_cmd_with_output(cmd, exit_on_failure=True)
if not dst in output: if not dst in output:
# OOB branch does not exist thus create it and then check it out # OOB branch does not exist thus create it, first ensuring we are on
# the src branch and then check it out
# First ensure we are on the src branch for cmd in [['git', 'checkout', src],
cmd = ['git', 'checkout', src] ['git', 'checkout', '-b', dst],
return_code = run_cmd(cmd) ['git', 'push', '-u', 'origin', dst]]:
if not return_code:
cmd = ['git', 'checkout', '-b', dst] run_cmd(cmd, exit_on_failure=True)
return_code = run_cmd(cmd)
if not return_code:
# Push new branch upstream
cmd = ['git', 'push', '-u', 'origin', dst]
return_code = run_cmd(cmd)
else: else:
cmd = ['git', 'checkout', dst] cmd = ['git', 'checkout', dst]
return_code = run_cmd(cmd) run_cmd(cmd, exit_on_failure=True)
if return_code: def upgrade_example(github, example, tag, ref, user, src, dst, template):
update_log.error("Failed to prepare branch: %s", dst)
return False
return True
def upgrade_example(github, example, tag, ref, user, src, dst):
""" Upgrade all versions of mbed-os.lib found in the specified example repo """ Upgrade all versions of mbed-os.lib found in the specified example repo
Description: Description:
@ -375,13 +379,15 @@ def upgrade_example(github, example, tag, ref, user, src, dst):
update_log.error("Upstream repo: %s, does not exist - skipping", upstream_repo) update_log.error("Upstream repo: %s, does not exist - skipping", upstream_repo)
return False return False
body = "Please test this PR.\n" jinja_loader = FileSystemLoader(template)
body += "If successful then merge, otherwise provide a known issue.\n" jinja_environment = Environment(loader=jinja_loader,
body += "Once you get notification of the release being made public then tag Master with " + tag undefined=StrictUndefined)
pr_body = jinja_environment.get_template("pr.tmpl").render(tag=tag)
# Raise a PR from release-candidate to master # Raise a PR from release-candidate to master
user_fork = user + ':master' user_fork = user + ':master'
try: try:
pr = repo.create_pull(title='Updating mbed-os to ' + tag, head=user_fork, base='master', body=body) pr = repo.create_pull(title='Updating mbed-os to ' + tag, head=user_fork, base='master', body=pr_body)
ret = True ret = True
except GithubException as e: except GithubException as e:
# Default to False # Default to False
@ -475,13 +481,15 @@ if __name__ == '__main__':
failures = [] failures = []
successes = [] successes = []
results = {} results = {}
template = dirname(abspath(__file__))
os.chdir('examples') os.chdir('examples')
for example in json_data['examples']: for example in json_data['examples']:
# Determine if this example should be updated and if so update any found # Determine if this example should be updated and if so update any found
# mbed-os.lib files. # mbed-os.lib files.
result = upgrade_example(github, example, tag, ref, user, src, dst) result = upgrade_example(github, example, tag, ref, user, src, dst, template)
if result: if result:
successes += [example['name']] successes += [example['name']]