Skip to content

Commit 28eb63b

Browse files
committed
Relativize paths for annotations
1 parent 5970813 commit 28eb63b

File tree

3 files changed

+30
-34
lines changed

3 files changed

+30
-34
lines changed

dist/index.js

Lines changed: 16 additions & 15 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/main.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as core from '@actions/core'
22
import * as tc from '@actions/tool-cache'
33
import * as exec from '@actions/exec'
44
import path from 'path'
5+
import * as process from 'node:process'
56

67
interface Entry {
78
file?: string
@@ -51,28 +52,14 @@ export async function run(): Promise<void> {
5152
}
5253

5354
// Run the SwiftLint binary and capture its standard output
54-
let stdout = ''
55-
56-
const swiftlintArgs = ['lint', '--reporter=json']
57-
if (core.getInput('strict') === 'true') {
58-
swiftlintArgs.push('--strict')
59-
}
60-
const returnCode = await exec.exec(
55+
const output = await exec.getExecOutput(
6156
path.join(portableSwiftlintDir, 'swiftlint'),
62-
swiftlintArgs,
63-
{
64-
ignoreReturnCode: true,
65-
listeners: {
66-
stdout: (data: Buffer) => {
67-
stdout += data.toString()
68-
}
69-
}
70-
}
57+
['lint', '--reporter=json']
7158
)
7259

7360
// Parse the SwiftLint's JSON output
7461
// and emit annotations
75-
const result: Entry[] = JSON.parse(stdout)
62+
const result: Entry[] = JSON.parse(output.stdout)
7663

7764
for (const entry of result) {
7865
let annotationFunc: (
@@ -90,6 +77,14 @@ export async function run(): Promise<void> {
9077
break
9178
}
9279

80+
// relativize the file path to the working directory
81+
if (entry.file) {
82+
entry.file = path.relative(
83+
process.env.GITHUB_WORKSPACE || process.cwd(),
84+
entry.file
85+
)
86+
}
87+
9388
annotationFunc(entry.reason, {
9489
title: `${entry.type} (${entry.rule_id})`,
9590
file: entry.file,
@@ -98,7 +93,7 @@ export async function run(): Promise<void> {
9893
})
9994
}
10095

101-
process.exit(returnCode)
96+
process.exit(output.exitCode)
10297
} catch (error) {
10398
// Fail the workflow run if an error occurs
10499
if (error instanceof Error) core.setFailed(error.message)

0 commit comments

Comments
 (0)