Skip to content

Commit

Permalink
Relativize paths for annotations (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
fkorotkov authored May 15, 2024
1 parent 5970813 commit 6d6f82e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
31 changes: 16 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

31 changes: 13 additions & 18 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as core from '@actions/core'
import * as tc from '@actions/tool-cache'
import * as exec from '@actions/exec'
import path from 'path'
import * as process from 'node:process'

interface Entry {
file?: string
Expand Down Expand Up @@ -51,28 +52,14 @@ export async function run(): Promise<void> {
}

// Run the SwiftLint binary and capture its standard output
let stdout = ''

const swiftlintArgs = ['lint', '--reporter=json']
if (core.getInput('strict') === 'true') {
swiftlintArgs.push('--strict')
}
const returnCode = await exec.exec(
const output = await exec.getExecOutput(
path.join(portableSwiftlintDir, 'swiftlint'),
swiftlintArgs,
{
ignoreReturnCode: true,
listeners: {
stdout: (data: Buffer) => {
stdout += data.toString()
}
}
}
['lint', '--reporter=json']
)

// Parse the SwiftLint's JSON output
// and emit annotations
const result: Entry[] = JSON.parse(stdout)
const result: Entry[] = JSON.parse(output.stdout)

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

// relativize the file path to the working directory
if (entry.file) {
entry.file = path.relative(
process.env.GITHUB_WORKSPACE || process.cwd(),
entry.file
)
}

annotationFunc(entry.reason, {
title: `${entry.type} (${entry.rule_id})`,
file: entry.file,
Expand All @@ -98,7 +93,7 @@ export async function run(): Promise<void> {
})
}

process.exit(returnCode)
process.exit(output.exitCode)
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)
Expand Down

0 comments on commit 6d6f82e

Please sign in to comment.