Skip to content

Commit

Permalink
Merge pull request #110 from github/brrygrdn/dont-handle-job-details-…
Browse files Browse the repository at this point in the history
…fails

Do not attempt to relay failures getting job details via api
  • Loading branch information
Barry Gordon authored and GitHub committed Oct 1, 2021
2 parents e216473 + b7793cb commit 7b7ff2c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 36 deletions.
17 changes: 6 additions & 11 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('run', () => {

expect(core.setFailed).not.toHaveBeenCalled()
expect(core.info).toHaveBeenCalledWith(
expect.stringContaining('🤖 ~fin~')
expect.stringContaining('🤖 ~ finished ~')
)
})

Expand Down Expand Up @@ -126,24 +126,19 @@ describe('run', () => {
context = new Context()
})

test('it fails the workflow', async () => {
test('it fails the workflow with the raw error', async () => {
await run(context)

expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining('error getting job details')
new Error('error getting job details')
)
})

test('it relays a failure message to the dependabot service', async () => {
test('it does not inform dependabot-api as the job may not be in a writeable state', async () => {
await run(context)

expect(reportJobErrorSpy).toHaveBeenCalledWith({
'error-type': 'actions_workflow_unknown',
'error-details': {
'action-error': 'error getting job details'
}
})
expect(markJobAsProcessedSpy).toHaveBeenCalled()
expect(markJobAsProcessedSpy).not.toHaveBeenCalled()
expect(reportJobErrorSpy).not.toHaveBeenCalled()
})
})

Expand Down
28 changes: 17 additions & 11 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

32 changes: 19 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,31 @@ export enum DependabotErrorType {

export async function run(context: Context): Promise<void> {
try {
core.info('🤖 ~start~')
// Decode JobParameters:
core.info('🤖 ~ starting update ~')
// Decode JobParameters
const params = getJobParameters(context)
if (params === null) {
return // No parameters, nothing to do
core.info('No job parameters')
core.info('🤖 ~ finished: nothing to do ~')
return
}

core.info('Starting updater')

core.debug(JSON.stringify(params))
core.debug(`Job parameters: ${JSON.stringify(params)}`)

core.setSecret(params.jobToken)
core.setSecret(params.credentialsToken)

const client = axios.create({baseURL: params.dependabotApiUrl})
const apiClient = new ApiClient(client, params)

try {
core.info('Fetching job details')
core.info('Fetching job details')

const details = await apiClient.getJobDetails()
// If we fail to succeed in fetching the job details, we cannot be sure the job has entered a 'processing' state,
// so we do not try attempt to report back an exception if this fails and instead rely on the the workflow run
// webhook as it anticipates scenarios where jobs have failed while 'enqueued'.
const details = await apiClient.getJobDetails()

try {
const credentials = await apiClient.getCredentials()
const updater = new Updater(
UPDATER_IMAGE_NAME,
Expand All @@ -51,12 +55,12 @@ export async function run(context: Context): Promise<void> {
)

try {
core.info('Pulling updater and proxy images')
core.info('Pulling updater images')

await ImageService.pull(UPDATER_IMAGE_NAME)
await ImageService.pull(PROXY_IMAGE_NAME)
} catch (error) {
core.error('Error fetching updater and proxy images')
core.error('Error fetching updater images')

await failJob(apiClient, error, DependabotErrorType.Image)
return
Expand All @@ -71,10 +75,10 @@ export async function run(context: Context): Promise<void> {
await failJob(apiClient, error, DependabotErrorType.UpdateRun)
return
}
core.info('🤖 ~fin~')
core.info('🤖 ~ finished ~')
} catch (error) {
// Update Dependabot API on the job failure
await failJob(apiClient, error)
return
}
} catch (error) {
// If we've reached this point, we do not have a viable
Expand All @@ -83,6 +87,7 @@ export async function run(context: Context): Promise<void> {
// We output the raw error in the Action logs and defer
// to workflow_run monitoring to detect the job failure.
core.setFailed(error)
core.info('🤖 ~ finished: unexpected error ~')
}
}

Expand All @@ -99,6 +104,7 @@ async function failJob(
})
await apiClient.markJobAsProcessed()
core.setFailed(error.message)
core.info('🤖 ~ finished: error reported to Dependabot ~')
}

run(github.context)

0 comments on commit 7b7ff2c

Please sign in to comment.