-
Notifications
You must be signed in to change notification settings - Fork 40
Martin/rea 132 create socket scan create reach option for running tier 1 #704
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
Changes from all commits
67e3648
ee0199d
15916db
9d771f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,13 +7,16 @@ import { fetchSupportedScanFileNames } from './fetch-supported-scan-file-names.m | |||||||||||||||||||||||||||||
| import { handleScanReport } from './handle-scan-report.mts' | ||||||||||||||||||||||||||||||
| import { outputCreateNewScan } from './output-create-new-scan.mts' | ||||||||||||||||||||||||||||||
| import constants from '../../constants.mts' | ||||||||||||||||||||||||||||||
| import { handleApiCall } from '../../utils/api.mts' | ||||||||||||||||||||||||||||||
| import { checkCommandInput } from '../../utils/check-input.mts' | ||||||||||||||||||||||||||||||
| import { spawnCoana } from '../../utils/coana.mts' | ||||||||||||||||||||||||||||||
| import { getPackageFilesForScan } from '../../utils/path-resolve.mts' | ||||||||||||||||||||||||||||||
| import { setupSdk } from '../../utils/sdk.mts' | ||||||||||||||||||||||||||||||
| import { readOrDefaultSocketJson } from '../../utils/socketjson.mts' | ||||||||||||||||||||||||||||||
| import { detectManifestActions } from '../manifest/detect-manifest-actions.mts' | ||||||||||||||||||||||||||||||
| import { generateAutoManifest } from '../manifest/generate_auto_manifest.mts' | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import type { OutputKind } from '../../types.mts' | ||||||||||||||||||||||||||||||
| import type { CResult, OutputKind } from '../../types.mts' | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export async function handleCreateNewScan({ | ||||||||||||||||||||||||||||||
| autoManifest, | ||||||||||||||||||||||||||||||
|
|
@@ -28,6 +31,7 @@ export async function handleCreateNewScan({ | |||||||||||||||||||||||||||||
| outputKind, | ||||||||||||||||||||||||||||||
| pendingHead, | ||||||||||||||||||||||||||||||
| pullRequest, | ||||||||||||||||||||||||||||||
| reach, | ||||||||||||||||||||||||||||||
| readOnly, | ||||||||||||||||||||||||||||||
| repoName, | ||||||||||||||||||||||||||||||
| report, | ||||||||||||||||||||||||||||||
|
|
@@ -46,6 +50,7 @@ export async function handleCreateNewScan({ | |||||||||||||||||||||||||||||
| pendingHead: boolean | ||||||||||||||||||||||||||||||
| pullRequest: number | ||||||||||||||||||||||||||||||
| outputKind: OutputKind | ||||||||||||||||||||||||||||||
| reach: boolean | ||||||||||||||||||||||||||||||
| readOnly: boolean | ||||||||||||||||||||||||||||||
| repoName: string | ||||||||||||||||||||||||||||||
| report: boolean | ||||||||||||||||||||||||||||||
|
|
@@ -106,8 +111,30 @@ export async function handleCreateNewScan({ | |||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| let scanPaths: string[] = packagePaths | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // If reachability is enabled, perform reachability analysis | ||||||||||||||||||||||||||||||
| if (reach) { | ||||||||||||||||||||||||||||||
| const reachResult = await performReachabilityAnalysis({ | ||||||||||||||||||||||||||||||
| packagePaths, | ||||||||||||||||||||||||||||||
| orgSlug, | ||||||||||||||||||||||||||||||
| cwd, | ||||||||||||||||||||||||||||||
| repoName, | ||||||||||||||||||||||||||||||
| branchName, | ||||||||||||||||||||||||||||||
| outputKind, | ||||||||||||||||||||||||||||||
| interactive, | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if (!reachResult.ok) { | ||||||||||||||||||||||||||||||
| await outputCreateNewScan(reachResult, outputKind, interactive) | ||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| scanPaths = reachResult.data?.scanPaths || [] | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const fullScanCResult = await fetchCreateOrgFullScan( | ||||||||||||||||||||||||||||||
| packagePaths, | ||||||||||||||||||||||||||||||
| scanPaths, | ||||||||||||||||||||||||||||||
| orgSlug, | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| commitHash, | ||||||||||||||||||||||||||||||
|
|
@@ -153,3 +180,101 @@ export async function handleCreateNewScan({ | |||||||||||||||||||||||||||||
| await outputCreateNewScan(fullScanCResult, outputKind, interactive) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| async function performReachabilityAnalysis({ | ||||||||||||||||||||||||||||||
| branchName, | ||||||||||||||||||||||||||||||
| cwd, | ||||||||||||||||||||||||||||||
| orgSlug, | ||||||||||||||||||||||||||||||
| packagePaths, | ||||||||||||||||||||||||||||||
| repoName, | ||||||||||||||||||||||||||||||
| }: { | ||||||||||||||||||||||||||||||
| packagePaths: string[] | ||||||||||||||||||||||||||||||
| orgSlug: string | ||||||||||||||||||||||||||||||
| cwd: string | ||||||||||||||||||||||||||||||
| repoName: string | ||||||||||||||||||||||||||||||
| branchName: string | ||||||||||||||||||||||||||||||
| outputKind: OutputKind | ||||||||||||||||||||||||||||||
| interactive: boolean | ||||||||||||||||||||||||||||||
| }): Promise<CResult<{ scanPaths?: string[] }>> { | ||||||||||||||||||||||||||||||
| logger.info('Starting reachability analysis...') | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| packagePaths = packagePaths.filter( | ||||||||||||||||||||||||||||||
| p => | ||||||||||||||||||||||||||||||
| /* Exclude DOT_SOCKET_DOT_FACTS_JSON from previous runs */ !p.includes( | ||||||||||||||||||||||||||||||
| constants.DOT_SOCKET_DOT_FACTS_JSON, | ||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
|
Comment on lines
+201
to
+206
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parameter
Suggested change
Spotted by Diamond (based on custom rule: Custom rules) |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Lazily access constants.spinner. | ||||||||||||||||||||||||||||||
| const { spinner } = constants | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Setup SDK for uploading manifests | ||||||||||||||||||||||||||||||
| const sockSdkCResult = await setupSdk() | ||||||||||||||||||||||||||||||
| if (!sockSdkCResult.ok) { | ||||||||||||||||||||||||||||||
| return sockSdkCResult | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| const sockSdk = sockSdkCResult.data | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Upload manifests to get tar hash | ||||||||||||||||||||||||||||||
| spinner.start('Uploading manifests for reachability analysis...') | ||||||||||||||||||||||||||||||
| const uploadCResult = await handleApiCall( | ||||||||||||||||||||||||||||||
| sockSdk.uploadManifestFiles(orgSlug, packagePaths), | ||||||||||||||||||||||||||||||
| { desc: 'upload manifests' }, | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| spinner.stop() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if (!uploadCResult.ok) { | ||||||||||||||||||||||||||||||
| return uploadCResult | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const tarHash = (uploadCResult.data as { tarHash?: string })?.tarHash | ||||||||||||||||||||||||||||||
| if (!tarHash) { | ||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||
| ok: false, | ||||||||||||||||||||||||||||||
| message: 'Failed to get manifest tar hash', | ||||||||||||||||||||||||||||||
| cause: 'Server did not return a tar hash for the uploaded manifests', | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| logger.success(`Manifests uploaded successfully. Tar hash: ${tarHash}`) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Run Coana with the manifests tar hash | ||||||||||||||||||||||||||||||
| logger.info('Running reachability analysis with Coana...') | ||||||||||||||||||||||||||||||
| const coanaResult = await spawnCoana( | ||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||
| 'run', | ||||||||||||||||||||||||||||||
| cwd, | ||||||||||||||||||||||||||||||
| '--output-dir', | ||||||||||||||||||||||||||||||
| cwd, | ||||||||||||||||||||||||||||||
| '--socket-mode', | ||||||||||||||||||||||||||||||
| constants.DOT_SOCKET_DOT_FACTS_JSON, | ||||||||||||||||||||||||||||||
| '--disable-report-submission', | ||||||||||||||||||||||||||||||
| '--manifests-tar-hash', | ||||||||||||||||||||||||||||||
| tarHash, | ||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| cwd, | ||||||||||||||||||||||||||||||
| stdio: 'inherit', | ||||||||||||||||||||||||||||||
| env: { | ||||||||||||||||||||||||||||||
| ...process.env, | ||||||||||||||||||||||||||||||
| SOCKET_REPO_NAME: repoName, | ||||||||||||||||||||||||||||||
| SOCKET_BRANCH_NAME: branchName, | ||||||||||||||||||||||||||||||
| SOCKET_CLI_VERSION: constants.ENV.INLINED_SOCKET_CLI_VERSION, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if (!coanaResult.ok) { | ||||||||||||||||||||||||||||||
| return coanaResult | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| logger.success('Reachability analysis completed successfully') | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Use the DOT_SOCKET_DOT_FACTS_JSON file for the scan | ||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||
| ok: true, | ||||||||||||||||||||||||||||||
| data: { | ||||||||||||||||||||||||||||||
| scanPaths: [constants.DOT_SOCKET_DOT_FACTS_JSON], | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.