diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index b9ef95e..eec35ca 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -139,7 +139,9 @@ describe('run', () => { expect(reportJobErrorSpy).toHaveBeenCalledWith({ 'error-type': 'actions_workflow_unknown', - 'error-detail': 'error getting job details' + 'error-details': { + 'action-error': 'error getting job details' + } }) expect(markJobAsProcessedSpy).toHaveBeenCalled() }) @@ -173,7 +175,9 @@ describe('run', () => { expect(reportJobErrorSpy).toHaveBeenCalledWith({ 'error-type': 'actions_workflow_unknown', - 'error-detail': 'error getting credentials' + 'error-details': { + 'action-error': 'error getting credentials' + } }) expect(markJobAsProcessedSpy).toHaveBeenCalled() }) @@ -207,7 +211,9 @@ describe('run', () => { expect(reportJobErrorSpy).toHaveBeenCalledWith({ 'error-type': 'actions_workflow_image', - 'error-detail': 'error pulling an image' + 'error-details': { + 'action-error': 'error pulling an image' + } }) expect(markJobAsProcessedSpy).toHaveBeenCalled() }) @@ -241,7 +247,9 @@ describe('run', () => { expect(reportJobErrorSpy).toHaveBeenCalledWith({ 'error-type': 'actions_workflow_updater', - 'error-detail': 'error running the update' + 'error-details': { + 'action-error': 'error running the update' + } }) expect(markJobAsProcessedSpy).toHaveBeenCalled() }) diff --git a/src/api-client.ts b/src/api-client.ts index 5bdc056..fbd7878 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -22,7 +22,9 @@ export type JobDetails = { export type JobError = { 'error-type': string - 'error-detail': any + 'error-details': { + 'action-error': string + } } export type Credential = { @@ -39,6 +41,12 @@ export class ApiClient { readonly params: JobParameters ) {} + // We use a static unknown SHA when making a job as complete from the action + // to remain in parity with the existing runner. + UnknownSha = { + 'base-commit-sha': 'unknown' + } + async getJobDetails(): Promise { const detailsURL = `/update_jobs/${this.params.jobId}/details` const res = await this.client.get(detailsURL, { @@ -65,25 +73,29 @@ export class ApiClient { async reportJobError(error: JobError): Promise { const recordErrorURL = `/update_jobs/${this.params.jobId}/record_update_job_error` - const res = await this.client.post(recordErrorURL, error, { - headers: {Authorization: this.params.jobToken} - }) - if (res.status !== 200) { + const res = await this.client.post( + recordErrorURL, + {data: error}, + { + headers: {Authorization: this.params.jobToken} + } + ) + if (res.status !== 204) { throw new Error(`Unexpected status code: ${res.status}`) } - - return res.data.data.attributes } async markJobAsProcessed(): Promise { const markAsProcessedURL = `/update_jobs/${this.params.jobId}/mark_as_processed` - const res = await this.client.get(markAsProcessedURL, { - headers: {Authorization: this.params.jobToken} - }) - if (res.status !== 200) { + const res = await this.client.patch( + markAsProcessedURL, + {data: this.UnknownSha}, + { + headers: {Authorization: this.params.jobToken} + } + ) + if (res.status !== 204) { throw new Error(`Unexpected status code: ${res.status}`) } - - return res.data.data.attributes } } diff --git a/src/main.ts b/src/main.ts index 62e6693..f8d339a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -92,7 +92,9 @@ async function failJob( ): Promise { await apiClient.reportJobError({ 'error-type': errorType, - 'error-detail': error.message + 'error-details': { + 'action-error': error.message + } }) await apiClient.markJobAsProcessed() core.setFailed(error.message)