Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix-download-locations #20

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/detect/detect-facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,6 @@ export class DetectFacade {
)
}

if (this.isDiagnosticModeEnabled()) {
const diagnosticZip = await this.getDiagnosticFilesPaths(outputPath)
await uploadArtifact('Detect Diagnostic Zip', outputPath, diagnosticZip)
}

return hasPolicyViolations
}

Expand Down Expand Up @@ -254,6 +249,12 @@ export class DetectFacade {
`${TOOL_NAME} exited with code ${detectExitCode} - ${exitCodeName}.`
)

// always process diagnostics regardless of exit code
if (this.isDiagnosticModeEnabled()) {
const diagnosticZip = await this.getDiagnosticFilesPaths(outputPath)
await uploadArtifact('Detect Diagnostic Zip', outputPath, diagnosticZip)
}

const isSuccessOrPolicyFailure =
detectExitCode === ExitCode.SUCCESS ||
detectExitCode === ExitCode.FAILURE_POLICY_VIOLATION
Expand Down
44 changes: 40 additions & 4 deletions src/detect/detect-tool-downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,45 @@ import { IHeaders } from 'typed-rest-client/Interfaces'
import { DetectToolsVersions } from './detect-tools-versions'
import { DetectToolVersion } from './detect-tool-version'

const DETECT_BINARY_REPO_URL = 'https://sig-repo.synopsys.com'
// new location since split with Synopsys
const DETECT_BINARY_REPO_URL = 'https://repo.blackduck.com'

// curate the correct URI for the version
const DETECT_URI_BASE = '/bds-integrations-release/com/'
const DETECT_LOCATION_SYNOPSYS = `${DETECT_URI_BASE}synopsys/integration/synopsys-detect`
const DETECT_LOCATION_BLACKDUCK = `${DETECT_URI_BASE}blackduck/integration/detect`

export const TOOL_NAME = 'detect'

export class DetectToolDownloader implements ToolDownloader {
private AUTH_URI: string
private DOWNLOAD_URI: string
private TOOL_NAME_LOCAL: string

constructor() {
// assume properties for v9.x or earlier
this.AUTH_URI = `${DETECT_BINARY_REPO_URL}/api/storage/${DETECT_LOCATION_SYNOPSYS}`
this.DOWNLOAD_URI = `${DETECT_BINARY_REPO_URL}${DETECT_LOCATION_SYNOPSYS}`
this.TOOL_NAME_LOCAL = 'synopsys-detect-'
}

private setupUris(versionAsNum = 8): undefined {
if (versionAsNum >= 10) {
// new location to download versions >= 10
this.AUTH_URI = `${DETECT_BINARY_REPO_URL}/api/storage/${DETECT_LOCATION_BLACKDUCK}`
this.DOWNLOAD_URI = `${DETECT_BINARY_REPO_URL}${DETECT_LOCATION_BLACKDUCK}`
this.TOOL_NAME_LOCAL = 'detect-'
}
}

private async getDetectVersions(): Promise<DetectToolsVersions> {
const authenticationClient = new HttpClient(APPLICATION_NAME)
const headers: IHeaders = {
'X-Result-Detail': 'info'
}

const httpClientResponse = await authenticationClient.get(
`${DETECT_BINARY_REPO_URL}/api/storage/bds-integrations-release/com/synopsys/integration/synopsys-detect?properties`,
`${this.AUTH_URI}?properties`,
headers
)
const responseBody = await httpClientResponse.readBody()
Expand All @@ -28,11 +55,20 @@ export class DetectToolDownloader implements ToolDownloader {
private async findDetectVersion(
version?: string
): Promise<DetectToolVersion> {
// default to 8.x
let majorVersionAsNum = 8
if (version?.match(/^[0-9]+/)) {
majorVersionAsNum = parseInt(version)
}

// URIs differ based on version used
this.setupUris(majorVersionAsNum)

if (version?.match(/^[0-9]+.[0-9]+.[0-9]+$/)) {
return {
url: `${DETECT_BINARY_REPO_URL}/bds-integrations-release/com/synopsys/integration/synopsys-detect/${version}/synopsys-detect-${version}.jar`,
url: `${this.DOWNLOAD_URI}/${version}/${this.TOOL_NAME_LOCAL}${version}.jar`,
version,
jarName: `synopsys-detect-${version}.jar`
jarName: `${this.TOOL_NAME_LOCAL}${version}.jar`
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ async function run(): Promise<void> {
// eslint-disable-next-line github/no-then
run().catch(error => {
core.error(error)
if (error instanceof Error) {
if (error.stack) core.error(error.stack)
core.setFailed(error.message)
}

// TypeError is not a decendant class of Error (instanceof)
if (error.stack) core.error(error.stack)
core.setFailed(error.message)
})
Loading