Skip to content

Commit 6a0a9c0

Browse files
committed
Cleanup
1 parent b91d9fe commit 6a0a9c0

6 files changed

Lines changed: 42 additions & 44 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v3
2222

23-
- name: Set Node.js 21.x
23+
- name: Set Node.js 22.x
2424
uses: actions/setup-node@v3
2525
with:
26-
node-version: 21.x
26+
node-version: 22.x
2727

2828
- name: Install dependencies
2929
run: npm ci

__tests__/utils/github.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ test('build annotations', function () {
6565
message: 'This line is not covered by a test'
6666
}
6767
])
68+
69+
const consoleMock = jest.spyOn(console, 'log').mockImplementation()
70+
71+
githubUtil.annotate(annotations)
72+
expect(console.log).toHaveBeenCalledTimes(4)
73+
expect(console.log).toHaveBeenCalledWith(
74+
'::warning file=file1.txt,line=132,endLine=132::This line is not covered by a test'
75+
)
76+
expect(console.log).toHaveBeenCalledWith(
77+
'::warning file=file1.txt,line=134,endLine=136::These lines are not covered by a test'
78+
)
79+
expect(console.log).toHaveBeenCalledWith(
80+
'::warning file=file1.txt,line=1007,endLine=1007::This line is not covered by a test'
81+
)
82+
expect(console.log).toHaveBeenCalledWith(
83+
'::warning file=test/dir/file1.txt,line=22,endLine=22::This line is not covered by a test'
84+
)
85+
86+
consoleMock.mockRestore()
6887
})
6988

7089
// @todo test for rest of github class

dist/index.js

Lines changed: 10 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/action.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {env} from 'node:process'
22
import * as core from '@actions/core'
33
import * as github from '@actions/github'
4-
import {filterCoverageByFile} from './utils/general'
4+
import {CoverageParsed, filterCoverageByFile} from './utils/general'
55
import {parseLCov} from './utils/lcov'
66
import {parseClover} from './utils/clover'
77
import {parseGoCoverage} from './utils/gocoverage'
@@ -46,15 +46,16 @@ export async function play(): Promise<void> {
4646
const workspacePath = env.GITHUB_WORKSPACE || ''
4747
core.info(`Workspace: ${workspacePath}`)
4848

49+
let parsedCov: CoverageParsed
4950
// 1. Parse coverage file
5051
if (COVERAGE_FORMAT === 'clover') {
51-
var parsedCov = await parseClover(COVERAGE_FILE_PATH, workspacePath)
52+
parsedCov = await parseClover(COVERAGE_FILE_PATH, workspacePath)
5253
} else if (COVERAGE_FORMAT === 'go') {
5354
// Assuming that go.mod is available in working directory
54-
var parsedCov = await parseGoCoverage(COVERAGE_FILE_PATH, 'go.mod')
55+
parsedCov = await parseGoCoverage(COVERAGE_FILE_PATH, 'go.mod')
5556
} else {
5657
// lcov default
57-
var parsedCov = await parseLCov(COVERAGE_FILE_PATH, workspacePath)
58+
parsedCov = await parseLCov(COVERAGE_FILE_PATH, workspacePath)
5859
}
5960
// Sum up lines.found for each entry in parsedCov
6061
const totalLines = parsedCov.reduce(
@@ -91,10 +92,7 @@ export async function play(): Promise<void> {
9192
)
9293

9394
// 4. Annotate in github
94-
await githubUtil.annotate({
95-
referenceCommitHash: githubUtil.getPullRequestRef(),
96-
annotations
97-
})
95+
githubUtil.annotate(annotations)
9896
core.info('Annotation done')
9997
} catch (error) {
10098
if (error instanceof Error) core.setFailed(error.message)

src/utils/github.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,14 @@ export class GithubUtil {
4646
}
4747

4848
/**
49-
* https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#create-a-check-run
50-
* https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#update-a-check-run
49+
* https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-a-warning-message
5150
*/
52-
async annotate(input: InputAnnotateParams): Promise<number> {
53-
if (input.annotations.length === 0) {
54-
return 0
55-
}
56-
for (const ann of input.annotations) {
51+
annotate(annotations: Annotations[]): void {
52+
for (const ann of annotations) {
5753
console.log(
58-
`::warning file=${ann.path},line=${ann.start_line},endLine=${ann.end_line}::${ann.message}`
54+
`::${ann.annotation_level} file=${ann.path},line=${ann.start_line},endLine=${ann.end_line}::${ann.message}`
5955
)
6056
}
61-
return 0
6257
}
6358

6459
buildAnnotations(
@@ -97,11 +92,6 @@ export class GithubUtil {
9792
}
9893
}
9994

100-
type InputAnnotateParams = {
101-
referenceCommitHash: string
102-
annotations: Annotations[]
103-
}
104-
10595
type Annotations = {
10696
path: string
10797
start_line: number

0 commit comments

Comments
 (0)