@@ -2,6 +2,7 @@ import * as core from '@actions/core'
2
2
import * as tc from '@actions/tool-cache'
3
3
import * as exec from '@actions/exec'
4
4
import path from 'path'
5
+ import * as process from 'node:process'
5
6
6
7
interface Entry {
7
8
file ?: string
@@ -51,28 +52,14 @@ export async function run(): Promise<void> {
51
52
}
52
53
53
54
// 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 (
61
56
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' ]
71
58
)
72
59
73
60
// Parse the SwiftLint's JSON output
74
61
// and emit annotations
75
- const result : Entry [ ] = JSON . parse ( stdout )
62
+ const result : Entry [ ] = JSON . parse ( output . stdout )
76
63
77
64
for ( const entry of result ) {
78
65
let annotationFunc : (
@@ -90,6 +77,14 @@ export async function run(): Promise<void> {
90
77
break
91
78
}
92
79
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
+
93
88
annotationFunc ( entry . reason , {
94
89
title : `${ entry . type } (${ entry . rule_id } )` ,
95
90
file : entry . file ,
@@ -98,7 +93,7 @@ export async function run(): Promise<void> {
98
93
} )
99
94
}
100
95
101
- process . exit ( returnCode )
96
+ process . exit ( output . exitCode )
102
97
} catch ( error ) {
103
98
// Fail the workflow run if an error occurs
104
99
if ( error instanceof Error ) core . setFailed ( error . message )
0 commit comments