-
Notifications
You must be signed in to change notification settings - Fork 0
247 lines (211 loc) · 7.82 KB
/
build-and-deploy.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
name: Build and Deploy
on:
push:
branches:
- dev
release:
types:
- published
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Restore
run: dotnet restore
- name: Trim readme.md
if: github.event_name == 'release'
shell: pwsh
run: |
(Get-Content .\readme.md | Select-Object -Skip 2) | Out-File readme.md
- name: Build
shell: pwsh
run: |
$additionalBuildArgs = @()
if ('${{ github.event_name }}' -ieq 'release') {
[string] $baseVersionPart, [string] $preReleaseVersionPart = '${{ github.ref_name }}' -split '\-'
[int] $major, [int] $minor, [int] $revision = $baseVersionPart -split '\.', 3
# The build version represents a build of the same sources, this seldom happens with releases.
# Pre-releases have only major and minor version leaving the build and revision numbers as undefined.
#
# Releases map the major, minor and patch version numbers to major, minor and revision respectively,
# leaving the build number to always be 0. If there will be a case where the same sources are build
# and released in a separate NuGet package it will be addressed at that point, right now I don't see
# how that will ever happen since releases are tagged in git (must be unique) using SemVer.
#
# https://learn.microsoft.com/dotnet/api/system.version
# https://semver.org
[string] $version = "$major.$minor.0.$revision"
if ($preReleaseVersionPart -ne [string]::Empty) {
$version = "$major.$minor"
}
$additionalBuildArgs += "-property:Version=$version"
}
$additionalBuildArgs += '-property:InformationalVersion=${{ github.ref_name }}'
[Convert]::FromBase64String('${{ secrets.KeyFile }}') `
| Set-Content ./CodeMap.snk -AsByteStream
dotnet build `
--configuration Release `
--no-restore `
-property:SignAssembly=True `
-property:AssemblyOriginatorKeyFile=../CodeMap.snk `
-property:DisableStrongNamer=False `
@additionalBuildArgs
- name: Test
shell: pwsh
run: |
dotnet test `
--configuration Release `
--no-build `
--verbosity normal
- name: Pack
if: github.event_name == 'release'
shell: pwsh
run: |
[string] $releaseNotes = (@"
${{ github.event.release.body }}
"@ -split '# Release Notes', 2 | Select-Object -Last 1).Trim() -replace ',', '%2c'
dotnet pack `
--configuration Release `
--output publish `
--no-build `
-property:PackageVersion='${{ github.ref_name }}' `
-property:PackageReleaseNotes="$releaseNotes"
- name: Upload CodeMap NuGet Package to Release
uses: actions/upload-release-asset@v1
if: github.event_name == 'release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./publish/CodeMap.${{ github.ref_name }}.nupkg
asset_name: CodeMap.${{ github.ref_name }}.nupkg
asset_content_type: application/zip
- name: Generate Project Site
shell: pwsh
run: |
function Sort-SemVerDescending([string[]] $versions) {
[string[]] $sortedVersions = @()
while ($versions.Length -gt 0) {
[string] $maxVersion = $versions[0]
$versions | Select-Object -Skip 1 | ForEach-Object {
if ((Compare-SemVer $maxVersion $_) -lt 0) {
$maxVersion = $_
}
}
$sortedVersions += $maxVersion
$versions = $versions | Where-Object { $_ -ne $maxVersion }
}
return $sortedVersions
}
function Compare-SemVer([string] $left, [string] $right) {
[string] $leftVersionParts = Get-VersionParts $left
[string] $rightVersionParts = Get-VersionParts $right
[int] $index = 0
[int] $result = 0
while ($index -lt $leftVersionParts.Length -and $index -lt $rightVersionParts.Length -and $result -eq 0) {
if ($leftVersionParts[$index] -lt $rightVersionParts[$index]) {
$result = -1
}
elseif ($leftVersionParts[$index] -gt $rightVersionParts[$index]) {
$result = 1
}
else {
$index++
}
}
if ($result -eq 0 -and ($leftVersionParts.Length -ne $rightVersionParts.Length)) {
if ($index -eq $leftVersionParts.Length) {
$result = -1
}
elseif ($index -eq $rightVersionParts.Length) {
$result = 1
}
}
return $result
}
function Get-VersionParts([string] $version) {
[string] $baseAndPreRelease, [string] $build = $version -split '\+', 2
[string] $base, [string] $preRelease = $baseAndPreRelease -split '-', 2
[int] $major, [int] $minor, [int] $patch = $base -split '\.', 3
$versionParts = @($major, $minor, $patch)
if (-not [string]::IsNullOrWhiteSpace($preRelease)) {
$versionParts += 0
($preRelease -split '\.') `
| ForEach-Object {
if ($_ -imatch '^\d+$') {
$versionParts += 0
$versionParts += [int]$_
}
else {
$versionParts += 1
$versionParts += $_
}
}
}
if (-not [string]::IsNullOrWhiteSpace($build)) {
$versionParts += 1
($build -split '\.') `
| ForEach-Object {
if ($_ -imatch '^\d+$') {
$versionParts += 0
$versionParts += [int]$_
}
else {
$versionParts += 1
$versionParts += $_
}
}
}
return $versionParts
}
New-Item `
-Type Directory `
-Name docs `
-ErrorAction SilentlyContinue `
| Out-Null
New-Item `
-Type Directory `
-Name _data `
-Path docs `
-ErrorAction SilentlyContinue `
| Out-Null
[string] $documentationDirectoryPath = if ('${{ github.event_name }}' -ieq 'release' -or '${{ github.ref_name }}' -ieq 'dev') { '${{ github.ref_name }}' } else { 'dev/${{ github.ref_name }}' }
dotnet run `
--project CodeMap.Documentation `
--configuration Release `
--no-build `
-- `
-OutputFilePath "./docs/$documentationDirectoryPath/index.html"
if (Test-Path 'CodeMap.Documentation/GitHub Pages') {
Copy-Item `
-Path 'CodeMap.Documentation/GitHub Pages/*' `
-Destination './docs' `
-Recurse
if (('${{ github.ref_name }}' -ine 'dev') -and (Test-Path './docs/_posts')) {
Remove-Item `
-Path './docs/_posts' `
-Recurse
}
}
Sort-SemVerDescending (
git tag `
| Where-Object { $_ -imatch '^\d+\.\d+\.\d+(-[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)?(\+[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)?$' }
) `
| ForEach-Object { "- $_" } `
| Out-File ./docs/_data/tags.yml -Encoding utf8
- name: Publish Project Site
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
destination_dir: docs
enable_jekyll: true
keep_files: true