14
14
# 2) Update a different ARMmbed branch of the specified example
15
15
#
16
16
# 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
+ #
18
36
#
19
37
# Command usage:
20
38
#
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
22
40
#
23
41
# Where:
24
42
# -c <config file> - Optional path to an examples file.
27
45
# -l <logging level> - Optional Level for providing logging output. Can be one of,
28
46
# CRITICAL, ERROR, WARNING, INFO, DEBUG
29
47
# 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.
34
55
#
35
- # <tag> mbed-os tag to which all examples will be updated
36
56
#
37
57
38
58
import os
39
- from os .path import dirname , abspath , basename
59
+ from os .path import dirname , abspath , basename , join
40
60
import sys
41
61
import logging
42
62
import argparse
46
66
import stat
47
67
import re
48
68
from github import Github , GithubException
69
+ from jinja2 import FileSystemLoader , StrictUndefined
70
+ from jinja2 .environment import Environment
49
71
50
72
ROOT = abspath (dirname (dirname (dirname (dirname (__file__ )))))
51
73
sys .path .insert (0 , ROOT )
@@ -216,7 +238,6 @@ def prepare_fork(arm_example):
216
238
217
239
Args:
218
240
arm_example - Full GitHub repo path for original example
219
- ret - True if the fork was synchronised successfully, False otherwise
220
241
221
242
"""
222
243
@@ -227,10 +248,7 @@ def prepare_fork(arm_example):
227
248
['git' , 'fetch' , 'armmbed' ],
228
249
['git' , 'reset' , '--hard' , 'armmbed/master' ],
229
250
['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 )
234
252
235
253
def prepare_branch (src , dst ):
236
254
""" Set up at branch ready for use in updating examples
@@ -244,45 +262,31 @@ def prepare_branch(src, dst):
244
262
Args:
245
263
src - branch to create the dst branch from
246
264
dst - branch to update
247
-
248
- Return:
249
- ret - True if the fork was synchronised successfully, False otherwise
250
265
251
266
"""
252
267
253
268
update_log .debug ("Preparing branch: %s" , dst )
254
269
255
270
# Check if branch already exists or not.
256
271
cmd = ['git' , 'branch' ]
257
- return_code , output = run_cmd_with_output (cmd )
272
+ _ , output = run_cmd_with_output (cmd , exit_on_failure = True )
258
273
259
274
if not dst in output :
260
275
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
262
278
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 )
271
284
272
- # Push new branch upstream
273
- cmd = ['git' , 'push' , '-u' , 'origin' , dst ]
274
- return_code = run_cmd (cmd )
275
285
else :
276
286
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 ):
286
290
""" Upgrade all versions of mbed-os.lib found in the specified example repo
287
291
288
292
Description:
@@ -375,13 +379,15 @@ def upgrade_example(github, example, tag, ref, user, src, dst):
375
379
update_log .error ("Upstream repo: %s, does not exist - skipping" , upstream_repo )
376
380
return False
377
381
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
+
381
387
# Raise a PR from release-candidate to master
382
388
user_fork = user + ':master'
383
389
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 )
385
391
ret = True
386
392
except GithubException as e :
387
393
# Default to False
@@ -475,13 +481,15 @@ def create_work_directory(path):
475
481
failures = []
476
482
successes = []
477
483
results = {}
484
+ template = dirname (abspath (__file__ ))
485
+
478
486
os .chdir ('examples' )
479
487
480
488
for example in json_data ['examples' ]:
481
489
# Determine if this example should be updated and if so update any found
482
490
# mbed-os.lib files.
483
491
484
- result = upgrade_example (github , example , tag , ref , user , src , dst )
492
+ result = upgrade_example (github , example , tag , ref , user , src , dst , template )
485
493
486
494
if result :
487
495
successes += [example ['name' ]]
0 commit comments