-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from github/brrygrdn/action-reports-failure-to…
…-api Add error reporting to Dependabot API
- Loading branch information
Showing
5 changed files
with
375 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "inputs": { | ||
| "jobID": "1", | ||
| "jobToken": "xxx", | ||
| "credentialsToken": "yyy", | ||
| "dependabotAPIURL": "http://localhost:9000" | ||
| }, | ||
| "ref": "main", | ||
| "repository": { | ||
| "owner": { | ||
| "login": "dependabot" | ||
| }, | ||
| "name": "dependabot-core" | ||
| }, | ||
| "sender": { | ||
| "type": "User" | ||
| }, | ||
| "installation": null, | ||
| "organization": null, | ||
| "workflow": "--workflow-yaml-goes-here--" | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,249 @@ | ||
| // shows how the runner will run a javascript action with env / stdout protocol | ||
| test('test runs', () => {}) | ||
| import * as core from '@actions/core' | ||
| import {Context} from '@actions/github/lib/context' | ||
| import {APIClient} from '../src/api-client' | ||
| import {Updater} from '../src/updater' | ||
| import {ImageService} from '../src/image-service' | ||
| import * as inputs from '../src/inputs' | ||
| import {run} from '../src/main' | ||
|
|
||
| import {eventFixturePath} from './helpers' | ||
|
|
||
| // We do not need to build actual containers or run updates for this test. | ||
| jest.mock('../src/api-client') | ||
| jest.mock('../src/image-service') | ||
| jest.mock('../src/updater') | ||
|
|
||
| describe('run', () => { | ||
| let context: Context | ||
|
|
||
| let markJobAsProcessedSpy: any | ||
| let reportJobErrorSpy: any | ||
|
|
||
| beforeEach(async () => { | ||
| markJobAsProcessedSpy = jest.spyOn( | ||
| APIClient.prototype, | ||
| 'markJobAsProcessed' | ||
| ) | ||
| reportJobErrorSpy = jest.spyOn(APIClient.prototype, 'reportJobError') | ||
|
|
||
| jest.spyOn(core, 'info').mockImplementation(jest.fn()) | ||
| jest.spyOn(core, 'setFailed').mockImplementation(jest.fn()) | ||
| }) | ||
|
|
||
| afterEach(async () => { | ||
| jest.clearAllMocks() // Reset any mocked classes | ||
| }) | ||
|
|
||
| describe('when the run follows the happy path', () => { | ||
| beforeAll(() => { | ||
| process.env.GITHUB_EVENT_PATH = eventFixturePath('default') | ||
| process.env.GITHUB_EVENT_NAME = 'workflow_dispatch' | ||
| context = new Context() | ||
| }) | ||
|
|
||
| test('it signs off at completion without any errors', async () => { | ||
| await run(context) | ||
|
|
||
| expect(core.setFailed).not.toHaveBeenCalled() | ||
| expect(core.info).toHaveBeenCalledWith( | ||
| expect.stringContaining('🤖 ~fin~') | ||
| ) | ||
| }) | ||
|
|
||
| test('it defers reporting back to dependabot-api to the updater itself', async () => { | ||
| await run(context) | ||
|
|
||
| expect(markJobAsProcessedSpy).not.toHaveBeenCalled() | ||
| expect(reportJobErrorSpy).not.toHaveBeenCalled() | ||
| }) | ||
| }) | ||
|
|
||
| describe('when the action is triggered on an unsupported event', () => { | ||
| beforeAll(() => { | ||
| process.env.GITHUB_EVENT_PATH = eventFixturePath('default') | ||
| process.env.GITHUB_EVENT_NAME = 'issue_created' | ||
| context = new Context() | ||
| }) | ||
|
|
||
| test('it fails the workflow', async () => { | ||
| await run(context) | ||
|
|
||
| expect(core.setFailed).not.toHaveBeenCalled() | ||
| expect(core.info).toHaveBeenCalledWith( | ||
| "Dependabot Updater Action does not support 'issue_created' events." | ||
| ) | ||
| }) | ||
|
|
||
| test('it does not report this failed run to dependabot-api', async () => { | ||
| await run(context) | ||
|
|
||
| expect(markJobAsProcessedSpy).not.toHaveBeenCalled() | ||
| expect(reportJobErrorSpy).not.toHaveBeenCalled() | ||
| }) | ||
| }) | ||
|
|
||
| describe('when there is an error retrieving job parameters', () => { | ||
| beforeEach(() => { | ||
| jest.spyOn(inputs, 'getJobParameters').mockImplementationOnce( | ||
| jest.fn(() => { | ||
| throw new Error('unexpected error retrieving job params') | ||
| }) | ||
| ) | ||
|
|
||
| process.env.GITHUB_EVENT_PATH = eventFixturePath('default') | ||
| process.env.GITHUB_EVENT_NAME = 'workflow_dispatch' | ||
| context = new Context() | ||
| }) | ||
|
|
||
| test('it fails the workflow with the raw error', async () => { | ||
| await run(context) | ||
|
|
||
| expect(core.setFailed).toHaveBeenCalledWith( | ||
| new Error('unexpected error retrieving job params') | ||
| ) | ||
| }) | ||
|
|
||
| test('it does not inform dependabot-api as it cannot instantiate a client without the params', async () => { | ||
| await run(context) | ||
|
|
||
| expect(markJobAsProcessedSpy).not.toHaveBeenCalled() | ||
| expect(reportJobErrorSpy).not.toHaveBeenCalled() | ||
| }) | ||
| }) | ||
|
|
||
| describe('when there is an error retrieving job details from DependabotAPI', () => { | ||
| beforeEach(() => { | ||
| jest | ||
| .spyOn(APIClient.prototype, 'getJobDetails') | ||
| .mockImplementationOnce( | ||
| jest.fn(async () => | ||
| Promise.reject(new Error('error getting job details')) | ||
| ) | ||
| ) | ||
|
|
||
| process.env.GITHUB_EVENT_PATH = eventFixturePath('default') | ||
| process.env.GITHUB_EVENT_NAME = 'workflow_dispatch' | ||
| context = new Context() | ||
| }) | ||
|
|
||
| test('it fails the workflow', async () => { | ||
| await run(context) | ||
|
|
||
| expect(core.setFailed).toHaveBeenCalledWith( | ||
| expect.stringContaining('error getting job details') | ||
| ) | ||
| }) | ||
|
|
||
| test('it relays a failure message to the dependabot service', async () => { | ||
| await run(context) | ||
|
|
||
| expect(reportJobErrorSpy).toHaveBeenCalledWith({ | ||
| 'error-type': 'actions_workflow_unknown', | ||
| 'error-detail': 'error getting job details' | ||
| }) | ||
| expect(markJobAsProcessedSpy).toHaveBeenCalled() | ||
| }) | ||
| }) | ||
|
|
||
| describe('when there is an error retrieving job credentials from DependabotAPI', () => { | ||
| beforeEach(() => { | ||
| jest | ||
| .spyOn(APIClient.prototype, 'getCredentials') | ||
| .mockImplementationOnce( | ||
| jest.fn(async () => | ||
| Promise.reject(new Error('error getting credentials')) | ||
| ) | ||
| ) | ||
|
|
||
| process.env.GITHUB_EVENT_PATH = eventFixturePath('default') | ||
| process.env.GITHUB_EVENT_NAME = 'workflow_dispatch' | ||
| context = new Context() | ||
| }) | ||
|
|
||
| test('it fails the workflow', async () => { | ||
| await run(context) | ||
|
|
||
| expect(core.setFailed).toHaveBeenCalledWith( | ||
| expect.stringContaining('error getting credentials') | ||
| ) | ||
| }) | ||
|
|
||
| test('it relays a failure message to the dependabot service', async () => { | ||
| await run(context) | ||
|
|
||
| expect(reportJobErrorSpy).toHaveBeenCalledWith({ | ||
| 'error-type': 'actions_workflow_unknown', | ||
| 'error-detail': 'error getting credentials' | ||
| }) | ||
| expect(markJobAsProcessedSpy).toHaveBeenCalled() | ||
| }) | ||
| }) | ||
|
|
||
| describe('when there is an error pulling images', () => { | ||
| beforeEach(() => { | ||
| jest | ||
| .spyOn(ImageService, 'pull') | ||
| .mockImplementationOnce( | ||
| jest.fn(async () => | ||
| Promise.reject(new Error('error pulling an image')) | ||
| ) | ||
| ) | ||
|
|
||
| process.env.GITHUB_EVENT_PATH = eventFixturePath('default') | ||
| process.env.GITHUB_EVENT_NAME = 'workflow_dispatch' | ||
| context = new Context() | ||
| }) | ||
|
|
||
| test('it fails the workflow', async () => { | ||
| await run(context) | ||
|
|
||
| expect(core.setFailed).toHaveBeenCalledWith( | ||
| expect.stringContaining('error pulling an image') | ||
| ) | ||
| }) | ||
|
|
||
| test('it relays a failure message to the dependabot service', async () => { | ||
| await run(context) | ||
|
|
||
| expect(reportJobErrorSpy).toHaveBeenCalledWith({ | ||
| 'error-type': 'actions_workflow_image', | ||
| 'error-detail': 'error pulling an image' | ||
| }) | ||
| expect(markJobAsProcessedSpy).toHaveBeenCalled() | ||
| }) | ||
| }) | ||
|
|
||
| describe('when there is an error running the update', () => { | ||
| beforeEach(() => { | ||
| jest | ||
| .spyOn(Updater.prototype, 'runUpdater') | ||
| .mockImplementationOnce( | ||
| jest.fn(async () => | ||
| Promise.reject(new Error('error running the update')) | ||
| ) | ||
| ) | ||
|
|
||
| process.env.GITHUB_EVENT_PATH = eventFixturePath('default') | ||
| process.env.GITHUB_EVENT_NAME = 'workflow_dispatch' | ||
| context = new Context() | ||
| }) | ||
|
|
||
| test('it fails the workflow', async () => { | ||
| await run(context) | ||
|
|
||
| expect(core.setFailed).toHaveBeenCalledWith( | ||
| expect.stringContaining('error running the update') | ||
| ) | ||
| }) | ||
|
|
||
| test('it relays a failure message to the dependabot service', async () => { | ||
| await run(context) | ||
|
|
||
| expect(reportJobErrorSpy).toHaveBeenCalledWith({ | ||
| 'error-type': 'actions_workflow_updater', | ||
| 'error-detail': 'error running the update' | ||
| }) | ||
| expect(markJobAsProcessedSpy).toHaveBeenCalled() | ||
| }) | ||
| }) | ||
| }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.