Skip to content

Commit d1f3eb6

Browse files
committed
Added template file for PR commit message plus minor review changes
1 parent b4ac0d0 commit d1f3eb6

File tree

2 files changed

+55
-43
lines changed

2 files changed

+55
-43
lines changed

tools/test/examples/pr.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Please test this PR
2+
3+
If successful then merge, otherwise provide a known issue.
4+
Once you get notification of the release being made public then tag Master with {{ tag }} .

tools/test/examples/update.py

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,29 @@
1414
# 2) Update a different ARMmbed branch of the specified example
1515
#
1616
# A branch to update is specified. If it doesn't already exist then it is first created.
17-
# This branch will be updated and the change automatically pushed.
17+
# This branch will be updated and the change automatically pushed. The new branch will
18+
# be created from the specified source branch.
19+
#
20+
# The modes are controlled via configuration data in the json file.
21+
# E.g.
22+
#
23+
# "update-config" : {
24+
# "help" : "Update each example repo with a version of mbed-os identified by the tag",
25+
# "via-fork" : {
26+
# "help" : "-f cmd line option. Update a fork",
27+
# "github-user" : "adbridge"
28+
# },
29+
# "via-branch" : {
30+
# "help" : "-b cmd line option. Update dst branch, created from src branch",
31+
# "src-branch" : "mbed-os-5.5.0-rc1-oob",
32+
# "dst-branch" : "mbed-os-5.5.0-rc2-oob"
33+
# },
34+
# "tag" : "mbed-os-5.5.0-rc2"
35+
#
1836
#
1937
# Command usage:
2038
#
21-
# update.py -c <config file> - T <github_token> -l <logging level> -U <github user> -b <branch> <tag>
39+
# update.py -c <config file> - T <github_token> -l <logging level> -f -b
2240
#
2341
# Where:
2442
# -c <config file> - Optional path to an examples file.
@@ -27,16 +45,18 @@
2745
# -l <logging level> - Optional Level for providing logging output. Can be one of,
2846
# CRITICAL, ERROR, WARNING, INFO, DEBUG
2947
# If not provided the default is 'INFO'
30-
# -U <github_user> - GitHub user for forked repos
31-
# -b <branch> - Branch to be updated
32-
#
33-
# NOTE only one of -U or -b can be specified.
48+
# -f - Update forked repos. This will use the 'github-user' parameter in
49+
# the 'via-fork' section.
50+
# -b - Update branched repos. This will use the "src-branch" and
51+
# "dst-branch" parameters in the 'via-branch' section. The destination
52+
# branch is created from the source branch (if it doesn't already exist).
53+
#
54+
# The options -f and -b are mutually exlusive. Only one can be specified.
3455
#
35-
# <tag> mbed-os tag to which all examples will be updated
3656
#
3757

3858
import os
39-
from os.path import dirname, abspath, basename
59+
from os.path import dirname, abspath, basename, join
4060
import sys
4161
import logging
4262
import argparse
@@ -46,6 +66,8 @@
4666
import stat
4767
import re
4868
from github import Github, GithubException
69+
from jinja2 import FileSystemLoader, StrictUndefined
70+
from jinja2.environment import Environment
4971

