更新
更旧
/**
*
* Copyright (c) 2020 Silicon Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter =
(this && this.__awaiter) ||
function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P
? value
: new P(function (resolve) {
resolve(value)
})
}
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function fulfilled(value) {
try {
step(generator.next(value))
} catch (e) {
reject(e)
}
}
function rejected(value) {
try {
step(generator['throw'](value))
} catch (e) {
reject(e)
}
}
function step(result) {
result.done
? resolve(result.value)
: adopt(result.value).then(fulfilled, rejected)
}
step((generator = generator.apply(thisArg, _arguments || [])).next())
})
}
var __generator =
(this && this.__generator) ||
function (thisArg, body) {
var _ = {
label: 0,
sent: function () {
if (t[0] & 1) throw t[1]
return t[1]
},
trys: [],
ops: [],
},
f,
y,
t,
g
return (
(g = { next: verb(0), throw: verb(1), return: verb(2) }),
typeof Symbol === 'function' &&
(g[Symbol.iterator] = function () {
return this
}),
g
)
function verb(n) {
return function (v) {
return step([n, v])
}
}
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
if (f) throw new TypeError('Generator is already executing.')
while (_)
try {
if (
((f = 1),
y &&
(t =
op[0] & 2
? y['return']
: op[0]
? y['throw'] || ((t = y['return']) && t.call(y), 0)
: y.next) &&
!(t = t.call(y, op[1])).done)
)
return t
if (((y = 0), t)) op = [op[0] & 2, t.value]
switch (op[0]) {
case 0:
case 1:
t = op
break
case 4:
_.label++
return { value: op[1], done: false }
case 5:
_.label++
y = op[1]
op = [0]
continue
case 7:
op = _.ops.pop()
_.trys.pop()
continue
default:
if (
!((t = _.trys), (t = t.length > 0 && t[t.length - 1])) &&
(op[0] === 6 || op[0] === 2)
) {
_ = 0
continue
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1]
break
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1]
t = op
break
}
if (t && _.label < t[2]) {
_.label = t[2]
_.ops.push(op)
break
}
if (t[2]) _.ops.pop()
_.trys.pop()
continue
}
op = body.call(thisArg, _)
} catch (e) {
op = [6, e]
y = 0
} finally {
f = t = 0
}
if (op[0] & 5) throw op[1]
return { value: op[0] ? op[1] : void 0, done: true }
}
var __spreadArray =
(this && this.__spreadArray) ||
function (to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar; i < l; i++) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i)
ar[i] = from[i]
}
return to.concat(ar || Array.prototype.slice.call(from))
}
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod }
}
exports.__esModule = true
// This util script downloads ZAP artifact from Github.com
// Usage: node ./download-artifact.js $branch [ $commit | latest ]
var octokit_1 = require('octokit')
var http_status_codes_1 = require('http-status-codes')
var nodejs_file_downloader_1 = __importDefault(
require('nodejs-file-downloader')
)
var yargs_1 = __importDefault(require('yargs'))
var node_os_1 = __importDefault(require('node:os'))
var is_reachable_1 = __importDefault(require('is-reachable'))
var axios_1 = __importDefault(require('axios'))
var path_1 = __importDefault(require('path'))
var fs_1 = __importDefault(require('fs'))
var date_fns_1 = require('date-fns')
var DEBUG = false
var DEFAULT_COMMIT_LATEST = 'commit_latest'
var DEFAULT_BRANCH = 'master'
var DEFAULT_OWNER = 'SiliconLabs'
var DEFAULT_REPO = 'zap'
var NEXUS_SERVER = 'https://nexus.silabs.net'
var NEXUS_REPO_NAME = 'zap-release-package'
var nexusCachedBranches = ['master', 'rel']
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'
return ''
.concat(NEXUS_SERVER, '/service/rest/v1/search/assets?repository=')
.concat(repository, '&name=')
.concat(nameFilter)
return __awaiter(this, void 0, void 0, function () {
var resp
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4 /*yield*/, axios_1['default'].get(url)]
case 1:
resp = _a.sent()
return [2 /*return*/, resp.data]
}
})
})
}
function verifyPlatformAndFormat(name, platforms, formats) {
// verify platform
var verifyPlatform = platforms.reduce(function (prev, cur) {
return prev || name.includes(cur)
}, false)
var verifyFormat = formats.reduce(function (prev, cur) {
return prev || name.endsWith(cur)
}, false)
if (!verifyPlatform || !verifyFormat) {
return false
}
return true
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
function githubDownloadArtifacts(
artifacts,
dlOptions,
verifyPlatformAndFormat
) {
return __awaiter(this, void 0, void 0, function () {
var outputDir,
githubToken,
owner,
repo,
branch,
commit,
platforms,
formats,
_i,
artifacts_1,
artifact,
archive_download_url,
name_1,
created_at,
size_in_bytes
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
;(outputDir = dlOptions.outputDir),
(githubToken = dlOptions.githubToken),
(owner = dlOptions.owner),
(repo = dlOptions.repo),
(branch = dlOptions.branch),
(commit = dlOptions.commit),
(platforms = dlOptions.platforms),
(formats = dlOptions.formats)
if (artifacts.length == 0) {
return [2 /*return*/]
}
console.log(
'Repo: https://github.com/'
.concat(owner, '/')
.concat(repo, '/tree/')
.concat(branch)
)
console.log(
'Commit: https://github.com/'
.concat(owner, '/')
.concat(repo, '/commit/')
.concat(
commit === null || commit === void 0
? void 0
: commit.substring(0, 7)
)
)
if (!artifacts.length) return [3 /*break*/, 4]
if (dlOptions.mirror) {
outputDir = path_1['default'].join(
outputDir,
'artifacts',
dlOptions.branch,
artifacts[0].created_at
)
}
console.log('Output directory: '.concat(outputDir))
;(_i = 0), (artifacts_1 = artifacts)
_a.label = 1
case 1:
if (!(_i < artifacts_1.length)) return [3 /*break*/, 4]
artifact = artifacts_1[_i]
;(archive_download_url = artifact.archive_download_url),
(name_1 = artifact.name),
(created_at = artifact.created_at),
(size_in_bytes = artifact.size_in_bytes)
if (!verifyPlatformAndFormat.call(null, name_1, platforms, formats)) {
return [3 /*break*/, 3]
}
return [
4 /*yield*/,
download(
archive_download_url,
outputDir,
githubToken,
''.concat(name_1, '.zip')
),
// download metadata file.
]
case 2:
_a.sent()
// download metadata file.
try {
fs_1['default'].writeFileSync(
path_1['default'].join(outputDir, ''.concat(name_1, '.json')),
JSON.stringify(artifact, null, 4)
)
} catch (err) {
console.error(err)
}
_a.label = 3
case 3:
_i++
return [3 /*break*/, 1]
case 4:
return [2 /*return*/]
}
})
})
}
function githubListArtifacts(artifacts, dlOptions, verifyPlatformAndFormat) {
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
return __awaiter(this, void 0, void 0, function () {
var branch,
outputDir,
platforms,
formats,
artifactsList,
_i,
artifacts_2,
artifact,
name_2,
artifactPath
return __generator(this, function (_a) {
;(branch = dlOptions.branch),
(outputDir = dlOptions.outputDir),
(platforms = dlOptions.platforms),
(formats = dlOptions.formats)
if (artifacts.length == 0) {
return [2 /*return*/]
}
if (artifacts.length) {
if (dlOptions.mirror) {
outputDir = path_1['default'].join(outputDir, 'artifacts')
}
artifactsList = []
for (_i = 0, artifacts_2 = artifacts; _i < artifacts_2.length; _i++) {
artifact = artifacts_2[_i]
name_2 = artifact.name
if (!verifyPlatformAndFormat.call(null, name_2, platforms, formats)) {
continue
}
artifactPath = path_1['default'].join(
branch,
artifacts[0].created_at,
''.concat(name_2, '.zip')
)
if (DEBUG) console.log(''.concat(artifactPath))
artifactsList.push(artifactPath)
}
try {
fs_1['default'].mkdirSync(outputDir, { recursive: true })
fs_1['default'].writeFileSync(
path_1['default'].join(outputDir, ''.concat(branch, '.txt')),
artifactsList.join('\n')
)
} catch (err) {
console.error(err)
}
}
return [2 /*return*/]
})
})
}
function download(archive_download_url, outDir, githubToken, name) {
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
return __awaiter(this, void 0, void 0, function () {
var chunkCount, chunkSize, downloader, error_1
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
chunkCount = 0
chunkSize = 200
downloader = new nodejs_file_downloader_1['default']({
url: archive_download_url,
directory: outDir,
cloneFiles: false,
maxAttempts: 3,
headers: {
'User-Agent': 'Silabs Download Script',
Authorization: 'token '.concat(githubToken),
},
onProgress: function (percentage, chunk, remainingSize) {
chunkCount++
if (chunkCount > chunkSize) {
process.stdout.write('.')
chunkCount = 0
}
},
})
_a.label = 1
case 1:
_a.trys.push([1, 3, , 4])
process.stdout.write('Downloading '.concat(name, '...'))
return [4 /*yield*/, downloader.download()] //Downloader.download() returns a promise.
case 2:
_a.sent() //Downloader.download() returns a promise.
process.stdout.write('done\n')
return [3 /*break*/, 4]
case 3:
error_1 = _a.sent()
process.stdout.write('failed\n')
console.error(error_1)
return [3 /*break*/, 4]
case 4:
return [2 /*return*/]
}
})
})
var platformMap = {
linux: 'linux',
win32: 'win',
darwin: 'mac',
}
var list = []
if (argv.linux) {
list.push('linux')
}
if (argv.win) {
list.push('win')
}
if (argv.mac) {
list.push('mac')
}
if (!argv.linux && !argv.win && !argv.mac) {
list.push(platformMap[node_os_1['default'].platform()])
}
return list
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
function getExistingGithubBranches(options) {
var _a
return __awaiter(this, void 0, void 0, function () {
var url, branches, resp, error_2
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
url = 'https://api.github.com/repos/'
.concat(options.owner, '/')
.concat(options.repo, '/branches')
branches = []
_b.label = 1
case 1:
_b.trys.push([1, 3, , 4])
if (DEBUG) console.log('GET: '.concat(url))
return [4 /*yield*/, axios_1['default'].get(url)]
case 2:
resp = _b.sent()
branches =
(_a = resp === null || resp === void 0 ? void 0 : resp.data) ===
null || _a === void 0
? void 0
: _a.map(function (x) {
return x.name
})
return [3 /*break*/, 4]
case 3:
error_2 = _b.sent()
return [3 /*break*/, 4]
case 4:
return [2 /*return*/, branches]
}
})
})
}
function nexusGetArtifacts(baseUrl, options) {
var _a, _b, _c, _d
return __awaiter(this, void 0, void 0, function () {
var accumulatedItems, continuationToken, resp, url, error_3
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
accumulatedItems = []
continuationToken = ''
_e.label = 1
case 1:
_e.trys.push([1, 7, , 8])
if (DEBUG) console.log('GET: '.concat(baseUrl))
return [4 /*yield*/, axios_1['default'].get(baseUrl)]
case 2:
resp = _e.sent()
accumulatedItems = accumulatedItems.concat(
(_a = resp === null || resp === void 0 ? void 0 : resp.data) ===
null || _a === void 0
? void 0
: _a.items
)
continuationToken =
(_b = resp === null || resp === void 0 ? void 0 : resp.data) ===
null || _b === void 0
? void 0
: _b.continuationToken
url = ''
_e.label = 3
case 3:
if (continuationToken) {
url = baseUrl + '&continuationToken='.concat(continuationToken)
} else {
return [3 /*break*/, 6]
}
if (DEBUG) console.log('GET: '.concat(url))
return [4 /*yield*/, axios_1['default'].get(url)]
case 4:
resp = _e.sent()
accumulatedItems = accumulatedItems.concat(
(_c = resp === null || resp === void 0 ? void 0 : resp.data) ===
null || _c === void 0
? void 0
: _c.items
)
continuationToken =
(_d = resp === null || resp === void 0 ? void 0 : resp.data) ===
null || _d === void 0
? void 0
: _d.continuationToken
_e.label = 5
case 5:
if (continuationToken) return [3 /*break*/, 3]
_e.label = 6
case 6:
return [3 /*break*/, 8]
case 7:
error_3 = _e.sent()
console.error(error_3)
return [3 /*break*/, 8]
case 8:
return [2 /*return*/, accumulatedItems]
}
})
})
function nexusDownloadArtifacts(items, dlOptions, verifyPlatformAndFormat) {
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
return __awaiter(this, void 0, void 0, function () {
var owner,
repo,
branch,
outputDir,
platforms,
formats,
dateRegex,
date,
artifacts,
jsonFiles,
jsonContent,
_i,
artifacts_3,
artifact,
downloadUrl,
name_3
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
;(owner = dlOptions.owner),
(repo = dlOptions.repo),
(branch = dlOptions.branch),
(outputDir = dlOptions.outputDir),
(platforms = dlOptions.platforms),
(formats = dlOptions.formats)
dateRegex = new RegExp(
''.concat(owner, '/').concat(repo, '/').concat(branch, '/([^/]*)')
)
items.sort(function (a, b) {
var _a, _b, _c
// sort entries via 'path' key
// e.g. path: 'SiliconLabs/zap/master/2022-07-22T14:55:43Z/zap-win-zip.json'
var res =
(_a = a === null || a === void 0 ? void 0 : a.path) === null ||
_a === void 0
? void 0
: _a.match(dateRegex)
var dateA = new Date(
(_b = a === null || a === void 0 ? void 0 : a.path) === null ||
_b === void 0
? void 0
: _b.match(dateRegex)[1]
)
var dateB = new Date(
(_c = b === null || b === void 0 ? void 0 : b.path) === null ||
_c === void 0
? void 0
: _c.match(dateRegex)[1]
)
if ((0, date_fns_1.isEqual)(dateA, dateB)) {
return b.path.localeCompare(a.path)
} else {
return (0, date_fns_1.compareDesc)(dateA, dateB)
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
})
if (!(items.length > 1)) return [3 /*break*/, 6]
date = items[0].path.match(dateRegex)[1]
console.log(
'Repo: '
.concat(NEXUS_SERVER, '/#browse/browse:')
.concat(NEXUS_REPO_NAME, ':')
.concat(dlOptions.owner, '/')
.concat(dlOptions.repo, '/')
.concat(dlOptions.branch, '/')
.concat(date)
)
return [
4 /*yield*/,
nexusGetArtifacts(
nexusRestApiUrl(
NEXUS_REPO_NAME,
''
.concat(dlOptions.owner, '/')
.concat(dlOptions.repo, '/')
.concat(dlOptions.branch, '/')
.concat(date, '/*')
),
dlOptions
),
// find commit
]
case 1:
artifacts = _a.sent()
jsonFiles = artifacts.filter(function (x) {
return x.contentType.toLowerCase().includes('json')
})
return [4 /*yield*/, urlContent(jsonFiles.shift().downloadUrl)]
case 2:
jsonContent = _a.sent()
console.log(
'Commit: '.concat(jsonContent.workflow_run.head_sha.substring(0, 7))
)
console.log('Output directory: '.concat(outputDir))
;(_i = 0), (artifacts_3 = artifacts)
_a.label = 3
case 3:
if (!(_i < artifacts_3.length)) return [3 /*break*/, 6]
artifact = artifacts_3[_i]
downloadUrl = artifact.downloadUrl
name_3 = downloadUrl.substring(downloadUrl.lastIndexOf('/') + 1)
// download .json from Nexus as well.
// This is needed by internal CI to track zap version across builds.
formats.push('.json')
if (!verifyPlatformAndFormat.call(null, name_3, platforms, formats)) {
return [3 /*break*/, 5]
}
return [
4 /*yield*/,
download(artifact.downloadUrl, outputDir, undefined, name_3),
]
case 4:
_a.sent()
_a.label = 5
case 5:
_i++
return [3 /*break*/, 3]
case 6:
return [2 /*return*/]
}
})
})
}
/**
* Get list of artifacts from Github:
* @param {*} owner
* @param {*} repo
* @param {*} branch
* @param {*} commit ["latest" | commit_hash_id]
* @returns list of artifact entries following Github Artifacts schema
* https://docs.github.com/en/rest/actions/artifacts
*/
function githubGetArtifacts(options) {
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
var _a, _b, _c, _d, _e, _f
return __awaiter(this, void 0, void 0, function () {
var owner,
repo,
branch,
commit,
githubToken,
octokit,
refCommit,
refWorkflowRunId,
res,
artifacts
return __generator(this, function (_g) {
switch (_g.label) {
case 0:
;(owner = options.owner),
(repo = options.repo),
(branch = options.branch),
(commit = options.commit),
(githubToken = options.githubToken)
octokit = new octokit_1.Octokit({
githubToken: githubToken,
})
refCommit = ''
refWorkflowRunId = 0
return [
4 /*yield*/,
octokit.request('GET /repos/{owner}/{repo}/actions/artifacts', {
owner: owner,
repo: repo,
}),
]
case 1:
res = _g.sent()
if (res.status != http_status_codes_1.StatusCodes.OK) {
console.error(
'Failed to query Github Artifacts API to download artifacts'
)
return [2 /*return*/, []]
}
artifacts = res.data.artifacts
// filter all artifact with current branch
artifacts =
artifacts === null || artifacts === void 0
? void 0
: artifacts.filter(function (e) {
return e.workflow_run.head_branch === branch
})
if (artifacts && artifacts.length) {
if (commit === DEFAULT_COMMIT_LATEST) {
refCommit =
(_b =
(_a = artifacts[0]) === null || _a === void 0
? void 0
: _a.workflow_run) === null || _b === void 0
? void 0
: _b.head_sha
options.commit = refCommit
refWorkflowRunId =
(_d =
(_c = artifacts[0]) === null || _c === void 0
? void 0
: _c.workflow_run) === null || _d === void 0
? void 0
: _d.id
return [
2 /*return*/,
artifacts.filter(function (artifact) {
return (
artifact.workflow_run.head_sha === refCommit &&
artifact.workflow_run.id === refWorkflowRunId
)
}),
]
} else {
refCommit = commit
artifacts =
artifacts === null || artifacts === void 0
? void 0
: artifacts.filter(function (artifact) {
return artifact.workflow_run.head_sha.startsWith(
refCommit
)
})
// multiple builds can correspond to the same commit id
// always pick artifacts with the latest run (newest run "id")
if (
artifacts === null || artifacts === void 0
? void 0
: artifacts.length
) {
refWorkflowRunId =
(_f =
(_e = artifacts[0]) === null || _e === void 0
? void 0
: _e.workflow_run) === null || _f === void 0
? void 0
: _f.id
artifacts = artifacts.filter(function (artifact) {
return artifact.workflow_run.id == refWorkflowRunId
})
}
return [2 /*return*/, __spreadArray([], artifacts, true)]
} else {
console.error('Unable to find any artifacts for download.')
return [2 /*return*/, []]
}
return [2 /*return*/]
}
})
})
return yargs_1['default']
.option('mac', {
alias: 'm',
description: 'Download macOS artifacts',
.option('linux', {
alias: 'l',
description: 'Download Linux artifacts',
.option('win', {
alias: 'w',
description: 'Download Windows artifacts',
.option('outputDir', {
description: 'Output dir',
default: process.cwd(),
type: 'string',
.option('commit', {
alias: 'c',
description: 'Commit hash for Github artifact',
default: DEFAULT_COMMIT_LATEST,
.option('branch', {
alias: 'b',
description: 'Commit hash for Github artifact',
default: DEFAULT_BRANCH,
.option('repo', {
alias: 'r',
description: 'Name of Github repo: https://github.com/${owner}/${repo}',
default: DEFAULT_REPO,
.option('owner', {
alias: 'o',
description: 'Owner of Github repo: https://github.com/${owner}/${repo}',
default: DEFAULT_OWNER,
.option('githubToken', {
description: 'Define GITHUB_TOKEN for downloading artifacts from Github',
default: null,
type: 'string',
.option('formats', {
alias: 'f',
description: 'Define a list of desired format for artifacts',
default: ['zip'],
type: 'array',
.option('mirror', {
description:
'Download Github artifacts into ./artifacts folder to simplify Nexus upload process.',
type: 'boolean',
default: false,
.option('nameOnly', {
description:
'Output list of latest artifacts to <branch_name>.txt. Used for verifying the presence on Nexus',
type: 'boolean',
default: false,
.option('src', {
description: 'URL source for obtaining ZAP binaries',
type: 'string',
default: 'nexus',
choices: ['github', 'nexus'],
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
return __awaiter(this, void 0, void 0, function () {
var y, dlOptions, githubBranches, _a, nexusUrl, nexusItems, artifacts
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
y = configureBuildCommand()
dlOptions = {
githubToken: y.argv.githubToken
? y.argv.githubToken
: process.env.GITHUB_TOKEN,
owner: y.argv.owner,
repo: y.argv.repo,
branch: y.argv.branch,
commit: y.argv.commit,
outputDir: y.argv.outputDir,
platforms: platforms(y.argv),
formats: y.argv.formats,
src: y.argv.src,
mirror: y.argv.mirror,
nameOnly: y.argv.nameOnly,
}
return [
4 /*yield*/,
getExistingGithubBranches(dlOptions),
// evaluate artifact source
]
case 1:
githubBranches = _b.sent()
_a = dlOptions.src === 'nexus'
if (!_a) return [3 /*break*/, 3]
return [4 /*yield*/, (0, is_reachable_1['default'])(NEXUS_SERVER)]
case 2:
_a = _b.sent()
_b.label = 3
case 3:
// evaluate artifact source
if (_a) {
if (
githubBranches.includes(dlOptions.branch) &&
!nexusCachedBranches.includes(dlOptions.branch)
) {
console.log(
'Branch '.concat(
dlOptions.branch,
' is not cached on Nexus. Defaulting to master branch on Github instead.'
)
)
dlOptions.src = 'github'
} else if (!nexusCachedBranches.includes(dlOptions.branch)) {
console.log(
'Branch '.concat(
dlOptions.branch,
' is not cached on Nexus. Defaulting to master branch instead.'
)
)
dlOptions.branch = 'master'
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
}
if (!(dlOptions.src === 'nexus')) return [3 /*break*/, 6]
nexusUrl = nexusRestApiUrl(
NEXUS_REPO_NAME,
''
.concat(dlOptions.owner, '/')
.concat(dlOptions.repo, '/')
.concat(dlOptions.branch, '/*')
)
return [4 /*yield*/, nexusGetArtifacts(nexusUrl, dlOptions)]
case 4:
nexusItems = _b.sent()
return [
4 /*yield*/,
nexusDownloadArtifacts(
nexusItems,
dlOptions,
verifyPlatformAndFormat
),
]
case 5:
_b.sent()
return [3 /*break*/, 11]
case 6:
if (!dlOptions.githubToken) {
return [
2 /*return*/,
console.error(
'Missing GITHUB_TOKEN env variable for Github.com access!\nFind more information at https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret'
),
]
}
return [4 /*yield*/, githubGetArtifacts(dlOptions)]
case 7:
artifacts = _b.sent()
if (!dlOptions.nameOnly) return [3 /*break*/, 9]
return [
4 /*yield*/,
githubListArtifacts(artifacts, dlOptions, verifyPlatformAndFormat),
]
case 8:
_b.sent()
return [3 /*break*/, 11]
case 9:
return [
4 /*yield*/,
githubDownloadArtifacts(
artifacts,
dlOptions,
verifyPlatformAndFormat
),
]
case 10:
_b.sent()
_b.label = 11
case 11:
return [2 /*return*/]
}
})
})