Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert errors into Actions-compatible logging with annotations #138

Merged
merged 6 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use error-utils to add error metadata to Actions workflow run annotat…
…ions
  • Loading branch information
JamesMGreene committed Mar 28, 2024
commit b974ee5c493947114e05b132e719880e5b8a8b56
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
Loading