Add configs
This commit is contained in:
@@ -39,6 +39,12 @@ function readInlineConfig(): ConfigurationOptionsPartial {
|
||||
const base_ref = getOptionalInput('base-ref')
|
||||
const head_ref = getOptionalInput('head-ref')
|
||||
const comment_summary_in_pr = getOptionalBoolean('comment-summary-in-pr')
|
||||
const retry_on_snapshot_warnings = getOptionalBoolean(
|
||||
'retry-on-snapshot-warnings'
|
||||
)
|
||||
const retry_on_snapshot_warnings_timeout = getOptionalNumber(
|
||||
'retry-on-snapshot-warnings'
|
||||
)
|
||||
|
||||
validatePURL(allow_dependencies_licenses)
|
||||
validateLicenses('allow-licenses', allow_licenses)
|
||||
@@ -55,7 +61,9 @@ function readInlineConfig(): ConfigurationOptionsPartial {
|
||||
vulnerability_check,
|
||||
base_ref,
|
||||
head_ref,
|
||||
comment_summary_in_pr
|
||||
comment_summary_in_pr,
|
||||
retry_on_snapshot_warnings,
|
||||
retry_on_snapshot_warnings_timeout
|
||||
}
|
||||
|
||||
return Object.fromEntries(
|
||||
@@ -63,6 +71,12 @@ function readInlineConfig(): ConfigurationOptionsPartial {
|
||||
)
|
||||
}
|
||||
|
||||
function getOptionalNumber(name: string): number | undefined {
|
||||
const value = core.getInput(name)
|
||||
const parsed = z.number().safeParse(value)
|
||||
return parsed.success ? parsed.data : undefined
|
||||
}
|
||||
|
||||
function getOptionalBoolean(name: string): boolean | undefined {
|
||||
const value = core.getInput(name)
|
||||
return value.length > 0 ? core.getBooleanInput(name) : undefined
|
||||
|
||||
31
src/main.ts
31
src/main.ts
@@ -24,8 +24,8 @@ async function delay(ms: number): Promise<void> {
|
||||
async function getComparison(
|
||||
baseRef: string,
|
||||
headRef: string,
|
||||
opts: {
|
||||
retries: number
|
||||
retryOpts?: {
|
||||
retryUntil: number
|
||||
retryDelay: number
|
||||
}
|
||||
): ReturnType<typeof dependencyGraph.compare> {
|
||||
@@ -35,11 +35,15 @@ async function getComparison(
|
||||
baseRef,
|
||||
headRef
|
||||
})
|
||||
if (comparison.snapshot_warnings.trim() !== '' && opts.retries > 0) {
|
||||
if (
|
||||
retryOpts !== undefined &&
|
||||
comparison.snapshot_warnings.trim() !== '' &&
|
||||
retryOpts.retryUntil < Date.now()
|
||||
) {
|
||||
core.info(comparison.snapshot_warnings)
|
||||
core.info('Retrying in 10 seconds...')
|
||||
await delay(opts.retryDelay)
|
||||
return getComparison(baseRef, headRef, {...opts, retries: opts.retries - 1})
|
||||
core.info(`Retrying in ${retryOpts.retryDelay} seconds...`)
|
||||
await delay(retryOpts.retryDelay * 1000)
|
||||
return getComparison(baseRef, headRef, retryOpts)
|
||||
}
|
||||
return comparison
|
||||
}
|
||||
@@ -50,10 +54,17 @@ async function run(): Promise<void> {
|
||||
|
||||
const refs = getRefs(config, github.context)
|
||||
|
||||
const comparison = await getComparison(refs.base, refs.head, {
|
||||
retries: 10,
|
||||
retryDelay: 10_000
|
||||
})
|
||||
const comparison = await getComparison(
|
||||
refs.base,
|
||||
refs.head,
|
||||
config.retry_on_snapshot_warnings
|
||||
? {
|
||||
retryUntil:
|
||||
Date.now() + config.retry_on_snapshot_warnings_timeout * 1000,
|
||||
retryDelay: 10
|
||||
}
|
||||
: undefined
|
||||
)
|
||||
|
||||
const changes = comparison.changes
|
||||
const snapshot_warnings = comparison.snapshot_warnings
|
||||
|
||||
@@ -47,7 +47,9 @@ export const ConfigurationOptionsSchema = z
|
||||
config_file: z.string().optional(),
|
||||
base_ref: z.string().optional(),
|
||||
head_ref: z.string().optional(),
|
||||
comment_summary_in_pr: z.boolean().default(false)
|
||||
comment_summary_in_pr: z.boolean().default(false),
|
||||
retry_on_snapshot_warnings: z.boolean().default(true),
|
||||
retry_on_snapshot_warnings_timeout: z.number().default(120)
|
||||
})
|
||||
.superRefine((config, context) => {
|
||||
if (config.allow_licenses && config.deny_licenses) {
|
||||
|
||||
Reference in New Issue
Block a user