Skip to content

Commit

Permalink
fix: resolve race conditions in async core.group calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ebickle committed Nov 19, 2024
1 parent 0a198ab commit fb86db2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 36 deletions.
40 changes: 20 additions & 20 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

36 changes: 21 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ async function run(): Promise<void> {
if (config.vulnerability_check) {
core.setOutput('vulnerable-changes', JSON.stringify(vulnerableChanges))
summary.addChangeVulnerabilitiesToSummary(vulnerableChanges, minSeverity)
issueFound ||= printVulnerabilitiesBlock(
issueFound ||= await printVulnerabilitiesBlock(
vulnerableChanges,
minSeverity,
warnOnly
Expand All @@ -158,12 +158,12 @@ async function run(): Promise<void> {
JSON.stringify(invalidLicenseChanges)
)
summary.addLicensesToSummary(invalidLicenseChanges, config)
issueFound ||= printLicensesBlock(invalidLicenseChanges, warnOnly)
issueFound ||= await printLicensesBlock(invalidLicenseChanges, warnOnly)
}
if (config.deny_packages || config.deny_groups) {
core.setOutput('denied-changes', JSON.stringify(deniedChanges))
summary.addDeniedToSummary(deniedChanges)
issueFound ||= printDeniedDependencies(deniedChanges, config)
issueFound ||= await printDeniedDependencies(deniedChanges, config)
}
if (config.show_openssf_scorecard) {
summary.addScorecardToSummary(scorecard, config)
Expand Down Expand Up @@ -214,9 +214,10 @@ function printVulnerabilitiesBlock(
addedChanges: Changes,
minSeverity: Severity,
warnOnly: boolean
): boolean {
let vulFound = false
core.group('Vulnerabilities', async () => {
): Promise<boolean> {
return core.group('Vulnerabilities', async () => {
let vulFound = false

for (const change of addedChanges) {
vulFound ||= printChangeVulnerabilities(change)
}
Expand All @@ -233,8 +234,9 @@ function printVulnerabilitiesBlock(
`Dependency review did not detect any vulnerable packages with severity level "${minSeverity}" or higher.`
)
}

return vulFound
})
return vulFound
}

function printChangeVulnerabilities(change: Change): boolean {
Expand All @@ -254,9 +256,10 @@ function printChangeVulnerabilities(change: Change): boolean {
function printLicensesBlock(
invalidLicenseChanges: Record<string, Changes>,
warnOnly: boolean
): boolean {
let issueFound = false
core.group('Licenses', async () => {
): Promise<boolean> {
return core.group('Licenses', async () => {
let issueFound = false

if (invalidLicenseChanges.forbidden.length > 0) {
issueFound = true
core.info('\nThe following dependencies have incompatible licenses:')
Expand All @@ -279,8 +282,9 @@ function printLicensesBlock(
)
}
printNullLicenses(invalidLicenseChanges.unlicensed)

return issueFound
})
return issueFound
}

function printLicensesError(changes: Changes): void {
Expand Down Expand Up @@ -382,9 +386,10 @@ function printScannedDependencies(changes: Changes): void {
function printDeniedDependencies(
changes: Changes,
config: ConfigurationOptions
): boolean {
let issueFound = false
core.group('Denied', async () => {
): Promise<boolean> {
return core.group('Denied', async () => {
let issueFound = false

for (const denied of config.deny_packages) {
core.info(`Config: ${denied}`)
}
Expand All @@ -400,8 +405,9 @@ function printDeniedDependencies(
} else {
core.info('Dependency review did not detect any denied packages')
}

return issueFound
})
return issueFound
}

function getScorecardChanges(changes: Changes): Changes {
Expand Down

0 comments on commit fb86db2

Please sign in to comment.