forked from MaterialDesignInXAML/MaterialDesignInXamlToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
304 lines (253 loc) · 10 KB
/
release.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
name: Production Release
on:
workflow_dispatch:
inputs:
milestone:
description: 'The milestone to generate a release for'
required: true
type: string
env:
solution: MaterialDesignToolkit.Full.sln
# Needed for GitHub CLI
GH_TOKEN: ${{ github.token }}
defaults:
run:
shell: pwsh
jobs:
get_versions:
name: Get Versions
uses: ./.github/workflows/get_versions.yml
with:
is-full-release: true
version_number_check:
needs: [get_versions]
runs-on: ubuntu-latest
name: Version matches milestone
steps:
- name: Check versions
run: |
if ('${{ inputs.milestone }}' -ne '${{ needs.get_versions.outputs.mdix-version }}') {
Write-Error "Milestone ${{ inputs.milestone }} does not match MDIX ${{ needs.get_versions.outputs.mdix-version }}"
exit 1
} else {
Write-Host "Versions match"
}
build_release_notes:
runs-on: ubuntu-latest
name: Generate Release Notes
steps:
- name: Get Contributors
id: get-contribs
uses: Keboo/GitHubHelper@master
with:
milestone: '${{ inputs.milestone }}'
repository: 'MaterialDesignInXamlToolkit'
repository-owner: 'MaterialDesignInXAML'
token: ${{ github.token }}
- name: Generate Release Notes
run: |
$response = gh api --method POST -H "Accept: application/vnd.github+json" /repos/${{ github.repository }}/releases/generate-notes -f tag_name='v${{ inputs.milestone }}'
$json = $response | ConvertFrom-Json
$releaseNotes = $json.body
$contributors = "${{ steps.get-contribs.outputs.contributors }}"
$releaseNotes | Out-File -Append "ReleaseNotes.md"
"`n" | Out-File -Append "ReleaseNotes.md"
$contributors | Out-File -Append "ReleaseNotes.md"
cat "ReleaseNotes.md"
- name: Upload Release Notes
uses: actions/upload-artifact@v3
with:
name: ReleaseNotes
path: "ReleaseNotes.md"
build_artifacts:
name: Build artifacts
needs: get_versions
uses: ./.github/workflows/build_artifacts.yml
with:
mdix-version: ${{ needs.get_versions.outputs.mdix-version }}
mdix-colors-version: ${{ needs.get_versions.outputs.mdix-colors-version }}
mdix-mahapps-version: ${{ needs.get_versions.outputs.mdix-mahapps-version }}
build_icon_changes:
needs: [build_artifacts]
runs-on: windows-latest
name: Get Icon Changes
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download NuGet Artifacts
uses: actions/download-artifact@v3
with:
name: NuGets
path: nugets
- name: Get Previous NuGet release
run: |
$release = (gh api -H "Accept: application/vnd.github+json" /repos/${{ github.repository }}/releases/latest) | ConvertFrom-Json
gh release download "$($release.tag_name)" --repo "${{ github.repository }}" --pattern *.nupkg
working-directory: nugets
- name: Create Icon Diff File
run: |
dotnet run --project ./mdresgen/mdresgen.csproj -c Release -- icon-diff
- name: Upload Icon Changes
uses: actions/upload-artifact@v3
with:
name: IconChanges
path: "IconChanges*.md"
create_release:
needs: [build_release_notes, build_artifacts, build_icon_changes, version_number_check]
runs-on: ubuntu-latest
name: Create Draft Release
steps:
- name: Download NuGet Artifacts
uses: actions/download-artifact@v3
with:
name: NuGets
path: nugets
- name: Download Demo App Artifacts
uses: actions/download-artifact@v3
with:
name: DemoApp
path: demo-app
- name: Zip Demo App
run: zip -r DemoApp.zip demo-app/*
- name: Download Release Notes
uses: actions/download-artifact@v3
with:
name: ReleaseNotes
- name: Create Release
run: |
# We can't use glob pattern because of this bug https://github.com/cli/cli/issues/5099
gh release create v${{ inputs.milestone }} --repo '${{ github.repository }}' --draft --latest --title "${{ inputs.milestone }}" --notes-file ReleaseNotes.md (Get-Item '${{ github.workspace }}/nugets/*.nupkg') '${{ github.workspace }}/DemoApp.zip'
update_wiki:
needs: [create_release]
runs-on: ubuntu-latest
environment: production
name: Update Wiki
steps:
- name: Checkout Wiki Repo
uses: actions/checkout@v3
with:
repository: ${{ github.repository }}.wiki
- name: Download Icon Changes
uses: actions/download-artifact@v3
with:
name: IconChanges
path: icon-changes
- name: Update Wiki
run: |
$iconUpdates = Get-ChildItem -Path "icon-changes/*.md"
foreach($update in $iconUpdates){
Write-Host "Updating from $update"
if ($update.Name -match '-(?<PreviousVersion>\d+\.\d+\.\d+)--(?<TargetVersion>\d+\.\d+\.\d+).md$') {
$previousVersion = $Matches.PreviousVersion
$targetVersion = $Matches.TargetVersion
$majorVersion = $targetVersion.Split(".") | Select-Object -First 1
# Update the changes
$changesFileName = "$majorVersion-x-icon-changes"
$changesFile = "$changesFileName.md"
if (!(Test-Path $changesFile)) {
New-Item -ItemType File $changesFile | Out-Null
}
@(
(Get-Content $update),
"",
(Get-Content $changesFile)
) | Set-Content $changesFile
# Update the PackIcon Release notes
[string[]] $releaseNotes = Get-Content "PackIcon-ReleaseNotes.md"
$firstLine = $releaseNotes | Where-Object { $_.StartsWith("[Pack Icon Changes") } | Select-Object -First 1
$index = $releaseNotes.IndexOf($firstLine)
@(
($releaseNotes | Select-Object -First $index),
"[Pack Icon Changes $previousVersion => $targetVersion]($changesFileName#pack-icon-changes-$($previousVersion -replace '\.', '')--$($targetVersion -replace '\.', ''))",
"",
($releaseNotes | Select-Object -Skip $index)
) | Set-Content "PackIcon-ReleaseNotes.md"
Remove-Item $update
} else {
Write-Warning "Did not parse version from $($update.Name)"
}
}
- name: Push Wiki
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "[automated] Update Wiki with icon changes for ${{ inputs.milestone }}" --all
git push
push_nugets:
needs: [create_release]
runs-on: ubuntu-latest
name: Push NuGets
environment: production
steps:
- name: Download NuGet Artifacts
uses: actions/download-artifact@v3
with:
name: NuGets
path: nugets
- name: Push NuGets
run: |
dotnet nuget push nugets/*.nupkg --api-key ${{ secrets.PAT }} --source https://api.nuget.org/v3/index.json --skip-duplicate
publish_release:
needs: [create_release]
runs-on: ubuntu-latest
name: Publish Release
environment: production
steps:
- name: Publish Release
run: |
gh release edit v${{ inputs.milestone }} --repo '${{ github.repository }}' --draft=false
close_milestone:
needs: [create_release]
runs-on: ubuntu-latest
name: Close Milestone
environment: production
steps:
# Doing a checkout, until this issue is resolved.
# https://github.com/valeriobelli/gh-milestone/issues/15
- uses: actions/checkout@v3
- name: Close Milestone
run: |
gh extension install valeriobelli/gh-milestone
$milestones = $(gh milestone list --json number,title) | ConvertFrom-Json
$milestoneNumber = ($milestones | Where-Object { $_.title -eq "${{ inputs.milestone }}" }).number
gh milestone edit $milestoneNumber --state closed
update_version_numbers:
needs: [create_release]
runs-on: ubuntu-latest
name: Update Version Numbers
environment: production
permissions:
actions: write
steps:
# Checkout is needed so that we can update the get_versions.yml file
- uses: actions/checkout@v3
- name: Increment Version Numbers
run: |
function Update-Version {
param (
[string]$Prefix
)
$workflowPath = "./.github/workflows/get_versions.yml"
$workflowContent = Get-Content -Path $workflowPath
$versionPattern = '"(\d+\.\d+\.)(\d+)"'
$pattern = "$Prefix`: $versionPattern"
$match = $workflowContent -match $pattern
if ($match[0] -match $versionPattern) {
$newVersion = $Matches[1] + ([int]$Matches[2] + 1)
$workflowContent = $workflowContent -replace $pattern,"$Prefix`: `"$newVersion`""
Write-Host "$Prefix updated to $newVersion"
} else {
Write-Error "Failed to update $Prefix version"
}
Set-Content -Path $workflowPath -Value $workflowContent
}
Update-Version -Prefix "mdix-version"
Update-Version -Prefix "mdix-colors-version"
Update-Version -Prefix "mdix-mahapps-version"
- name: Push Changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "[automated] Increment version numbers after release of ${{ inputs.milestone }}" --all
git push