Skip to content

Commit

Permalink
feat: 🔇 params to mute warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
meisZWFLZ committed Dec 18, 2024
1 parent d5393ea commit dee5772
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 20 deletions.
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ inputs:
description: 'The commit message that will be used when updating the depot'
required: false

quiet:
description: 'When true, all warnings will be silenced. Errors should still be logged.'
required: false
default: false

ignore-non-template-assets:
description: 'When true, silences warnings regarding assets that do not contain a template.pros file.'
required: false
default: false
runs:
using: node20
main: dist/index.js
103 changes: 89 additions & 14 deletions dist/index.js

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

16 changes: 14 additions & 2 deletions src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,16 @@ function stringifyDepot(depot: Depot, readable: boolean): string {
* @param readable Whether to format the JSON string for human readability.
* @param unified Whether the beta and stable versions should be contained in a single depot.
* @param quietWarnings prevents warnings regarding {@link retrieveTemplateDetails.Error} from being logged
* @param ignoreNonTemplates Prevents warnings about non templates being found in assets
* @returns A map of depot JSON strings, with keys 'stable' and 'beta'. If unified is true, only 'stable' is present.
*/
export async function createDepotJsonsFromGithub({
repoId,
client = new Octokit(),
readable = true,
unified = false,
quietWarnings = false
quietWarnings = false,
ignoreNonTemplates = false
}: {
repoId: {
owner: string
Expand All @@ -164,6 +166,7 @@ export async function createDepotJsonsFromGithub({
readable?: boolean
unified?: boolean
quietWarnings?: boolean
ignoreNonTemplates?: boolean
}): Promise<DepotJsonMap> {
// get releases from github
const rawReleases = (await client.repos.listReleases(repoId)).data
Expand Down Expand Up @@ -192,7 +195,16 @@ export async function createDepotJsonsFromGithub({
(t): t is TemplateDetails => {
if ('error' in t) {
// log errors
if (quietWarnings !== true) console.warn(t) // TODO: implement logger
if (
!quietWarnings &&
((t.error !=

Check failure on line 200 in src/json.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected '!==' and instead saw '!='
'asset is a project, not a template (no template.pros file, but there is a project.pros file)' &&
t.error !=
'unknown asset type (no template.pros or project.pros file)') ||
!ignoreNonTemplates)
)
console.warn(t) // TODO: implement logger

return false
} else return true
}
Expand Down
9 changes: 8 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ export async function run(): Promise<void> {
const routes = getDepotLocations()

const readableFlag = core.getInput('readable-json') === 'true'
const quietWarningsFlag = core.getInput('quiet') === 'true'
const ignoreNonTemplateAssetsFlag =
core.getInput('ignore-non-template-assets') === 'true'
const ghToken = core.getInput('token')
let message: string | undefined = core.getInput('message') || undefined
updateDepots({
...repos,
routes,
readableJson: readableFlag,
token: ghToken,
message
message,
logConfig: {
quietWarnings: quietWarningsFlag,
ignoreNonTemplateAssets: ignoreNonTemplateAssetsFlag
}
})
} catch (error) {
// Fail the workflow run if an error occurs
Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ export type DepotRouteMap = Record<Extract<DepotType, 'stable'>, DepotRoute> &
export type DepotJsonMap = Record<'stable', string> &
Partial<Record<DepotType, string>>

/** Describes what should and shouldn't be logged */
export interface LogConfig {
/** Silences all warnings */
quietWarnings: boolean
/** Prevents logging of warnings for assets that are not templates */
ignoreNonTemplateAssets: boolean
}

export interface Inputs {
/** repo from which to parse releases */
srcRepo: RepositoryIdentifier
Expand All @@ -40,4 +48,5 @@ export interface Inputs {
routes: DepotRouteMap
readableJson: boolean
message?: string
logConfig: LogConfig
}
13 changes: 10 additions & 3 deletions src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,23 @@ export async function updateDepots({
token,
routes,
readableJson,
message: messageInput
message: messageInput,
logConfig: { ignoreNonTemplateAssets, quietWarnings }
}: Inputs) {
const client = new Octokit({ auth: token })

const unified =
routes.beta.branch === routes.stable.branch &&
routes.beta.path === routes.stable.path
// create depot jsons
const jsons = await createDepotJsonsFromGithub(
{ repoId: srcRepo, client, readable: readableJson, unified } )
const jsons = await createDepotJsonsFromGithub({
repoId: srcRepo,
client,
readable: readableJson,
unified,
quietWarnings: quietWarnings,
ignoreNonTemplates: ignoreNonTemplateAssets
})

// remove beta depot if it's route has an undefined part
const depots = filterDepots(destRepo, routes, jsons)
Expand Down

0 comments on commit dee5772

Please sign in to comment.