5072
ROOT = abspath(dirname(dirname(dirname(dirname(__file__)))))
5173
sys.path.insert(0, ROOT)
@@ -216,7 +238,6 @@ def prepare_fork(arm_example):
216238
217239
Args:
218240
arm_example - Full GitHub repo path for original example
219-
ret - True if the fork was synchronised successfully, False otherwise
220241
221242
"""
222243

@@ -227,10 +248,7 @@ def prepare_fork(arm_example):
227248
['git', 'fetch', 'armmbed'],
228249
['git', 'reset', '--hard', 'armmbed/master'],
229250
['git', 'push', '-f', 'origin']]:
230-
if run_cmd(cmd):
231-
update_log.error("Fork preparation failed")
232-
return False
233-
return True
251+
run_cmd(cmd, exit_on_failure=True)
234252

235253
def prepare_branch(src, dst):
236254
""" Set up at branch ready for use in updating examples
@@ -244,45 +262,31 @@ def prepare_branch(src, dst):
244262
Args:
245263
src - branch to create the dst branch from
246264
dst - branch to update
247-
248-
Return:
249-
ret - True if the fork was synchronised successfully, False otherwise
250265
251266
"""
252267

253268
update_log.debug("Preparing branch: %s", dst)
254269

255270
# Check if branch already exists or not.
256271
cmd = ['git', 'branch']
257-
return_code, output = run_cmd_with_output(cmd)
272+
_, output = run_cmd_with_output(cmd, exit_on_failure=True)
258273

259274
if not dst in output:
260275

261-
# OOB branch does not exist thus create it and then check it out
276+
# OOB branch does not exist thus create it, first ensuring we are on
277+
# the src branch and then check it out
262278

263-
# First ensure we are on the src branch
264-
cmd = ['git', 'checkout', src]
265-
return_code = run_cmd(cmd)
266-
if not return_code:
267-
268-
cmd = ['git', 'checkout', '-b', dst]
269-
return_code = run_cmd(cmd)
270-
if not return_code:
279+
for cmd in [['git', 'checkout', src],
280+
['git', 'checkout', '-b', dst],
281+
['git', 'push', '-u', 'origin', dst]]:
282+
283+
run_cmd(cmd, exit_on_failure=True)
271284

272-
# Push new branch upstream
273-
cmd = ['git', 'push', '-u', 'origin', dst]
274-
return_code = run_cmd(cmd)
275285
else:
276286
cmd = ['git', 'checkout', dst]
277-
return_code = run_cmd(cmd)
278-
279-
if return_code:
280-
update_log.error("Failed to prepare branch: %s", dst)
281-
return False
282-
283-
return True
284-
285-
def upgrade_example(github, example, tag, ref, user, src, dst):
287+
run_cmd(cmd, exit_on_failure=True)
288+
289+
def upgrade_example(github, example, tag, ref, user, src, dst, template):
286290
""" Upgrade all versions of mbed-os.lib found in the specified example repo
287291
288292
Description:
@@ -375,13 +379,15 @@ def upgrade_example(github, example, tag, ref, user, src, dst):
375379
update_log.error("Upstream repo: %s, does not exist - skipping", upstream_repo)
376380
return False
377381

378-
body = "Please test this PR.\n"
379-
body += "If successful then merge, otherwise provide a known issue.\n"
380-
body += "Once you get notification of the release being made public then tag Master with " + tag
382+
jinja_loader = FileSystemLoader(template)
383+
jinja_environment = Environment(loader=jinja_loader,
384+
undefined=StrictUndefined)
385+
pr_body = jinja_environment.get_template("pr.tmpl").render(tag=tag)
386+
381387
# Raise a PR from release-candidate to master
382388
user_fork = user + ':master'
383389
try:
384-
pr = repo.create_pull(title='Updating mbed-os to ' + tag, head=user_fork, base='master', body=body)
390+
pr = repo.create_pull(title='Updating mbed-os to ' + tag, head=user_fork, base='master', body=pr_body)
385391
ret = True
386392
except GithubException as e:
387393
# Default to False
@@ -475,13 +481,15 @@ def create_work_directory(path):
475481
failures = []
476482
successes = []
477483
results = {}
484+
template = dirname(abspath(__file__))
485+
478486
os.chdir('examples')
479487

480488
for example in json_data['examples']:
481489
# Determine if this example should be updated and if so update any found
482490
# mbed-os.lib files.
483491

484-
result = upgrade_example(github, example, tag, ref, user, src, dst)
492+
result = upgrade_example(github, example, tag, ref, user, src, dst, template)
485493

486494
if result:
487495
successes += [example['name']]

0 commit comments

Comments
 (0)