Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Problem Matcher for dotnet-format #583

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/dotnet-format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"problemMatcher": [
{
"owner": "dotnet-format",
"pattern": [
{
"regexp": "^\\s*(.*)\\((\\d+),(\\d+)\\):\\s+(error|warning)\\s+(.+):\\s+(.*)\\s+\\[(.+)\\]$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"code": 5,
"message": 6,
"fromPath": 7
}
]
}
]
}
45 changes: 0 additions & 45 deletions __tests__/csc.test.ts

This file was deleted.

70 changes: 70 additions & 0 deletions __tests__/problem-matchers.json.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import csc from '../.github/csc.json';
import dotnetFormat from '../.github/dotnet-format.json';

// Unit tests for problem matchers
// https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md

describe('/.github/csc.json tests', () => {
const problemMatcher = csc.problemMatcher[0].pattern[0];

it.each([
[
'Program.cs(10,79): error CS1002: ; expected [/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj]',
{
file: 'Program.cs',
line: '10',
severity: 'error',
code: 'CS1002',
message: '; expected',
fromPath:
'/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj'
}
],
[
"S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs(33,7): error CS1003: Syntax error, ',' expected [S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop]",
{
file: 'S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs',
line: '33',
severity: 'error',
code: 'CS1003',
message: "Syntax error, ',' expected",
fromPath:
'S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop'
}
]
])('log "%s" matches %o', (logOutput, expected) => {
const regexp = new RegExp(problemMatcher.regexp);
const res = logOutput.match(regexp);

for (const key in expected) {
expect(res?.[problemMatcher[key]]).toBe(expected[key]);
}
});
});

describe('/.github/dotnet-format.json tests', () => {
const problemMatcher = dotnetFormat.problemMatcher[0].pattern[0];

it.each([
[
"/home/runner/work/repo/Test.cs(18,6): error WHITESPACE: Fix whitespace formatting. Replace 12 characters with '\\n\\s\\s\\s\\s\\s\\s\\s\\s'. [/home/runner/work/repo/Test.csproj]",
{
file: '/home/runner/work/repo/Test.cs',
line: '18',
column: '6',
severity: 'error',
code: 'WHITESPACE',
message:
"Fix whitespace formatting. Replace 12 characters with '\\n\\s\\s\\s\\s\\s\\s\\s\\s'.",
fromPath: '/home/runner/work/repo/Test.csproj'
}
]
])('log "%s" matches %o', (logOutput, expected) => {
const regexp = new RegExp(problemMatcher.regexp);
const res = logOutput.match(regexp);

for (const key in expected) {
expect(res?.[problemMatcher[key]]).toBe(expected[key]);
}
});
});
6 changes: 6 additions & 0 deletions __tests__/setup-dotnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ describe('setup-dotnet tests', () => {
expect(debugSpy).toHaveBeenCalledWith(expectedDebugMessage);
expect(existsSyncSpy).toHaveBeenCalled();
expect(infoSpy).toHaveBeenCalledWith(expectedInfoMessage);
expect(infoSpy).toHaveBeenCalledWith(
expect.stringMatching(/^##\[add-matcher\](.+)csc\.json$/)
);
expect(infoSpy).toHaveBeenCalledWith(
expect.stringMatching(/^##\[add-matcher\](.+)dotnet-format\.json$/)
);
});

it('should fail the action if quality is supplied but its value is not supported', async () => {
Expand Down
10 changes: 8 additions & 2 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94047,6 +94047,11 @@ const qualityOptions = [
'preview',
'ga'
];
/**
* The problem matcher files to be registered with the runner.
* https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md
*/
const problemMatchers = ['csc.json', 'dotnet-format.json'];
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
Expand Down Expand Up @@ -94104,8 +94109,9 @@ function run() {
const cacheDependencyPath = core.getInput('cache-dependency-path');
yield (0, cache_restore_1.restoreCache)(cacheDependencyPath);
}
const matchersPath = path_1.default.join(__dirname, '..', '..', '.github');
core.info(`##[add-matcher]${path_1.default.join(matchersPath, 'csc.json')}`);
for (const file of problemMatchers) {
core.info(`##[add-matcher]${path_1.default.join(__dirname, '..', '..', '.github', file)}`);
}
}
catch (error) {
core.setFailed(error.message);
Expand Down
13 changes: 11 additions & 2 deletions src/setup-dotnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ const qualityOptions = [

export type QualityOptions = (typeof qualityOptions)[number];

/**
* The problem matcher files to be registered with the runner.
* https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md
*/
const problemMatchers = ['csc.json', 'dotnet-format.json'];

export async function run() {
try {
//
Expand Down Expand Up @@ -89,8 +95,11 @@ export async function run() {
await restoreCache(cacheDependencyPath);
}

const matchersPath = path.join(__dirname, '..', '..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'csc.json')}`);
for (const file of problemMatchers) {
core.info(
`##[add-matcher]${path.join(__dirname, '..', '..', '.github', file)}`
);
}
} catch (error) {
core.setFailed(error.message);
}
Expand Down
Loading