Add configs

This commit is contained in:
Henri Maurer
2023-06-09 10:26:24 +01:00
parent 1644401f8d
commit 66b6f67835
8 changed files with 83 additions and 27 deletions
+3 -1
View File
@@ -24,7 +24,9 @@ const defaultConfig: ConfigurationOptions = {
allow_ghsas: [], allow_ghsas: [],
allow_licenses: [], allow_licenses: [],
deny_licenses: [], deny_licenses: [],
comment_summary_in_pr: true comment_summary_in_pr: true,
retry_on_snapshot_warnings: true,
retry_on_snapshot_warnings_timeout: 120
} }
const changesWithEmptyManifests: Changes = [ const changesWithEmptyManifests: Changes = [
+8
View File
@@ -47,6 +47,14 @@ inputs:
comment-summary-in-pr: comment-summary-in-pr:
description: A boolean to determine if the report should be posted as a comment in the PR itself. Setting this to true requires you to give the workflow the write permissions for pull-requests description: A boolean to determine if the report should be posted as a comment in the PR itself. Setting this to true requires you to give the workflow the write permissions for pull-requests
required: false required: false
retry-on-snapshot-warnings:
description: Whether to retry on snapshot warnings
required: false
default: true
retry-on-snapshot-warnings-timeout:
description: How many seconds before bailing on retries
required: false
default: 120
runs: runs:
using: 'node16' using: 'node16'
main: 'dist/index.js' main: 'dist/index.js'
Generated Vendored
+29 -12
View File
@@ -490,7 +490,7 @@ function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms)); return new Promise(resolve => setTimeout(resolve, ms));
}); });
} }
function getComparison(baseRef, headRef, opts) { function getComparison(baseRef, headRef, retryOpts) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const comparison = yield dependencyGraph.compare({ const comparison = yield dependencyGraph.compare({
owner: github.context.repo.owner, owner: github.context.repo.owner,
@@ -498,11 +498,13 @@ function getComparison(baseRef, headRef, opts) {
baseRef, baseRef,
headRef 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(comparison.snapshot_warnings);
core.info('Retrying in 10 seconds...'); core.info(`Retrying in ${retryOpts.retryDelay} seconds...`);
yield delay(opts.retryDelay); yield delay(retryOpts.retryDelay * 1000);
return getComparison(baseRef, headRef, Object.assign(Object.assign({}, opts), { retries: opts.retries - 1 })); return getComparison(baseRef, headRef, retryOpts);
} }
return comparison; return comparison;
}); });
@@ -512,10 +514,12 @@ function run() {
try { try {
const config = yield (0, config_1.readConfig)(); const config = yield (0, config_1.readConfig)();
const refs = (0, git_refs_1.getRefs)(config, github.context); const refs = (0, git_refs_1.getRefs)(config, github.context);
const comparison = yield getComparison(refs.base, refs.head, { const comparison = yield getComparison(refs.base, refs.head, config.retry_on_snapshot_warnings
retries: 10, ? {
retryDelay: 10000 retryUntil: Date.now() + config.retry_on_snapshot_warnings_timeout * 1000,
}); retryDelay: 10
}
: undefined);
const changes = comparison.changes; const changes = comparison.changes;
const snapshot_warnings = comparison.snapshot_warnings; const snapshot_warnings = comparison.snapshot_warnings;
if (!changes) { if (!changes) {
@@ -737,7 +741,9 @@ exports.ConfigurationOptionsSchema = z
config_file: z.string().optional(), config_file: z.string().optional(),
base_ref: z.string().optional(), base_ref: z.string().optional(),
head_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) => { .superRefine((config, context) => {
if (config.allow_licenses && config.deny_licenses) { if (config.allow_licenses && config.deny_licenses) {
@@ -46372,6 +46378,8 @@ function readInlineConfig() {
const base_ref = getOptionalInput('base-ref'); const base_ref = getOptionalInput('base-ref');
const head_ref = getOptionalInput('head-ref'); const head_ref = getOptionalInput('head-ref');
const comment_summary_in_pr = getOptionalBoolean('comment-summary-in-pr'); 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); validatePURL(allow_dependencies_licenses);
validateLicenses('allow-licenses', allow_licenses); validateLicenses('allow-licenses', allow_licenses);
validateLicenses('deny-licenses', deny_licenses); validateLicenses('deny-licenses', deny_licenses);
@@ -46386,10 +46394,17 @@ function readInlineConfig() {
vulnerability_check, vulnerability_check,
base_ref, base_ref,
head_ref, head_ref,
comment_summary_in_pr comment_summary_in_pr,
retry_on_snapshot_warnings,
retry_on_snapshot_warnings_timeout
}; };
return Object.fromEntries(Object.entries(keys).filter(([_, value]) => value !== undefined)); return Object.fromEntries(Object.entries(keys).filter(([_, value]) => value !== undefined));
} }
function getOptionalNumber(name) {
const value = core.getInput(name);
const parsed = z.number().safeParse(value);
return parsed.success ? parsed.data : undefined;
}
function getOptionalBoolean(name) { function getOptionalBoolean(name) {
const value = core.getInput(name); const value = core.getInput(name);
return value.length > 0 ? core.getBooleanInput(name) : undefined; return value.length > 0 ? core.getBooleanInput(name) : undefined;
@@ -46669,7 +46684,9 @@ exports.ConfigurationOptionsSchema = z
config_file: z.string().optional(), config_file: z.string().optional(),
base_ref: z.string().optional(), base_ref: z.string().optional(),
head_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) => { .superRefine((config, context) => {
if (config.allow_licenses && config.deny_licenses) { if (config.allow_licenses && config.deny_licenses) {
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -1
View File
@@ -28,7 +28,9 @@ const defaultConfig: ConfigurationOptions = {
'pkg:pip/certifi', 'pkg:pip/certifi',
'pkg:pip/[email protected]' 'pkg:pip/[email protected]'
], ],
comment_summary_in_pr: true comment_summary_in_pr: true,
retry_on_snapshot_warnings: true,
retry_on_snapshot_warnings_timeout: 120
} }
const tmpDir = path.resolve(__dirname, '../tmp') const tmpDir = path.resolve(__dirname, '../tmp')
+15 -1
View File
@@ -39,6 +39,12 @@ function readInlineConfig(): ConfigurationOptionsPartial {
const base_ref = getOptionalInput('base-ref') const base_ref = getOptionalInput('base-ref')
const head_ref = getOptionalInput('head-ref') const head_ref = getOptionalInput('head-ref')
const comment_summary_in_pr = getOptionalBoolean('comment-summary-in-pr') 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) validatePURL(allow_dependencies_licenses)
validateLicenses('allow-licenses', allow_licenses) validateLicenses('allow-licenses', allow_licenses)
@@ -55,7 +61,9 @@ function readInlineConfig(): ConfigurationOptionsPartial {
vulnerability_check, vulnerability_check,
base_ref, base_ref,
head_ref, head_ref,
comment_summary_in_pr comment_summary_in_pr,
retry_on_snapshot_warnings,
retry_on_snapshot_warnings_timeout
} }
return Object.fromEntries( 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 { function getOptionalBoolean(name: string): boolean | undefined {
const value = core.getInput(name) const value = core.getInput(name)
return value.length > 0 ? core.getBooleanInput(name) : undefined return value.length > 0 ? core.getBooleanInput(name) : undefined
+21 -10
View File
@@ -24,8 +24,8 @@ async function delay(ms: number): Promise<void> {
async function getComparison( async function getComparison(
baseRef: string, baseRef: string,
headRef: string, headRef: string,
opts: { retryOpts?: {
retries: number retryUntil: number
retryDelay: number retryDelay: number
} }
): ReturnType<typeof dependencyGraph.compare> { ): ReturnType<typeof dependencyGraph.compare> {
@@ -35,11 +35,15 @@ async function getComparison(
baseRef, baseRef,
headRef 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(comparison.snapshot_warnings)
core.info('Retrying in 10 seconds...') core.info(`Retrying in ${retryOpts.retryDelay} seconds...`)
await delay(opts.retryDelay) await delay(retryOpts.retryDelay * 1000)
return getComparison(baseRef, headRef, {...opts, retries: opts.retries - 1}) return getComparison(baseRef, headRef, retryOpts)
} }
return comparison return comparison
} }
@@ -50,10 +54,17 @@ async function run(): Promise<void> {
const refs = getRefs(config, github.context) const refs = getRefs(config, github.context)
const comparison = await getComparison(refs.base, refs.head, { const comparison = await getComparison(
retries: 10, refs.base,
retryDelay: 10_000 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 changes = comparison.changes
const snapshot_warnings = comparison.snapshot_warnings const snapshot_warnings = comparison.snapshot_warnings
+3 -1
View File
@@ -47,7 +47,9 @@ export const ConfigurationOptionsSchema = z
config_file: z.string().optional(), config_file: z.string().optional(),
base_ref: z.string().optional(), base_ref: z.string().optional(),
head_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) => { .superRefine((config, context) => {
if (config.allow_licenses && config.deny_licenses) { if (config.allow_licenses && config.deny_licenses) {