Skip to content
代码片段 群组 项目
未验证 提交 2132026f 编辑于 作者: Jing T's avatar Jing T 提交者: GitHub
浏览文件

fix Nexus asset query issue. (#724)

* fix Nexus asset query issue.

was not constructing continuationToken URL correctly.

* ignore temp artifact files.

* unit test for download-artifact

* update cached download-artifact.js

* ignore download-artifact test from zap unit tests.

* download-artifact: add unit test / delegate to Github if specified branch is not cached on Nexus

intended for internal jenkins PRs that specifies a non-cached ZAP branch
on Nexus
上级 aaa1322d
No related branches found
No related tags found
无相关合并请求
...@@ -83,3 +83,6 @@ reports ...@@ -83,3 +83,6 @@ reports
# Downloaded artifacts from Nexus / Github / etc via download-artifact script # Downloaded artifacts from Nexus / Github / etc via download-artifact script
artifacts artifacts
**/zap-*.zip
**/zap-*zip.json
**/zap-*.zip.download
...@@ -58,4 +58,8 @@ module.exports = { ...@@ -58,4 +58,8 @@ module.exports = {
transformIgnorePatterns: ['<rootDir>/node_modules/(?!quasar/lang)'], transformIgnorePatterns: ['<rootDir>/node_modules/(?!quasar/lang)'],
snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'], snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
testResultsProcessor: 'jest-sonar-reporter', testResultsProcessor: 'jest-sonar-reporter',
testPathIgnorePatterns: [
'/node_modules/',
'<rootDir>/test/download-artifact.test.js',
],
} }
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
"download-artifact": "ts-node src-script/download-artifact.ts", "download-artifact": "ts-node src-script/download-artifact.ts",
"pkg:download-artifact": "npx pkg src-script/download-artifact.js -t node16-linux-x64,node16-linux-arm64,node16-macos-x64,node16-win-x64 --output dist/download-artifact --compress GZip", "pkg:download-artifact": "npx pkg src-script/download-artifact.js -t node16-linux-x64,node16-linux-arm64,node16-macos-x64,node16-win-x64 --output dist/download-artifact --compress GZip",
"compile:download-artifact": "tsc src-script/download-artifact.ts --esModuleInterop", "compile:download-artifact": "tsc src-script/download-artifact.ts --esModuleInterop",
"test:download-artifact": "npx jest --collectCoverage=false ./test/download-artifact.test.js --testPathIgnorePatterns=[]",
"lic": "node src-script/license-check.js --production", "lic": "node src-script/license-check.js --production",
"lint": "eslint --ext .js,.vue src src-electron src-shared src-script test", "lint": "eslint --ext .js,.vue src src-electron src-shared src-script test",
"lintfix": "eslint --fix --ext .js,.vue src src-electron src-shared src-script test", "lintfix": "eslint --fix --ext .js,.vue src src-electron src-shared src-script test",
......
此差异已折叠。
...@@ -39,7 +39,7 @@ const DEFAULT_OWNER = 'SiliconLabs' ...@@ -39,7 +39,7 @@ const DEFAULT_OWNER = 'SiliconLabs'
const DEFAULT_REPO = 'zap' const DEFAULT_REPO = 'zap'
const NEXUS_SERVER = 'https://nexus.silabs.net' const NEXUS_SERVER = 'https://nexus.silabs.net'
const NEXUS_REPO_NAME = 'zap-release-package' const NEXUS_REPO_NAME = 'zap-release-package'
const cachedBranches = ['master', 'rel'] const nexusCachedBranches = ['master', 'rel']
// cheap and secure // cheap and secure
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0' process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'
...@@ -242,19 +242,35 @@ function platforms(argv: any) { ...@@ -242,19 +242,35 @@ function platforms(argv: any) {
return list return list
} }
async function nexusGetArtifacts(url: string, options: DlOptions) { async function getExistingGithubBranches(
let accumulatedItems: any[] = [] options: DlOptions
let continuationToken = '' ): Promise<string[]> {
const url = `https://api.github.com/repos/${options.owner}/${options.repo}/branches`
let branches = []
try { try {
if (DEBUG) console.log(`GET: ${url}`) if (DEBUG) console.log(`GET: ${url}`)
let resp = await axios.get(url) let resp = await axios.get(url)
branches = resp?.data?.map((x: any) => x.name)
} catch (error) {}
return branches
}
async function nexusGetArtifacts(baseUrl: string, options: DlOptions) {
let accumulatedItems: any[] = []
let continuationToken = ''
try {
if (DEBUG) console.log(`GET: ${baseUrl}`)
let resp = await axios.get(baseUrl)
accumulatedItems = accumulatedItems.concat(resp?.data?.items) accumulatedItems = accumulatedItems.concat(resp?.data?.items)
continuationToken = resp?.data?.continuationToken continuationToken = resp?.data?.continuationToken
let url = ''
do { do {
if (continuationToken) { if (continuationToken) {
url = url + `&continuationToken=${continuationToken}` url = baseUrl + `&continuationToken=${continuationToken}`
} else { } else {
break break
} }
...@@ -414,7 +430,7 @@ async function githubGetArtifacts(options: DlOptions) { ...@@ -414,7 +430,7 @@ async function githubGetArtifacts(options: DlOptions) {
return [...artifacts] return [...artifacts]
} }
} else { } else {
console.error('Unable to retrieve any artifacts for download.') console.error('Unable to find any artifacts for download.')
return [] return []
} }
} }
...@@ -521,15 +537,28 @@ async function main() { ...@@ -521,15 +537,28 @@ async function main() {
nameOnly: y.argv.nameOnly, nameOnly: y.argv.nameOnly,
} }
// Download site sources: Nexus, Github let githubBranches = await getExistingGithubBranches(dlOptions)
// evaluate artifact source
if (dlOptions.src === 'nexus' && (await isReachable(NEXUS_SERVER))) { if (dlOptions.src === 'nexus' && (await isReachable(NEXUS_SERVER))) {
if (!cachedBranches.includes(dlOptions.branch)) { if (
githubBranches.includes(dlOptions.branch) &&
!nexusCachedBranches.includes(dlOptions.branch)
) {
console.log(
`Branch ${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( console.log(
`Branch ${dlOptions.branch} is not cached on Nexus. Defaulting to master branch instead.` `Branch ${dlOptions.branch} is not cached on Nexus. Defaulting to master branch instead.`
) )
dlOptions.branch = 'master' dlOptions.branch = 'master'
} }
}
// Download site sources: Nexus, Github
if (dlOptions.src === 'nexus') {
const nexusUrl = nexusRestApiUrl( const nexusUrl = nexusRestApiUrl(
NEXUS_REPO_NAME, NEXUS_REPO_NAME,
`${dlOptions.owner}/${dlOptions.repo}/${dlOptions.branch}/*` `${dlOptions.owner}/${dlOptions.repo}/${dlOptions.branch}/*`
......
/**
*
* Copyright (c) 2021 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.
*
*
* @jest-environment node
*/
const { exec, execSync, execFile } = require('child_process')
const path = require('node:path')
const download_artifact_script = path.join(
__dirname,
'../src-script/download-artifact.js'
)
beforeAll(() => {
execSync(`npm run compile:download-artifact`)
execSync(`chmod a+x ${download_artifact_script}`)
})
test('Downloading from Nexus (default)', async () => {
let output = execSync(download_artifact_script)
console.log(output.toString())
expect(output.toString()).toMatch(/.*nexus.silabs.*/)
expect(output.toString()).toMatch(/.*zap-...-zip.zip[.]*done.*/)
})
test('Downloading from Github', async () => {
let output = execSync(`${download_artifact_script} --src github`)
console.log(output.toString())
expect(output.toString()).toMatch(/.*github.com.*/)
expect(output.toString()).toMatch(/.*zap-...-zip.zip[.]*done.*/)
})
test('Default back to master branch if unknown branch is specified', async () => {
let output = execSync(
`${download_artifact_script} -b random_unknown_branch_name`
)
console.log(output.toString())
expect(output.toString()).toMatch(/.Defaulting to master branch instead.*/)
})
test('Download from Github if specified branch is available on Github but not Nexus', async () => {
let output = execSync(`${download_artifact_script} -b unit_test_branch`)
console.log(output.toString())
expect(output.toString()).toMatch(
/.*Defaulting to master branch on Github instead.*/
)
})
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册