@@ -19,47 +19,14 @@ var (
19
19
gitName = flag .String ("git-author-name" , "cs3org-bot" , "Git author name" )
20
20
gitSSH = flag .Bool ("git-ssh" , false , "Use git protocol instead of https for cloning repos" )
21
21
22
- _only_build = flag .Bool ("only-build" , false , "Build all protos and languages but do not push to language repos" )
23
- _all = flag .Bool ("all" , false , "Compile, build and publish for all available languages, mean to be run in CI platform like Drone" )
24
-
25
- _buildProto = flag .Bool ("build-proto" , false , "Compile Protobuf definitions" )
26
-
27
- _buildGo = flag .Bool ("build-go" , false , "Build Go library" )
28
- _pushGo = flag .Bool ("push-go" , false , "Push Go library to github.com/cs3org/go-cs3apis" )
29
-
30
- _buildPython = flag .Bool ("build-python" , false , "Build Python library" )
31
- _pushPython = flag .Bool ("push-python" , false , "Push Python library to github.com/cs3org/python-cs3apis" )
32
-
33
- _buildJs = flag .Bool ("build-js" , false , "Build Js library" )
34
- _pushJs = flag .Bool ("push-js" , false , "Push Js library to github.com/cs3org/js-cs3apis" )
35
-
36
- _buildNode = flag .Bool ("build-node" , false , "Build Node.js library" )
37
- _pushNode = flag .Bool ("push-node" , false , "Push Node.js library to github.com/cs3org/node-cs3apis" )
22
+ _pushGo = flag .Bool ("push-go" , false , "Push Go library to github.com/cs3org/go-cs3apis" )
23
+ _pushPython = flag .Bool ("push-python" , false , "Push Python library to github.com/cs3org/python-cs3apis" )
24
+ _pushJs = flag .Bool ("push-js" , false , "Push Js library to github.com/cs3org/js-cs3apis" )
25
+ _pushNode = flag .Bool ("push-node" , false , "Push Node.js library to github.com/cs3org/node-cs3apis" )
38
26
)
39
27
40
28
func init () {
41
29
flag .Parse ()
42
-
43
- if * _all {
44
- * _buildProto = true
45
- * _buildGo = true
46
- * _buildPython = true
47
- * _buildJs = true
48
- * _buildNode = true
49
-
50
- * _pushGo = true
51
- * _pushPython = true
52
- * _pushJs = true
53
- * _pushNode = true
54
- }
55
-
56
- if * _only_build {
57
- * _buildProto = true
58
- * _buildGo = true
59
- * _buildPython = true
60
- * _buildJs = true
61
- * _buildNode = true
62
- }
63
30
}
64
31
65
32
func getProtoOS () string {
@@ -280,185 +247,57 @@ func findFolders() []string {
280
247
return folders
281
248
}
282
249
283
- func buildProto () {
284
- dir := "."
285
- cmd := exec .Command ("prototool" , "compile" , "--walk-timeout" , "10s" )
286
- cmd .Dir = dir
287
- run (cmd )
288
-
289
- cmd = exec .Command ("protolock" , "status" )
290
- cmd .Dir = dir
291
- run (cmd )
292
-
293
- // lint
294
- cmd = exec .Command ("prototool" , "format" , "-w" , "--walk-timeout" , "10s" )
295
- cmd .Dir = dir
296
- run (cmd )
297
- cmd = exec .Command ("prototool" , "lint" , "--walk-timeout" , "10s" )
298
- cmd .Dir = dir
299
- run (cmd )
300
- cmd = exec .Command ("go" , "run" , "tools/check-license/check-license.go" )
301
- cmd .Dir = dir
302
- run (cmd )
303
-
304
- os .RemoveAll ("docs" )
305
- os .MkdirAll ("docs" , 0755 )
306
-
307
- files := findProtos ()
308
- fmt .Println (files )
309
-
310
- args := []string {"--doc_out=./docs" , "--doc_opt=html,index.html" , "-I=." , "-I=./third_party" }
311
- args = append (args , files ... )
312
- cmd = exec .Command ("protoc" , args ... )
313
- run (cmd )
314
- }
315
-
316
- func buildGo () {
317
-
318
- // Remove build dir
319
- os .RemoveAll ("build/go-cs3apis" )
320
- os .MkdirAll ("build" , 0755 )
321
-
322
- // Clone Go repo and set branch to current branch
323
- clone ("cs3org/go-cs3apis" , "build" )
324
- protoBranch := getGitBranch ("." )
325
- goBranch := getGitBranch ("build/go-cs3apis" )
326
- fmt .Printf ("Proto branch: %s\n Go branch: %s\n " , protoBranch , goBranch )
327
-
328
- if goBranch != protoBranch {
329
- checkout (protoBranch , "build/go-cs3apis" )
250
+ func generate () {
251
+ cwd , err := os .Getwd ()
252
+ if err != nil {
253
+ panic (err )
330
254
}
255
+ fmt .Printf ("current working directory: %s\n " , cwd )
331
256
332
- // remove leftovers (existing defs)
333
- os .RemoveAll ("build/go-cs3apis/cs3" )
334
-
335
- cmd := exec .Command ("prototool" , "generate" , "--walk-timeout" , "10s" )
257
+ cmd := exec .Command ("git" , "config" , "--global" , "--add" , "safe.directory" , cwd )
336
258
run (cmd )
337
259
338
- sed ("build/go-cs3apis" , ".go" , "github.com/cs3org/go-cs3apis/build/go-cs3apis/cs3/" , "github.com/cs3org/go-cs3apis/cs3/" )
339
-
340
- if ! isRepoDirty ("build/go-cs3apis" ) {
341
- fmt .Println ("Repo is clean, nothing to do" )
342
- }
343
-
344
- // get proto repo commit id
345
- hash := getCommitID ("." )
346
- repo := "build/go-cs3apis"
347
- msg := "Synced to https://github.com/cs3org/cs3apis/tree/" + hash
348
- commit (repo , msg )
349
- }
350
-
351
- func buildPython () {
352
-
353
260
// Remove build dir
354
- os .RemoveAll ("build/python-cs3apis " )
261
+ os .RemoveAll ("build" )
355
262
os .MkdirAll ("build" , 0755 )
356
263
357
- // Clone Go repo and set branch to current branch
358
- clone ("cs3org/python-cs3apis" , "build" )
359
- protoBranch := getGitBranch ("." )
360
- buildBranch := getGitBranch ("build/python-cs3apis" )
361
- fmt .Printf ("Proto branch: %s\n Build branch: %s\n " , protoBranch , buildBranch )
362
-
363
- if buildBranch != protoBranch {
364
- checkout (protoBranch , "build/python-cs3apis" )
365
- }
366
-
367
- // remove leftovers (existing defs)
368
- os .RemoveAll ("build/python-cs3apis/cs3" )
369
-
370
- files := findProtos ()
371
-
372
- args := []string {"-m" , "grpc_tools.protoc" , "--python_out=./build/python-cs3apis" , "-I." , "-I./third_party" , "--grpc_python_out=./build/python-cs3apis" }
373
- args = append (args , files ... )
374
- cmd := exec .Command ("python3" , args ... )
375
- run (cmd )
376
-
377
- modules := findFolders ()
378
-
379
- var initFiles []string
380
- for _ , f := range modules {
381
- initPy := fmt .Sprintf ("%s/%s/%s" , "build/python-cs3apis" , f , "__init__.py" )
382
- initFiles = append (initFiles , initPy )
383
- }
264
+ languages := []string {"go" , "js" , "node" , "python" }
384
265
385
- cmd = exec .Command ("touch" , initFiles ... )
386
- run (cmd )
266
+ // prepare language git repos
267
+ for _ , l := range languages {
268
+ target := fmt .Sprintf ("%s-cs3apis" , l )
387
269
388
- // get proto repo commit id
389
- hash := getCommitID ("." )
390
- repo := "build/python-cs3apis"
391
- msg := "Synced to https://github.com/cs3org/cs3apis/tree/" + hash
392
- commit (repo , msg )
393
- }
270
+ // Clone Go repo and set branch to current branch
271
+ clone ("cs3org/" + target , "build" )
272
+ protoBranch := getGitBranch ("." )
273
+ targetBranch := getGitBranch ("build/" + target )
274
+ fmt .Printf ("Proto branch: %s\n %s branch: %s\n " , l , protoBranch , targetBranch )
394
275
395
- func buildJS () {
396
- // Remove build dir
397
- os .RemoveAll ("build/js-cs3apis" )
398
- os .MkdirAll ("build" , 0755 )
276
+ if targetBranch != protoBranch {
277
+ checkout (protoBranch , "build/" + target )
278
+ }
399
279
400
- // Clone repo and set branch to current branch
401
- clone ("cs3org/js-cs3apis" , "build" )
402
- protoBranch := getGitBranch ("." )
403
- buildBranch := getGitBranch ("build/js-cs3apis" )
404
- fmt .Printf ("Proto branch: %s\n Build branch: %s\n " , protoBranch , buildBranch )
280
+ // remove leftovers (existing defs)
281
+ os .RemoveAll (fmt .Sprintf ("build/%s/cs3" , target ))
405
282
406
- if buildBranch != protoBranch {
407
- checkout (protoBranch , "build/js-cs3apis" )
408
283
}
409
284
410
- // remove leftovers (existing defs)
411
- os .RemoveAll ("build/js-cs3apis/cs3" )
412
-
413
- files := findProtos ()
414
-
415
- args := []string {"--js_out=import_style=commonjs:./build/js-cs3apis" , "--grpc-web_out=import_style=commonjs,mode=grpcwebtext:./build/js-cs3apis/" , "-I." , "-I./third_party" }
416
- args = append (args , files ... )
417
- cmd := exec .Command ("protoc" , args ... )
285
+ cmd = exec .Command ("buf" , "generate" )
418
286
run (cmd )
419
287
420
- // get proto repo commit id
421
- hash := getCommitID ("." )
422
- repo := "build/js-cs3apis"
423
- msg := "Synced to https://github.com/cs3org/cs3apis/tree/" + hash
424
- commit (repo , msg )
425
- }
288
+ for _ , l := range languages {
289
+ target := fmt .Sprintf ("%s-cs3apis" , l )
426
290
427
- func buildNode () {
428
- // Remove build dir
429
- os .RemoveAll ("build/node-cs3apis" )
430
- os .MkdirAll ("build" , 0755 )
431
-
432
- // Clone repo and set branch to current branch
433
- clone ("cs3org/node-cs3apis" , "build" )
434
- protoBranch := getGitBranch ("." )
435
- buildBranch := getGitBranch ("build/node-cs3apis" )
436
- fmt .Printf ("Proto branch: %s\n Build branch: %s\n " , protoBranch , buildBranch )
291
+ if ! isRepoDirty ("build/" + target ) {
292
+ fmt .Println ("Repo is clean, nothing to do" )
293
+ }
437
294
438
- if buildBranch != protoBranch {
439
- checkout (protoBranch , "build/node-cs3apis" )
295
+ // get proto repo commit id
296
+ hash := getCommitID ("." )
297
+ repo := "build/" + target
298
+ msg := "Synced to https://github.com/cs3org/cs3apis/tree/" + hash
299
+ commit (repo , msg )
440
300
}
441
-
442
- // remove leftovers (existing defs)
443
- os .RemoveAll ("build/node-cs3apis/cs3" )
444
-
445
- files := findProtos ()
446
-
447
- args1 := []string {"--ts_out=grpc_js:./build/node-cs3apis" , "--proto_path=." , "--proto_path=./third_party" }
448
- args1 = append (args1 , files ... )
449
- cmd1 := exec .Command ("protoc-gen-grpc-ts" , args1 ... )
450
- run (cmd1 )
451
-
452
- args2 := []string {"--js_out=import_style=commonjs,binary:./build/node-cs3apis" , "--grpc_out=grpc_js:./build/node-cs3apis/" , "--proto_path=." , "--proto_path=./third_party" }
453
- args2 = append (args2 , files ... )
454
- cmd2 := exec .Command ("protoc-gen-grpc" , args2 ... )
455
- run (cmd2 )
456
-
457
- // get proto repo commit id
458
- hash := getCommitID ("." )
459
- repo := "build/node-cs3apis"
460
- msg := "Synced to https://github.com/cs3org/cs3apis/tree/" + hash
461
- commit (repo , msg )
462
301
}
463
302
464
303
func pushPython () {
@@ -478,46 +317,23 @@ func pushNode() {
478
317
}
479
318
480
319
func main () {
481
- if * _buildProto {
482
- fmt .Println ("Compiling and linting protobufs ..." )
483
- buildProto ()
484
- }
485
-
486
- if * _buildGo {
487
- fmt .Println ("Building Go ..." )
488
- buildGo ()
489
- }
320
+ generate ()
490
321
491
322
if * _pushGo {
492
323
fmt .Println ("Pushing Go ..." )
493
324
pushGo ()
494
325
}
495
326
496
- if * _buildPython {
497
- fmt .Println ("Building Python ..." )
498
- buildPython ()
499
- }
500
-
501
327
if * _pushPython {
502
328
fmt .Println ("Pushing Python ..." )
503
329
pushPython ()
504
330
}
505
331
506
- if * _buildJs {
507
- fmt .Println ("Building JS ..." )
508
- buildJS ()
509
- }
510
-
511
332
if * _pushJs {
512
333
fmt .Println ("Pushing Js ..." )
513
334
pushJS ()
514
335
}
515
336
516
- if * _buildNode {
517
- fmt .Println ("Building Node.js ..." )
518
- buildNode ()
519
- }
520
-
521
337
if * _pushNode {
522
338
fmt .Println ("Pushing Node.js ..." )
523
339
pushNode ()
0 commit comments