Skip to content

Commit

Permalink
Support for Workflow Summary (#143)
Browse files Browse the repository at this point in the history
* Write to workflow summary

* Write to workflow summary - only body

* Add choice type

* Print comment-type

* Run build

* Adding commentType validation

* Code cleanup

* Adapt tests

* Adding more tests

* Adding tests for validation

* Support for workflow summary (#89)

* Add summary_mode

* Token is not necessary for workflow summary

* Add summary_mode in action.ts

* Update description for comment-type field

---------

Co-authored-by: thsaravana <[email protected]>

---------

Co-authored-by: YiJhen Lin <[email protected]>
  • Loading branch information
thsaravana and yijhenlin authored Sep 18, 2024
1 parent 62da025 commit ad47d82
Show file tree
Hide file tree
Showing 19 changed files with 559 additions and 109 deletions.
100 changes: 67 additions & 33 deletions __tests__/action.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-nocheck
import * as action from '../src/action'
import * as core from '@actions/core'
import * as github from '@actions/github'
Expand All @@ -6,6 +8,19 @@ jest.mock('@actions/core')
jest.mock('@actions/github')

describe('Input validation', function () {
const eventName = 'pull_request'
const payload = {
pull_request: {
number: '45',
base: {
sha: 'guasft7asdtf78asfd87as6df7y2u3',
},
head: {
sha: 'aahsdflais76dfa78wrglghjkaghkj',
},
},
}

function getInput(key: string): string | undefined {
switch (key) {
case 'paths':
Expand All @@ -19,47 +34,44 @@ describe('Input validation', function () {
const listComments = jest.fn()
const updateComment = jest.fn()

/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore
core.getInput = jest.fn(getInput)
// @ts-ignore
github.getOctokit = jest.fn(() => {
return {
repos: {
compareCommits: jest.fn(() => {
return {
data: {
files: [
{
filename: 'src/main/kotlin/com/madrapps/jacoco/Math.kt',
blob_url:
'https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/kotlin/com/madrapps/jacoco/Math.kt',
},
{
filename:
'src/main/java/com/madrapps/jacoco/operation/StringOp.java',
blob_url:
'https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/java/com/madrapps/jacoco/operation/StringOp.java',
},
],
},
}
}),
},
issues: {
createComment,
listComments,
updateComment,
rest: {
repos: {
compareCommits: jest.fn(() => {
return {
data: {
files: [
{
filename: 'src/main/kotlin/com/madrapps/jacoco/Math.kt',
blob_url:
'https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/kotlin/com/madrapps/jacoco/Math.kt',
},
{
filename:
'src/main/java/com/madrapps/jacoco/operation/StringOp.java',
blob_url:
'https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/java/com/madrapps/jacoco/operation/StringOp.java',
},
],
},
}
}),
},
issues: {
createComment,
listComments,
updateComment,
},
},
}
})
// @ts-ignore
core.setFailed = jest.fn(c => {
fail(c)
})

it('Fail if paths is not present', async () => {
// @ts-ignore
core.getInput = jest.fn(c => {
switch (c) {
case 'paths':
Expand All @@ -70,15 +82,13 @@ describe('Input validation', function () {
})
github.context.eventName = 'pull_request'

// @ts-ignore
core.setFailed = jest.fn(c => {
expect(c).toEqual("'paths' is missing")
})
await action.action()
})

it('Fail if token is not present', async () => {
// @ts-ignore
core.getInput = jest.fn(c => {
switch (c) {
case 'token':
Expand All @@ -88,10 +98,34 @@ describe('Input validation', function () {
}
})
github.context.eventName = 'pull_request'
// @ts-ignore
core.setFailed = jest.fn(c => {
expect(c).toEqual("'token' is missing")
})
await action.action()
})

it('Fail if comment-type is invalid', async () => {
core.getInput = jest.fn(c => {
switch (c) {
case 'comment-type':
return 'invalid'
default:
return getInput(c)
}
})
core.setFailed = jest.fn(c => {
expect(c).toEqual("'comment-type' invalid is invalid")
})
initContext(eventName, payload)

await action.action()
})
})

function initContext(eventName, payload): void {
const context = github.context
context.eventName = eventName
context.payload = payload
context.repo = 'jacoco-playground'
context.owner = 'madrapps'
}
2 changes: 2 additions & 0 deletions __tests__/action_aggregate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ describe('Aggregate report', function () {
return './__tests__/__fixtures__/aggregate-report.xml'
case 'token':
return 'SMPLEHDjasdf876a987'
case 'comment-type':
return 'pr_comment'
case 'min-coverage-overall':
return 45
case 'min-coverage-changed-files':
Expand Down
2 changes: 2 additions & 0 deletions __tests__/action_empty_aggregate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ describe('Aggregate Empty report', function () {
return './__tests__/__fixtures__/empty-aggregate-report.xml'
case 'token':
return 'SMPLEHDjasdf876a987'
case 'comment-type':
return 'pr_comment'
case 'min-coverage-overall':
return 45
case 'min-coverage-changed-files':
Expand Down
2 changes: 2 additions & 0 deletions __tests__/action_empty_multiple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ describe('Multiple Empty reports', function () {
return './__tests__/__fixtures__/empty_multi_module/empty-appCoverage.xml,./__tests__/__fixtures__/multi_module/mathCoverage.xml,./__tests__/__fixtures__/empty_multi_module/empty-textCoverage.xml'
case 'token':
return 'SMPLEHDjasdf876a987'
case 'comment-type':
return 'pr_comment'
case 'min-coverage-overall':
return 45
case 'min-coverage-changed-files':
Expand Down
2 changes: 2 additions & 0 deletions __tests__/action_empty_report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ describe('Single Empty report', function () {
return './__tests__/__fixtures__/empty-report.xml'
case 'token':
return 'SMPLEHDjasdf876a987'
case 'comment-type':
return 'pr_comment'
case 'min-coverage-overall':
return 45
case 'min-coverage-changed-files':
Expand Down
2 changes: 2 additions & 0 deletions __tests__/action_multiple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ describe('Multiple reports', function () {
return './__tests__/__fixtures__/multi_module/appCoverage.xml,./__tests__/__fixtures__/multi_module/mathCoverage.xml,./__tests__/__fixtures__/multi_module/textCoverage.xml'
case 'token':
return 'SMPLEHDjasdf876a987'
case 'comment-type':
return 'pr_comment'
case 'min-coverage-overall':
return 45
case 'min-coverage-changed-files':
Expand Down
Loading

0 comments on commit ad47d82

Please sign in to comment.