@@ -232,106 +232,101 @@ def prepare_fork(arm_example):
232
232
return False
233
233
return True
234
234
235
- def prepare_branch (branch ):
235
+ def prepare_branch (src , dst ):
236
236
""" Set up at branch ready for use in updating examples
237
237
238
238
Description:
239
239
240
- This function checks whether or not the supplied branch exists.
241
- If it does not, the branch is created and pushed to the origin.
240
+ This function checks whether or not the supplied dst branch exists.
241
+ If it does not, the branch is created from the src and pushed to the origin.
242
242
The branch is then switched to.
243
243
244
244
Args:
245
- arm_example - Full GitHub repo path for original example
245
+ src - branch to create the dst branch from
246
+ dst - branch to update
247
+
248
+ Return:
246
249
ret - True if the fork was synchronised successfully, False otherwise
247
250
248
251
"""
249
252
250
- update_log .debug ("Preparing branch: %s" , branch )
253
+ update_log .debug ("Preparing branch: %s" , dst )
251
254
252
255
# Check if branch already exists or not.
253
256
cmd = ['git' , 'branch' ]
254
257
return_code , output = run_cmd_with_output (cmd )
255
258
256
- if not branch in output :
259
+ if not dst in output :
260
+
257
261
# OOB branch does not exist thus create it and then check it out
258
- cmd = ['git' , 'checkout' , '-b' , branch ]
262
+
263
+ # First ensure we are on the src branch
264
+ cmd = ['git' , 'checkout' , src ]
259
265
return_code = run_cmd (cmd )
260
266
if not return_code :
261
-
262
- # Push new branch upstream
263
- cmd = ['git' , 'push' , '-u' , 'origin' , branch ]
267
+
268
+ cmd = ['git' , 'checkout' , '-b' , dst ]
264
269
return_code = run_cmd (cmd )
270
+ if not return_code :
271
+
272
+ # Push new branch upstream
273
+ cmd = ['git' , 'push' , '-u' , 'origin' , dst ]
274
+ return_code = run_cmd (cmd )
265
275
else :
266
- cmd = ['git' , 'checkout' , branch ]
276
+ cmd = ['git' , 'checkout' , dst ]
267
277
return_code = run_cmd (cmd )
268
278
269
279
if return_code :
270
- update_log .error ("Failed to prepare branch: %s" , branch )
280
+ update_log .error ("Failed to prepare branch: %s" , dst )
271
281
return False
272
282
273
283
return True
274
284
275
- def upgrade_example (github , example , tag , ref ,
276
- user = 'ARMmbed' , branch = 'master' ):
285
+ def upgrade_example (github , example , tag , ref , user , src , dst ):
277
286
""" Upgrade all versions of mbed-os.lib found in the specified example repo
278
287
279
288
Description:
280
289
281
290
Clone a version of the example specified and upgrade all versions of
282
291
mbed-os.lib found within its tree. The version cloned and how it
283
- is upgraded depends on the user and branch specified. Only two options
284
- are valid:
285
- 1) ARMmbed + non master branch
286
- This option will update the branch directly in the ARMmbed repo. If the
287
- branch does not exist it will be first created.
288
-
289
- 2) alternative user + master branch
290
-
291
- This option assumes that a fork of the repo exists in the specified user's
292
- account. The fork will first be updated so that it is up to date with the
293
- upstream version , then the fork will be updated and a PR raised against
294
- the upstream ie ARMmbed repo.
295
-
292
+ is upgraded depends on the user, src and dst settings.
293
+ 1) user == None
294
+ The destination branch will be updated with the version of mbed-os
295
+ idenfied by the tag. If the destination branch does not exist then it
296
+ will be created from the source branch.
297
+
298
+ 2) user != None
299
+ The master branch of a fork of the example will be updated with the
300
+ version of mbed-os identified by the tag.
301
+
296
302
Args:
297
303
github - GitHub instance to allow internal git commands to be run
298
304
example - json example object containing the GitHub repo to update.
299
305
tag - GitHub tag corresponding to a version of mbed-os to upgrade to.
300
306
ref - SHA corresponding to the tag
301
- user - GitHub user name (defaults to 'ARMmbed' if not supplied)
302
- branch - branch to update (defaults to 'master' if not supplied)
307
+ user - GitHub user name
308
+ src - branch to create the dst branch from
309
+ dst - branch to update
303
310
304
311
returns True if the upgrade was successful, False otherwise
305
312
"""
313
+
314
+ # If a user has not been specified then branch update will be used and thus
315
+ # the git user will be ARMmbed.
316
+ if not user :
317
+ user = 'ARMmbed'
306
318
307
319
ret = False
308
320
update_log .info ("Updating example '%s'" , example ['name' ])
309
321
update_log .debug ("User: %s" , user )
310
- update_log .debug ("Branch: %s" , branch )
311
-
312
- # First check validity of user/branch combination
313
- if ((user == 'ARMmbed' and branch == 'master' ) or
314
- (user != 'ARMmbed' and branch != 'master' )):
315
- update_log .error ("Invalid user/branch combination" )
316
- return False
322
+ update_log .debug ("Src branch: %s" , (src or "None" ))
323
+ update_log .debug ("Dst branch: %s" , (dst or "None" ))
317
324
318
325
cwd = os .getcwd ()
319
326
320
- upstream_repo = 'ARMmbed/' + example ['name' ]
321
327
update_repo = "https://github.com/" + user + '/' + example ['name' ]
322
-
323
- update_log .debug ("Upstream repository: %s" , upstream_repo )
324
328
update_log .debug ("Update repository: %s" , update_repo )
325
329
326
- # Check access to mbed-os repo
327
- try :
328
- repo = github .get_repo (upstream_repo , False )
329
-
330
- except :
331
- update_log .error ("Upstream repo: %s, does not exist - skipping" , upstream_repo )
332
- return False
333
-
334
-
335
330
# Clone the example repo
336
331
clone_cmd = ['git' , 'clone' , update_repo ]
337
332
return_code = run_cmd (clone_cmd )
@@ -343,13 +338,11 @@ def upgrade_example(github, example, tag, ref,
343
338
344
339
os .chdir (example ['name' ])
345
340
346
- # If the user is not the default, then a fork will be used. Thus
347
- # synchronise the user fork with the upstream
348
- if user != 'ARMmbed' :
341
+ # If the user is ARMmbed then a branch is used.
342
+ if user == 'ARMmbed' :
343
+ prepare_branch (src , dst )
344
+ else :
349
345
prepare_fork (example ['github' ])
350
-
351
- if branch != 'master' :
352
- prepare_branch (branch )
353
346
354
347
for example_directory in example_directories :
355
348
if not upgrade_single_example (example , tag , os .path .relpath (example_directory , example ['name' ]), ref ):
@@ -369,8 +362,22 @@ def upgrade_example(github, example, tag, ref,
369
362
return_code = run_cmd (push_cmd )
370
363
371
364
if not return_code :
372
- if user != 'ARMmbed' :
373
- body = "Please test/merge this PR and then tag Master with " + tag
365
+ # If the user is not ARMmbed then a fork is being used
366
+ if user != 'ARMmbed' :
367
+
368
+ upstream_repo = 'ARMmbed/' + example ['name' ]
369
+ update_log .debug ("Upstream repository: %s" , upstream_repo )
370
+ # Check access to mbed-os repo
371
+ try :
372
+ repo = github .get_repo (upstream_repo , False )
373
+
374
+ except :
375
+ update_log .error ("Upstream repo: %s, does not exist - skipping" , upstream_repo )
376
+ return False
377
+
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
374
381
# Raise a PR from release-candidate to master
375
382
user_fork = user + ':master'
376
383
try :
@@ -409,16 +416,15 @@ def create_work_directory(path):
409
416
410
417
parser = argparse .ArgumentParser (description = __doc__ ,
411
418
formatter_class = argparse .RawDescriptionHelpFormatter )
412
- parser .add_argument ('tag' , help = "mbed-os tag to which all examples will be updated" )
413
419
parser .add_argument ('-c' , '--config_file' , help = "Path to the configuration file (default is 'examples.json')" , default = 'examples.json' )
414
420
parser .add_argument ('-T' , '--github_token' , help = "GitHub token for secure access" )
415
421
parser .add_argument ('-l' , '--log-level' ,
416
422
help = "Level for providing logging output" ,
417
423
default = 'INFO' )
418
424
419
425
exclusive = parser .add_mutually_exclusive_group (required = True )
420
- exclusive .add_argument ('-U ' , '--github_user ' , help = "GitHub user for forked repos, mutually exclusive to branch option" )
421
- exclusive .add_argument ('-b' , '--branch' , help = "Branch to be updated, mutually exclusive to user option" )
426
+ exclusive .add_argument ('-f ' , '--fork ' , help = "Update a fork" , action = 'store_true' )
427
+ exclusive .add_argument ('-b' , '--branch' , help = "Update a branch" , action = 'store_true' )
422
428
423
429
args = parser .parse_args ()
424
430
@@ -441,9 +447,24 @@ def create_work_directory(path):
441
447
create_work_directory ('examples' )
442
448
443
449
github = Github (args .github_token )
450
+ config = json_data ['update-config' ]
451
+ tag = config ['tag' ]
452
+
453
+ user = None
454
+ src = "master"
455
+ dst = None
456
+
457
+ if args .fork :
458
+ user = config ['via-fork' ]['github-user' ]
459
+ elif args .branch :
460
+ src = config ['via-branch' ]['src-branch' ]
461
+ dst = config ['via-branch' ]['dst-branch' ]
462
+ else :
463
+ userlog .error ("Must specify either -f or -b command line option" )
464
+ exit (1 )
444
465
445
466
# Get the github sha corresponding to the specified mbed-os tag
446
- cmd = ['git' , 'rev-list' , '-1' , args . tag ]
467
+ cmd = ['git' , 'rev-list' , '-1' , tag ]
447
468
return_code , ref = run_cmd_with_output (cmd )
448
469
449
470
if return_code :
@@ -460,11 +481,7 @@ def create_work_directory(path):
460
481
# Determine if this example should be updated and if so update any found
461
482
# mbed-os.lib files.
462
483
463
- # Only user or branch can be specified on the command line
464
- if args .github_user :
465
- result = upgrade_example (github , example , args .tag , ref , user = args .github_user )
466
- else :
467
- result = upgrade_example (github , example , args .tag , ref , branch = args .branch )
484
+ result = upgrade_example (github , example , tag , ref , user , src , dst )
468
485
469
486
if result :
470
487
successes += [example ['name' ]]
0 commit comments