Skip to content

Commit

Permalink
Use error-utils to add error metadata to Actions workflow run annotat…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
JamesMGreene committed Mar 28, 2024
1 parent 1c5932f commit b974ee5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
21 changes: 15 additions & 6 deletions src/api-client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const core = require('@actions/core')
const github = require('@actions/github')
const { convertErrorToAnnotationProperties } = require('./error-utils')

async function enablePagesSite({ githubToken }) {
const octokit = github.getOctokit(githubToken)
Expand Down Expand Up @@ -43,20 +44,25 @@ async function findOrCreatePagesSite({ githubToken, enablement = true }) {
} catch (error) {
if (!enablement) {
core.error(
'Get Pages site failed. Please verify that the repository has Pages enabled and configured to build using GitHub Actions, or consider exploring the `enablement` parameter for this action.',
error
`Get Pages site failed. Please verify that the repository has Pages enabled and configured to build using GitHub Actions, or consider exploring the \`enablement\` parameter for this action. Error: ${error.message}`,
convertErrorToAnnotationProperties(error)
)
throw error
}
core.warning('Get Pages site failed', error)
}
core.warning(
`Get Pages site failed. Error: ${error.message}`,
convertErrorToAnnotationProperties(error)
)

if (!pageObject && enablement) {
// Create a new Pages site if one doesn't exist
try {
pageObject = await enablePagesSite({ githubToken })
} catch (error) {
core.error('Create Pages site failed', error)
core.error(
`Create Pages site failed. Error: ${error.message}`,
convertErrorToAnnotationProperties(error)
)
throw error
}

Expand All @@ -66,7 +72,10 @@ async function findOrCreatePagesSite({ githubToken, enablement = true }) {
try {
pageObject = await getPagesSite({ githubToken })
} catch (error) {
core.error('Get Pages site still failed', error)
core.error(
`Get Pages site still failed. Error: ${error.message}`,
convertErrorToAnnotationProperties(error)
)
throw error
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/set-pages-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const core = require('@actions/core')
const { ConfigParser } = require('./config-parser')
const removeTrailingSlash = require('./remove-trailing-slash')
const { convertErrorToAnnotationProperties } = require('./error-utils')

const SUPPORTED_FILE_EXTENSIONS = ['.js', '.cjs', '.mjs']

Expand Down Expand Up @@ -88,13 +89,13 @@ function setPagesConfig({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
core.warning(
`Unsupported configuration file extension. Currently supported extensions: ${SUPPORTED_FILE_EXTENSIONS.map(
ext => JSON.stringify(ext)
).join(', ')}`,
error
).join(', ')}. Error: ${error.message}`,
convertErrorToAnnotationProperties(error)
)
} else {
core.warning(
`We were unable to determine how to inject the site metadata into your config. Generated URLs may be incorrect. The base URL for this site should be ${siteUrl}. Please ensure your framework is configured to generate relative links appropriately.`,
error
`We were unable to determine how to inject the site metadata into your config. Generated URLs may be incorrect. The base URL for this site should be ${siteUrl}. Please ensure your framework is configured to generate relative links appropriately. Error: ${error.message}`,
convertErrorToAnnotationProperties(error)
)
}
}
Expand Down

0 comments on commit b974ee5

Please sign in to comment.