mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-08-14 12:45:09 +00:00
Merge 90a52e1c23eeb84fe7d387857edbcb14808071d5 into e8e5b8203e7388d709f9575a9f1c6c380e074a22
This commit is contained in:
commit
b6a6d9953a
19
.github/dotnet-format.json
vendored
Normal file
19
.github/dotnet-format.json
vendored
Normal file
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
import cscFile from '../.github/csc.json';
|
||||
describe('csc tests', () => {
|
||||
test('regular expression in csc.json is valid', async () => {
|
||||
const regexPattern = cscFile['problemMatcher'][0]['pattern'][0]['regexp'];
|
||||
const regexResultsMap = cscFile['problemMatcher'][0]['pattern'][0];
|
||||
|
||||
const regex = new RegExp(regexPattern);
|
||||
|
||||
const stringsToMatch = [
|
||||
'Program.cs(10,79): error CS1002: ; expected [/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]"
|
||||
];
|
||||
// Expected results are calculated according to the csc matcher located in csc.json file
|
||||
const expectedResults = [
|
||||
{
|
||||
file: 'Program.cs',
|
||||
line: '10',
|
||||
severity: 'error',
|
||||
code: 'CS1002',
|
||||
message: '; expected',
|
||||
fromPath:
|
||||
'/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj'
|
||||
},
|
||||
{
|
||||
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'
|
||||
}
|
||||
];
|
||||
|
||||
stringsToMatch.map((string, index) => {
|
||||
const matchedResultsArray = string.match(regex);
|
||||
for (const propName in expectedResults[index]) {
|
||||
const propertyIndex = regexResultsMap[propName];
|
||||
const expectedPropValue = expectedResults[index][propName];
|
||||
const matchedPropValue = matchedResultsArray![propertyIndex];
|
||||
expect(matchedPropValue).toEqual(expectedPropValue);
|
||||
}
|
||||
});
|
||||
}, 10000);
|
||||
});
|
70
__tests__/problem-matchers.json.test.ts
Normal file
70
__tests__/problem-matchers.json.test.ts
Normal file
@ -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]);
|
||||
}
|
||||
});
|
||||
});
|
@ -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 () => {
|
||||
|
10
dist/setup/index.js
vendored
10
dist/setup/index.js
vendored
@ -99719,6 +99719,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 {
|
||||
@ -99776,8 +99781,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);
|
||||
|
@ -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 {
|
||||
//
|
||||
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user