Skip to content

Commit f23a674

Browse files
authored
Add workflow (#1112)
1 parent 99d437b commit f23a674

File tree

168 files changed

+1331
-1624
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+1331
-1624
lines changed

.editorconfig

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ dotnet_diagnostic.RCS0039.severity = suggestion
7070
dotnet_diagnostic.RCS0041.severity = suggestion
7171
dotnet_diagnostic.RCS0042.severity = suggestion
7272
dotnet_diagnostic.RCS0043.severity = suggestion
73-
dotnet_diagnostic.RCS0044.severity = suggestion
7473
dotnet_diagnostic.RCS0046.severity = suggestion
7574
dotnet_diagnostic.RCS0048.severity = silent
7675
dotnet_diagnostic.RCS0049.severity = suggestion

.github/workflows/build.yml

+279
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
tags:
6+
- v*
7+
- cli-v*
8+
pull_request:
9+
10+
env:
11+
Configuration: Release
12+
TreatWarningsAsErrors: true
13+
WarningsNotAsErrors: 1591,NU5128
14+
Deterministic: true
15+
RunCodeAnalysis: false
16+
17+
jobs:
18+
pre_build:
19+
runs-on: ubuntu-20.04
20+
outputs:
21+
version: ${{ steps.version.outputs.version }}
22+
version3: ${{ steps.version.outputs.version3 }}
23+
cliVersion: ${{ steps.cliVersion.outputs.version }}
24+
defaults:
25+
run:
26+
working-directory: src
27+
steps:
28+
- uses: actions/checkout@v3
29+
with:
30+
fetch-depth: 0
31+
- run: dotnet tool install -g GitVersion.Tool --version 5.12.0
32+
- name: Resolve version
33+
id: version
34+
run: |
35+
dotnet-gitversion > version.json
36+
version="$(jq -r '.SemVer' version.json)"
37+
version3="$(jq -r '.MajorMinorPatch' version.json)"
38+
pr_version="$(jq -r '.MajorMinorPatch' version.json)-$(jq -r '.PreReleaseLabel' version.json).${{ github.run_number }}.${{ github.run_attempt }}"
39+
if [ "${{ github.event_name }}" = "pull_request" ]; then version=$pr_version; fi
40+
echo "Resolved version: $version"
41+
echo "version=${version}" >> $GITHUB_OUTPUT
42+
echo "Resolved version3: $version3"
43+
echo "version3=${version3}" >> $GITHUB_OUTPUT
44+
- name: Resolve CLI version
45+
id: cliVersion
46+
run: |
47+
dotnet-gitversion /overrideconfig tag-prefix=cli-v > version.json
48+
version="$(jq -r '.SemVer' version.json)"
49+
pr_version="$(jq -r '.MajorMinorPatch' version.json)-$(jq -r '.PreReleaseLabel' version.json).${{ github.run_number }}.${{ github.run_attempt }}"
50+
if [ "${{ github.event_name }}" = "pull_request" ]; then version=$pr_version; fi
51+
echo "Resolved CLI version: $version"
52+
echo "version=${version}" >> $GITHUB_OUTPUT
53+
- run: dotnet restore Roslynator.sln
54+
- run: dotnet build Roslynator.sln --no-restore
55+
- run: |
56+
dotnet format Roslynator.sln --no-restore --verify-no-changes --severity info --exclude-diagnostics \
57+
IDE0220 `# 'foreach' statement implicitly converts type. Add an explicit cast to make intent clearer.` \
58+
IDE0251 `# Property can be made read-only.` \
59+
IDE0270 `# Null check can be simplified.`
60+
- run: dotnet test Roslynator.sln --no-build
61+
62+
build_core_and_testing:
63+
if: github.ref_type != 'tag' || startsWith(github.ref_name, 'v')
64+
needs: pre_build
65+
runs-on: ubuntu-20.04
66+
env:
67+
Version: ${{ needs.pre_build.outputs.version }}
68+
defaults:
69+
run:
70+
working-directory: src
71+
steps:
72+
- uses: actions/checkout@v3
73+
- run: dotnet restore Roslynator.CoreAndTesting.slnf
74+
- run: dotnet build Roslynator.CoreAndTesting.slnf --no-restore
75+
- run: dotnet pack Roslynator.CoreAndTesting.slnf --no-build -o _nupkg
76+
- uses: actions/upload-artifact@v3
77+
with:
78+
name: nuget_packages
79+
path: src/_nupkg/*nupkg
80+
81+
build_analyzers:
82+
if: github.ref_type != 'tag' || startsWith(github.ref_name, 'v')
83+
needs: pre_build
84+
runs-on: ubuntu-20.04
85+
env:
86+
Version: ${{ needs.pre_build.outputs.version }}
87+
strategy:
88+
matrix:
89+
component:
90+
- name: Analyzers
91+
propertyName: Analyzers
92+
- name: Formatting.Analyzers
93+
propertyName: FormattingAnalyzers
94+
- name: CodeAnalysis.Analyzers
95+
propertyName: CodeAnalysisAnalyzers
96+
defaults:
97+
run:
98+
working-directory: src/${{ matrix.component.name }}.CodeFixes
99+
steps:
100+
- uses: actions/checkout@v3
101+
- run: dotnet restore
102+
- run: dotnet build --no-restore /p:Roslynator${{ matrix.component.propertyName }}NuGet=true
103+
- run: dotnet pack --no-build
104+
- uses: actions/upload-artifact@v3
105+
with:
106+
name: nuget_packages
107+
path: src/${{ matrix.component.name }}.CodeFixes/bin/Release/*.nupkg
108+
109+
build_vs_extension:
110+
if: github.ref_type != 'tag' || startsWith(github.ref_name, 'v')
111+
needs: pre_build
112+
runs-on: windows-latest
113+
env:
114+
Version: ${{ needs.pre_build.outputs.version }}
115+
DeployExtension: false
116+
defaults:
117+
run:
118+
working-directory: src/VisualStudio
119+
steps:
120+
- uses: actions/checkout@v3
121+
- run: (Get-Content source.extension.vsixmanifest) -replace 'Version="1.0.0"', 'Version="${{ needs.pre_build.outputs.version3 }}"' | Set-Content source.extension.vsixmanifest
122+
- run: dotnet restore
123+
- uses: microsoft/[email protected]
124+
- run: msbuild
125+
- uses: actions/upload-artifact@v3
126+
with:
127+
name: vs_extension
128+
path: src/VisualStudio/bin/Release/net472/*.vsix
129+
- uses: actions/upload-artifact@v3
130+
with:
131+
name: vs_extension
132+
path: src/VisualStudio/manifest.json
133+
134+
build_vs_code_extension:
135+
if: github.ref_type != 'tag' || startsWith(github.ref_name, 'v')
136+
needs: [ pre_build, build_analyzers ]
137+
runs-on: ubuntu-20.04
138+
env:
139+
Version: ${{ needs.pre_build.outputs.version }}
140+
defaults:
141+
run:
142+
working-directory: src/VisualStudioCode
143+
steps:
144+
- uses: actions/checkout@v3
145+
- run: dotnet restore
146+
- run: dotnet build --no-restore /p:DefineConstants=VSCODE
147+
- run: |
148+
mkdir package/roslyn/analyzers
149+
mkdir package/roslyn/refactorings
150+
mkdir package/roslyn/fixes
151+
cp bin/Release/netstandard2.0/Roslynator.Core.dll package/roslyn/common
152+
cp bin/Release/netstandard2.0/Roslynator.Common.dll package/roslyn/common
153+
cp bin/Release/netstandard2.0/Roslynator.CSharp.dll package/roslyn/common
154+
cp bin/Release/netstandard2.0/Roslynator.Workspaces.Core.dll package/roslyn/common
155+
cp bin/Release/netstandard2.0/Roslynator.Workspaces.Common.dll package/roslyn/common
156+
cp bin/Release/netstandard2.0/Roslynator.CSharp.Workspaces.dll package/roslyn/common
157+
cp bin/Release/netstandard2.0/Roslynator.CSharp.Analyzers.dll package/roslyn/analyzers
158+
cp bin/Release/netstandard2.0/Roslynator.CSharp.Analyzers.CodeFixes.dll package/roslyn/analyzers
159+
cp bin/Release/netstandard2.0/Roslynator.Formatting.Analyzers.dll package/roslyn/analyzers
160+
cp bin/Release/netstandard2.0/Roslynator.Formatting.Analyzers.CodeFixes.dll package/roslyn/analyzers
161+
cp bin/Release/netstandard2.0/Roslynator.CSharp.Refactorings.dll package/roslyn/refactorings
162+
cp bin/Release/netstandard2.0/Roslynator.CSharp.CodeFixes.dll package/roslyn/fixes
163+
name: Copy DLLs to package
164+
- run: >
165+
sed -i 's/"version": "1.0.0"/"version": "${{ needs.pre_build.outputs.version3 }}"/' package/package.json
166+
- run: npm install
167+
working-directory: src/VisualStudioCode/package
168+
- run: npm install -g @vscode/vsce
169+
- run: vsce package
170+
working-directory: src/VisualStudioCode/package
171+
- uses: actions/upload-artifact@v3
172+
with:
173+
name: vs_code_extension
174+
path: src/VisualStudioCode/package/*.vsix
175+
- run: rm package/*.vsix
176+
- run: sed -i s/ms-dotnettools.csharp/muhammad-sammy.csharp/ package/package.json
177+
- run: vsce package
178+
working-directory: src/VisualStudioCode/package
179+
- uses: actions/upload-artifact@v3
180+
with:
181+
name: ovsx_extension
182+
path: src/VisualStudioCode/package/*.vsix
183+
184+
build_core_cli:
185+
if: github.ref_type != 'tag' || startsWith(github.ref_name, 'cli-v')
186+
needs: pre_build
187+
runs-on: ubuntu-20.04
188+
env:
189+
RoslynatorDotNetCli: true
190+
RoslynatorCliVersion: ${{ needs.pre_build.outputs.cliVersion }}
191+
Version: ${{ needs.pre_build.outputs.version }}
192+
defaults:
193+
run:
194+
working-directory: src/CommandLine
195+
steps:
196+
- uses: actions/checkout@v3
197+
- run: dotnet restore
198+
- run: dotnet build --no-restore
199+
- run: dotnet pack --no-build
200+
- uses: actions/upload-artifact@v3
201+
with:
202+
name: nuget_packages
203+
path: src/CommandLine/bin/Release/*.nupkg
204+
205+
build_framework_cli:
206+
if: github.ref_type != 'tag' || startsWith(github.ref_name, 'cli-v')
207+
needs: pre_build
208+
runs-on: windows-latest
209+
env:
210+
RoslynatorCommandLine: true
211+
RoslynatorCliVersion: ${{ needs.pre_build.outputs.cliVersion }}
212+
Version: ${{ needs.pre_build.outputs.version }}
213+
defaults:
214+
run:
215+
working-directory: src/CommandLine
216+
steps:
217+
- uses: actions/checkout@v3
218+
- run: dotnet restore
219+
- run: dotnet build --no-restore
220+
- run: dotnet publish --no-build
221+
- run: dotnet pack --no-build
222+
- uses: actions/upload-artifact@v3
223+
with:
224+
name: nuget_packages
225+
path: src/CommandLine/bin/Release/*.nupkg
226+
227+
publish_nuget_packages:
228+
needs: [ build_core_and_testing, build_analyzers, build_core_cli, build_framework_cli ]
229+
runs-on: ubuntu-20.04
230+
if: github.ref_type == 'tag'
231+
steps:
232+
- uses: actions/download-artifact@v3
233+
with:
234+
name: nuget_packages
235+
path: nuget_packages
236+
- run: dotnet nuget push "*.nupkg" -k ${{ secrets.NUGET_API_KEY }} -s "https://api.nuget.org/v3/index.json"
237+
working-directory: nuget_packages
238+
239+
publish_vs_code_extension:
240+
needs: build_vs_code_extension
241+
runs-on: ubuntu-20.04
242+
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
243+
steps:
244+
- uses: actions/download-artifact@v3
245+
with:
246+
name: vs_code_extension
247+
path: vs_code_extension
248+
- run: npm install -g @vscode/vsce
249+
- run: vsce publish -p ${{ secrets.VS_MARKETPLACE_TOKEN }}
250+
working-directory: vs_code_extension
251+
252+
publish_ovsx_extension:
253+
needs: build_vs_code_extension
254+
runs-on: ubuntu-20.04
255+
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
256+
steps:
257+
- uses: actions/download-artifact@v3
258+
with:
259+
name: ovsx_extension
260+
path: ovsx_extension
261+
- run: npm install -g ovsx
262+
- run: ovsx publish -p ${{ secrets.OPEN_VSX_TOKEN }}
263+
working-directory: ovsx_extension
264+
265+
publish_vs_extension:
266+
needs: build_vs_extension
267+
runs-on: windows-latest
268+
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
269+
steps:
270+
- uses: actions/download-artifact@v3
271+
with:
272+
name: vs_extension
273+
path: vs_extension
274+
- run: |
275+
$visualStudioPath = vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VSSDK -property installationPath
276+
$vsixPublisher = Join-Path "$visualStudioPath" "VSSDK\VisualStudioIntegration\Tools\Bin\VsixPublisher.exe"
277+
& "$vsixPublisher" publish -payload Roslynator.VisualStudio.vsix -publishManifest manifest.json -personalAccessToken ${{ secrets.VS_MARKETPLACE_TOKEN }}
278+
working-directory: vs_extension
279+
name: Publish VS extension to Marketplace

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"dotnet.defaultSolution": "src/Roslynator.sln"
3+
}

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ Guidelines for contributing to the Roslynator repo.
2525
## Coding Style
2626

2727
* **DO** follow [.NET Runtime Coding Style](https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/coding-style.md) (except using `s_` and `t_` prefix for field names).
28-
* **DO** install [Roslynator for Visual Studio](https://marketplace.visualstudio.com/items?itemName=josefpihrt.Roslynator2019) and follow suggestions.
28+
* **DO** install extension for VS/VS Code and follow suggestions.

ChangeLog.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add GitHub workflow ([#1112](https://github.com/josefpihrt/roslynator/pull/1112))
13+
1014
### Changed
1115

1216
- [CLI] Bump Roslyn to 4.6.0 ([#1106](https://github.com/josefpihrt/roslynator/pull/1106)).

GitVersion.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
build-metadata-padding: 4
2+
mode: ContinuousDeployment
3+
4+
branches:
5+
main:
6+
tag: beta
7+
pull-request:
8+
tag: alpha
9+
tag-number-pattern: '[/-](?<number>\d+)[-/]'

src/Analyzers.CodeFixes/Analyzers.CodeFixes.csproj

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66

77
<PropertyGroup>
8-
<Version>$(RoslynatorVersion)</Version>
8+
<Version>$(RoslynatorAnalyzersVersion)</Version>
99
<AssemblyName>Roslynator.CSharp.Analyzers.CodeFixes</AssemblyName>
1010
<RootNamespace>Roslynator.CSharp</RootNamespace>
1111
<NuspecFile>Roslynator.Analyzers.nuspec</NuspecFile>
@@ -34,4 +34,10 @@
3434
<ProjectReference Include="..\Workspaces.Core\Workspaces.Core.csproj" />
3535
</ItemGroup>
3636

37+
<ItemGroup>
38+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
39+
<_Parameter1>Roslynator.Analyzers.Tests, PublicKey=$(RoslynatorPublicKey)</_Parameter1>
40+
</AssemblyAttribute>
41+
</ItemGroup>
42+
3743
</Project>

src/Analyzers.CodeFixes/CSharp/CodeFixes/OptimizeLinqMethodCallCodeFixProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ private static Task<Document> CallFindInsteadOfFirstOrDefaultAsync(
424424
{
425425
ITypeSymbol typeSymbol = semanticModel.GetTypeSymbol(invocationInfo.Expression, cancellationToken);
426426

427-
if ((typeSymbol as IArrayTypeSymbol)?.Rank == 1)
427+
if (typeSymbol is IArrayTypeSymbol { Rank: 1 })
428428
{
429429
NameSyntax arrayName = ParseName("global::System.Array")
430430
.WithLeadingTrivia(invocationInfo.InvocationExpression.GetLeadingTrivia())

src/Analyzers.CodeFixes/CSharp/Refactorings/SimplifyNullCheckRefactoring.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static async Task<Document> RefactorAsync(
4444
//RCS1084 UseCoalesceExpressionInsteadOfConditionalExpression
4545
newNode = nullCheck.Expression;
4646
coalesce = true;
47-
47+
4848
// If the types are polymorphic then the LHS of the null coalesce must be cast to the base type.
4949
ITypeSymbol newNodeType = semanticModel.GetTypeSymbol(newNode);
5050
ITypeSymbol whenNullType = semanticModel.GetTypeSymbol(whenNull);
@@ -59,8 +59,8 @@ public static async Task<Document> RefactorAsync(
5959
castType = NullableType(castType);
6060

6161
newNode = CastExpression(
62-
castType,
63-
newNode.WithoutTrivia())
62+
castType,
63+
newNode.WithoutTrivia())
6464
.WithTriviaFrom(newNode);
6565
}
6666
}
@@ -73,7 +73,7 @@ public static async Task<Document> RefactorAsync(
7373
var memberAccessExpression = (MemberAccessExpressionSyntax)expression.Parent;
7474

7575
if (!memberAccessExpression.IsParentKind(SyntaxKind.InvocationExpression)
76-
&& (memberAccessExpression.Name as IdentifierNameSyntax)?.Identifier.ValueText == "Value")
76+
&& memberAccessExpression.Name is IdentifierNameSyntax { Identifier.ValueText: "Value" })
7777
{
7878
if (memberAccessExpression == whenNotNull)
7979
{

src/Analyzers.CodeFixes/Properties/AssemblyInfo.cs

-5
This file was deleted.

src/Analyzers/Analyzers.csproj

+9
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@
2424
<ProjectReference Include="..\CSharp\CSharp.csproj" />
2525
</ItemGroup>
2626

27+
<ItemGroup>
28+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
29+
<_Parameter1>Roslynator.Analyzers.Tests, PublicKey=$(RoslynatorPublicKey)</_Parameter1>
30+
</AssemblyAttribute>
31+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
32+
<_Parameter1>Roslynator.CSharp.Analyzers.CodeFixes, PublicKey=$(RoslynatorPublicKey)</_Parameter1>
33+
</AssemblyAttribute>
34+
</ItemGroup>
35+
2736
</Project>

0 commit comments

Comments
 (0)