-
Notifications
You must be signed in to change notification settings - Fork 0
343 lines (287 loc) · 14.6 KB
/
dotnet.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
name: .NET Workflow
on:
push:
branches:
- main
- develop
pull_request:
schedule:
- cron: "0 14 * * *"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
permissions:
packages: write
contents: write
env:
OUTPUT_PATH: 'output'
STAGING_PATH: 'staging'
DOTNET_VERSION: '9.0'
jobs:
dotnet:
name: .NET Workflow
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
persist-credentials: true
- name: Fetch tags
shell: pwsh
run: |
git fetch --prune --unshallow --tags
$global:LASTEXITCODE = 0
- name: Configure Environment
shell: pwsh
run: |
$IS_MAIN = "${{ github.ref }}" -eq "refs/heads/main"
$IS_TAGGED = (git show-ref --tags -d | Out-String).Contains("${{ github.sha }}")
$SHOULD_RELEASE = ($IS_MAIN -AND -NOT $IS_TAGGED)
$USE_DOTNET_SCRIPT = (Get-ChildItem -Recurse -Filter *.csx).Count -gt 0
$PACKAGE_PATTERN = Join-Path -Path "${{ github.workspace }}" -ChildPath "${{ env.STAGING_PATH }}" -AdditionalChildPath "*.nupkg"
$SYMBOLS_PATTERN = Join-Path -Path "${{ github.workspace }}" -ChildPath "${{ env.STAGING_PATH }}" -AdditionalChildPath "*.snupkg"
$APPLICATION_PATTERN = Join-Path -Path "${{ github.workspace }}" -ChildPath "${{ env.STAGING_PATH }}" -AdditionalChildPath "*.zip"
"IS_MAIN=$IS_MAIN" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"IS_TAGGED=$IS_TAGGED" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"SHOULD_RELEASE=$SHOULD_RELEASE" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"USE_DOTNET_SCRIPT=$USE_DOTNET_SCRIPT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"PACKAGE_PATTERN=$PACKAGE_PATTERN" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"SYMBOLS_PATTERN=$SYMBOLS_PATTERN" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"APPLICATION_PATTERN=$APPLICATION_PATTERN" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Host "IS_MAIN: $IS_MAIN"
Write-Host "IS_TAGGED: $IS_TAGGED"
Write-Host "SHOULD_RELEASE: $SHOULD_RELEASE"
Write-Host "USE_DOTNET_SCRIPT: $USE_DOTNET_SCRIPT"
Write-Host "PACKAGE_PATTERN: $PACKAGE_PATTERN"
Write-Host "SYMBOLS_PATTERN: $SYMBOLS_PATTERN"
Write-Host "APPLICATION_PATTERN: $APPLICATION_PATTERN"
$global:LASTEXITCODE = 0
- name: Generate Version
shell: pwsh
run: |
# find the last version that was released
$LAST_TAG = (git tag --list --sort=-v:refname)[0]
$LAST_VERSION = $LAST_TAG -replace 'v', ''
$IS_PRERELEASE = $LAST_VERSION.Contains('-')
$LAST_VERSION = $LAST_VERSION -replace '-alpha', ''
$LAST_VERSION = $LAST_VERSION -replace '-beta', ''
$LAST_VERSION = $LAST_VERSION -replace '-rc', ''
$LAST_VERSION = $LAST_VERSION -replace '-pre', ''
if ($LAST_VERSION -eq '') {
$LAST_VERSION = '1.0.0-pre.0'
}
$LAST_VERSION_COMPONENTS = $LAST_VERSION -split '\.'
$LAST_VERSION_MAJOR = [int]$LAST_VERSION_COMPONENTS[0]
$LAST_VERSION_MINOR = [int]$LAST_VERSION_COMPONENTS[1]
$LAST_VERSION_PATCH = [int]$LAST_VERSION_COMPONENTS[2]
$LAST_VERSION_PRERELEASE = 0
if ($LAST_VERSION_COMPONENTS.Length -gt 3) {
$LAST_VERSION_PRERELEASE = [int]$LAST_VERSION_COMPONENTS[3]
}
# calculate which increment is needed
$EXCLUDE_BOTS = '^(?!.*(\[bot\]|github|ProjectDirector|SyncFileContents)).*$'
$EXCLUDE_HIDDEN_FILES = ":(icase,exclude)*/.*"
$EXCLUDE_MARKDOWN_FILES = ":(icase,exclude)*/*.md"
$EXCLUDE_TEXT_FILES = ":(icase,exclude)*/*.txt"
$EXCLUDE_SOLUTIONS_FILES = ":(icase,exclude)*/*.sln"
$EXCLUDE_PROJECTS_FILES = ":(icase,exclude)*/*.*proj"
$EXCLUDE_URL_FILES = ":(icase,exclude)*/*.url"
$EXCLUDE_BUILD_FILES = ":(icase,exclude)*/Directory.Build.*"
$EXCLUDE_CI_FILES = ":(icase,exclude).github/workflows/*"
$INCLUDE_ALL_FILES = "*/*.*"
$FIRST_COMMIT = (git rev-list HEAD)[-1]
$LAST_COMMIT = '${{ github.sha }}'
$COMMITS = "$FIRST_COMMIT...$LAST_COMMIT"
$LAST_PATCH_COMMIT = git log -n 1 --perl-regexp --regexp-ignore-case --format=format:%H --committer="$EXCLUDE_BOTS" --author="$EXCLUDE_BOTS" $COMMITS
$LAST_MINOR_COMMIT = git log -n 1 --perl-regexp --regexp-ignore-case --format=format:%H --committer="$EXCLUDE_BOTS" --author="$EXCLUDE_BOTS" $COMMITS `
-- `
$INCLUDE_ALL_FILES `
$EXCLUDE_HIDDEN_FILES `
$EXCLUDE_MARKDOWN_FILES `
$EXCLUDE_TEXT_FILES `
$EXCLUDE_SOLUTIONS_FILES `
$EXCLUDE_PROJECTS_FILES `
$EXCLUDE_URL_FILES `
$EXCLUDE_BUILD_FILES `
$EXCLUDE_CI_FILES
$VERSION_INCREMENT = 'prerelease'
if ($LAST_COMMIT -eq $LAST_PATCH_COMMIT) {
$VERSION_INCREMENT = 'patch'
}
if ($LAST_COMMIT -eq $LAST_MINOR_COMMIT) {
$VERSION_INCREMENT = 'minor'
}
if ($IS_PRERELEASE) {
if ($VERSION_INCREMENT -eq 'prerelease') {
$NEW_PRERELEASE = $LAST_VERSION_PRERELEASE + 1
$VERSION = "$LAST_VERSION_MAJOR.$LAST_VERSION_MINOR.$LAST_VERSION_PATCH-pre.$NEW_PRERELEASE"
} elseif ($VERSION_INCREMENT -eq 'patch') {
$VERSION = "$LAST_VERSION_MAJOR.$LAST_VERSION_MINOR.$LAST_VERSION_PATCH"
}
} else {
if ($VERSION_INCREMENT -eq 'prerelease') {
$NEW_PATCH = $LAST_VERSION_PATCH + 1
$VERSION = "$LAST_VERSION_MAJOR.$LAST_VERSION_MINOR.$NEW_PATCH-pre.1"
} elseif ($VERSION_INCREMENT -eq 'patch') {
$NEW_PATCH = $LAST_VERSION_PATCH + 1
$VERSION = "$LAST_VERSION_MAJOR.$LAST_VERSION_MINOR.$NEW_PATCH"
}
}
if ($VERSION_INCREMENT -eq 'minor') {
$NEW_MINOR = $LAST_VERSION_MINOR + 1
$VERSION = "$LAST_VERSION_MAJOR.$NEW_MINOR.0"
}
# Output the version information
Write-Host "LAST_VERSION: $LAST_VERSION"
Write-Host "LAST_VERSION_MAJOR: $LAST_VERSION_MAJOR"
Write-Host "LAST_VERSION_MINOR: $LAST_VERSION_MINOR"
Write-Host "LAST_VERSION_PATCH: $LAST_VERSION_PATCH"
Write-Host "LAST_VERSION_PRERELEASE: $LAST_VERSION_PRERELEASE"
Write-Host "IS_PRERELEASE: $IS_PRERELEASE"
Write-Host "FIRST_COMMIT: $FIRST_COMMIT"
Write-Host "LAST_COMMIT: $LAST_COMMIT"
Write-Host "LAST_PATCH_COMMIT: $LAST_PATCH_COMMIT"
Write-Host "LAST_MINOR_COMMIT: $LAST_MINOR_COMMIT"
Write-Host "VERSION_INCREMENT: $VERSION_INCREMENT"
Write-Host "VERSION: $VERSION"
# set the environment variables
"LAST_VERSION=$LAST_VERSION" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"LAST_VERSION_MAJOR=$LAST_VERSION_MAJOR" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"LAST_VERSION_MINOR=$LAST_VERSION_MINOR" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"LAST_VERSION_PATCH=$LAST_VERSION_PATCH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"LAST_VERSION_PRERELEASE=$LAST_VERSION_PRERELEASE" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"IS_PRERELEASE=$IS_PRERELEASE" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"FIRST_COMMIT=$FIRST_COMMIT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"LAST_COMMIT=$LAST_COMMIT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"LAST_PATCH_COMMIT=$LAST_PATCH_COMMIT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"LAST_MINOR_COMMIT=$LAST_MINOR_COMMIT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"VERSION_INCREMENT=$VERSION_INCREMENT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"VERSION=$VERSION" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
# output files
$VERSION | Out-File -FilePath VERSION.md -Encoding utf8
$global:LASTEXITCODE = 0
- name: Generate License
shell: pwsh
run: |
$AUTHORS = '${{ github.repository_owner }}'.Replace('-', '.') + ' contributors'
$COPYRIGHT = "Copyright (c) 2023-$(Get-Date -Format 'yyyy') $AUTHORS"
$PROJECT_URL = "${{ github.server_url }}/${{ github.repository }}"
$AUTHORS_URL = "${{ github.server_url }}/${{ github.repository_owner }}"
$LICENSE = @"
MIT License
$PROJECT_URL
$COPYRIGHT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the `"Software`"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED `"AS IS`", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"@
# output files
$LICENSE | Out-File -FilePath LICENSE.md -Encoding utf8
$AUTHORS | Out-File -FilePath AUTHORS.md -Encoding utf8
$COPYRIGHT | Out-File -FilePath COPYRIGHT.md -Encoding utf8
$PROJECT_URL | Out-File -FilePath PROJECT_URL.url -Encoding utf8
$AUTHORS_URL | Out-File -FilePath AUTHORS.url -Encoding utf8
# output the metadata
Write-Host "AUTHORS: $AUTHORS"
Write-Host "COPYRIGHT: $COPYRIGHT"
Write-Host "LICENSE: $LICENSE"
Write-Host "PROJECT_URL: $PROJECT_URL"
Write-Host "AUTHORS_URL: $AUTHORS_URL"
# set the environment variables
"AUTHORS=$AUTHORS" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"COPYRIGHT=$COPYRIGHT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"PROJECT_URL=$PROJECT_URL" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"AUTHORS_URL=$AUTHORS_URL" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
$global:LASTEXITCODE = 0
- name: Generate Changelog
shell: pwsh
run: |
$CHANGELOG = ""
$CHANGELOG += "## $VERSION"
Write-Host "CHANGELOG: $CHANGELOG"
"CHANGELOG=$CHANGELOG" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
$CHANGELOG | Out-File -FilePath CHANGELOG.md -Encoding utf8
$global:LASTEXITCODE = 0
- name: Commit Metadata
shell: pwsh
run: |
git config --global user.name "Github Actions"
git config --global user.email "[email protected]"
git add VERSION.md LICENSE.md AUTHORS.md COPYRIGHT.md CHANGELOG.md PROJECT_URL.url AUTHORS.url
git commit -m "[bot][skip ci] Update Metadata"
git push
$RELEASE_HASH = (git rev-parse HEAD)
Write-Host "RELEASE_HASH: $RELEASE_HASH"
"RELEASE_HASH=$RELEASE_HASH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
${{ env.DOTNET_VERSION }}.x
- name: Install dotnet-script
if: ${{ env.USE_DOTNET_SCRIPT == 'True' }}
shell: pwsh
run: dotnet tool install -g dotnet-script
- name: Build
shell: pwsh
run: dotnet build --configuration Release --verbosity normal --no-incremental
- name: Test
shell: pwsh
run: dotnet test --configuration Release --verbosity normal --no-build
- name: Detect Dependencies
if: ${{ env.SHOULD_RELEASE == 'True' }}
uses: advanced-security/[email protected]
- name: Package Libraries
if: ${{ env.SHOULD_RELEASE == 'True' }}
shell: pwsh
run: dotnet pack --configuration Release --output ${{ github.workspace }}/${{ env.STAGING_PATH }}
- name: Package Applications
if: ${{ env.SHOULD_RELEASE == 'True' }}
shell: pwsh
run: |
if (Test-Path ${{ github.workspace }}/${{ env.OUTPUT_PATH }}) {
Remove-Item -Recurse -Force ${{ github.workspace }}/${{ env.OUTPUT_PATH }}
}
Get-ChildItem -Recurse -Filter *.csproj | ForEach-Object {
$csproj = $_
$projName = [System.IO.Path]::GetFileNameWithoutExtension($csproj)
$outDir = "${{ github.workspace }}/${{ env.OUTPUT_PATH }}/$projName"
$stageDir = "${{ github.workspace }}/${{ env.STAGING_PATH }}"
$stageFile = "$stageDir/$projName-${{ env.VERSION }}.zip"
New-Item -Path $outDir -ItemType Directory -Force
New-Item -Path $stageDir -ItemType Directory -Force
dotnet publish $csproj --no-build --configuration Release --framework net${{ env.DOTNET_VERSION }} --output $outDir
Compress-Archive -Path $outDir/* -DestinationPath $stageFile
}
- name: Publish Libraries to GitHub
if: ${{ env.SHOULD_RELEASE == 'True' && hashFiles(env.PACKAGE_PATTERN) != '' }}
shell: pwsh
run: dotnet nuget push ${{ env.PACKAGE_PATTERN }} --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate
- name: Publish Libraries to NuGet
if: ${{ env.SHOULD_RELEASE == 'True' && hashFiles(env.PACKAGE_PATTERN) != '' }}
shell: pwsh
run: dotnet nuget push ${{ env.PACKAGE_PATTERN }} --api-key ${{ secrets.NUGET_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
- name: Release
if: ${{ env.SHOULD_RELEASE == 'True' }}
uses: ncipollo/release-action@v1
with:
artifacts: "${{ env.PACKAGE_PATTERN }},${{ env.SYMBOLS_PATTERN }},${{ env.APPLICATION_PATTERN }}"
tag: v${{ env.VERSION }}
commit: ${{ env.RELEASE_HASH }}
allowUpdates: false
skipIfReleaseExists: true
omitBody: true
generateReleaseNotes: true
replacesArtifacts: false
makeLatest: true