From b974ee5c493947114e05b132e719880e5b8a8b56 Mon Sep 17 00:00:00 2001 From: "James M. Greene" Date: Wed, 27 Mar 2024 22:35:54 -0500 Subject: [PATCH] Use error-utils to add error metadata to Actions workflow run annotations --- src/api-client.js | 21 +++++++++++++++------ src/set-pages-config.js | 9 +++++---- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/api-client.js b/src/api-client.js index 52ab59f..c85897c 100644 --- a/src/api-client.js +++ b/src/api-client.js @@ -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) @@ -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 } @@ -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 } } diff --git a/src/set-pages-config.js b/src/set-pages-config.js index f462cb0..1dfc9e2 100644 --- a/src/set-pages-config.js +++ b/src/set-pages-config.js @@ -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'] @@ -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) ) } }