-
-
Notifications
You must be signed in to change notification settings - Fork 49
167 lines (155 loc) · 6.45 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: publish
on:
push:
branches:
- 'main'
paths-ignore:
- "docs/**"
- "renovate.json"
- "GenerateDocumentation.cmd"
- "codecov.yml"
- ".markdownlint.json"
- ".github/ISSUE_TEMPLATE/**"
- ".github/FUNDING.yml"
pull_request:
branches:
- '*'
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget
defaults:
run:
shell: pwsh
jobs:
compute_package_version:
runs-on: ubuntu-latest
outputs:
package_version: ${{ steps.compute-version.outputs.package_version }}
steps:
- id: compute-version
name: Compute version
run: |
$(Invoke-WebRequest "https://www.nuget.org/api/v2/package/Meziantou.Analyzer/").BaseResponse.RequestMessage.RequestUri -match "meziantou\.analyzer\.2\.0\.([0-9]+).nupkg$"
$NewVersion = "2.0.$([int]$Matches.1 + 1)"
if ($env:GITHUB_REF -ne 'refs/heads/main') {
$NewVersion = $NewVersion + '-build.${{ github.run_id }}'
}
Write-Host "New version: $NewVersion"
"package_version=$NewVersion" >> $env:GITHUB_OUTPUT
create_nuget:
runs-on: ubuntu-latest
needs: [ compute_package_version ]
env:
RepositoryBranch: ${{github.ref}}
steps:
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
- run: dotnet run --project src/ListDotNetTypes/ListDotNetTypes.csproj -- src/Meziantou.Analyzer/Resources/
- run: dotnet build src/Meziantou.Analyzer/Meziantou.Analyzer.csproj --configuration Release /p:RoslynVersion=roslyn3.8 /p:Version=${{ needs.compute_package_version.outputs.package_version }}
- run: dotnet build src/Meziantou.Analyzer/Meziantou.Analyzer.csproj --configuration Release /p:RoslynVersion=roslyn4.2 /p:Version=${{ needs.compute_package_version.outputs.package_version }}
- run: dotnet build src/Meziantou.Analyzer/Meziantou.Analyzer.csproj --configuration Release /p:RoslynVersion=roslyn4.4 /p:Version=${{ needs.compute_package_version.outputs.package_version }}
- run: dotnet build src/Meziantou.Analyzer/Meziantou.Analyzer.csproj --configuration Release /p:RoslynVersion=roslyn4.6 /p:Version=${{ needs.compute_package_version.outputs.package_version }}
- run: dotnet restore src/Meziantou.Analyzer.pack.csproj
- run: dotnet pack src/Meziantou.Analyzer.pack.csproj --configuration Release --no-build /p:Version=${{ needs.compute_package_version.outputs.package_version }}
- run: dotnet pack src/Meziantou.Analyzer.Annotations/Meziantou.Analyzer.Annotations.csproj --configuration Release
- uses: actions/upload-artifact@v3
with:
name: nuget
if-no-files-found: error
retention-days: 3
path: '**/*.nupkg'
validate_nuget:
runs-on: ubuntu-latest
needs: [ create_nuget ]
steps:
- uses: actions/checkout@v3
- name: Setup .NET Core (global.json)
uses: actions/setup-dotnet@v3
- uses: actions/download-artifact@v3
with:
name: nuget
path: ${{ env.NuGetDirectory }}
- name: Run dotnet validate
run: |
dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global
$files = Get-ChildItem "${{ env.NuGetDirectory }}/*" -Recurse -Include *.nupkg
$Errors = $false
foreach($file in $files) {
& meziantou.validate-nuget-package "$file"
if ($LASTEXITCODE -ne 0) {
$Errors = $true
}
}
if ($Errors) {
exit 1
}
build_and_test:
runs-on: ${{ matrix.runs-on }}
env:
TestResultsDirectory: ${{ github.workspace}}/TestResults
strategy:
matrix:
runs-on: [ ubuntu-latest, windows-latest ]
configuration: [ Debug, Release ]
roslyn-version: [ 'roslyn3.8', 'roslyn4.2', 'roslyn4.4', 'default' ]
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Setup .NET Core (global.json)
uses: actions/setup-dotnet@v3
- run: dotnet test --configuration ${{ matrix.configuration }} --logger trx --logger "GitHubActions;report-warnings=false" --collect:"XPlat Code Coverage" --blame-hang --blame-hang-timeout 2min --results-directory "${{ env.TestResultsDirectory }}" /p:WarningsAsErrors=true /p:RoslynVersion=${{ matrix.roslyn-version}}
name: Run tests
- uses: actions/upload-artifact@v3
if: always()
with:
name: test-results-${{ matrix.runs-on }}-${{ matrix.configuration }}
if-no-files-found: error
retention-days: 3
path: ${{ env.TestResultsDirectory }}/**/*
- uses: codecov/codecov-action@v3
deploy:
runs-on: 'ubuntu-latest'
needs: [ validate_nuget, build_and_test ]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- uses: actions/download-artifact@v3
with:
name: nuget
path: ${{ env.NuGetDirectory }}
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
- run: |
Write-Host "Current ref: $env:GITHUB_REF"
Write-Host "Searching nupkg in folder: ${{ env.NuGetDirectory }}"
$files = Get-ChildItem "${{ env.NuGetDirectory }}/*" -Recurse -Include *.nupkg
foreach($file in $files) {
Write-Host "Pushing NuGet package: $($file.FullName)"
if ($env:GITHUB_REF -eq 'refs/heads/main')
{
& dotnet nuget push "$($file.FullName)" --api-key "$env:NuGetApiKey" --source https://api.nuget.org/v3/index.json --force-english-output --skip-duplicate
}
else
{
& dotnet nuget push "$($file.FullName)" --api-key "$env:FeedzApiKey" --source https://f.feedz.io/meziantou/meziantou-analyzer/nuget/index.json --force-english-output --skip-duplicate
}
}
name: Publish NuGet packages
if: always()
env:
NuGetApiKey: ${{ secrets.NUGETAPIKEY }}
FeedzApiKey: ${{ secrets.FEEDZ_APIKEY }}
create_release:
runs-on: 'ubuntu-latest'
if: ${{ github.ref == 'refs/heads/main' }}
needs: [ compute_package_version, deploy ]
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- run: 'gh release create "${{ needs.compute_package_version.outputs.package_version }}" --generate-notes --notes "NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/${{ needs.compute_package_version.outputs.package_version }}>"'
env:
GH_TOKEN: ${{ github.token }}