forked from realm/SwiftLint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitHub Actions Logging reporter (
github-actions-logging
)
Use [GitHub Actions Logging](https://help.github.com/en/github/automating-your-workflow-with-github-actions/development-tools-for-github-actions#logging-commands) same as https://github.com/norio-nomura/action-swiftlint does.
- Loading branch information
1 parent
77bac34
commit 80d3813
Showing
7 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Source/SwiftLintFramework/Reporters/GitHubActionsLoggingReporter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
public struct GitHubActionsLoggingReporter: Reporter { | ||
public static let identifier = "github-actions-logging" | ||
public static let isRealtime = true | ||
|
||
public var description: String { | ||
return "Reports violations in the format GitHub-hosted virtual machine for Actions can recognize as messages." | ||
} | ||
|
||
public static func generateReport(_ violations: [StyleViolation]) -> String { | ||
return violations.map(generateForSingleViolation).joined(separator: "\n") | ||
} | ||
|
||
internal static func generateForSingleViolation(_ violation: StyleViolation) -> String { | ||
// swiftlint:disable:next line_length | ||
// https://help.github.com/en/github/automating-your-workflow-with-github-actions/development-tools-for-github-actions#logging-commands | ||
// ::(warning|error) file={relative_path_to_file},line={:line},col={:character}::{content} | ||
return [ | ||
"::\(violation.severity.rawValue) ", | ||
"file=\(violation.location.relativeFile ?? ""),", | ||
"line=\(violation.location.line ?? 1),", | ||
"col=\(violation.location.character ?? 1)::", | ||
violation.reason, | ||
" (\(violation.ruleDescription.identifier))" | ||
].joined() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
Tests/SwiftLintFrameworkTests/Resources/CannedGitHubActionsLoggingReporterOutput.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
::warning file=filename,line=1,col=2::Violation Reason. (line_length) | ||
::error file=filename,line=1,col=2::Violation Reason. (line_length) | ||
::error file=filename,line=1,col=2::Shorthand syntactic sugar should be used, i.e. [Int] instead of Array<Int>. (syntactic_sugar) | ||
::error file=,line=1,col=1::Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon) |