-
Notifications
You must be signed in to change notification settings - Fork 0
391 lines (373 loc) · 15.5 KB
/
Copy pathupdate-dotnet-version.yml
File metadata and controls
391 lines (373 loc) · 15.5 KB
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
name: Update dotnet version
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * MON'
concurrency:
group: update-dotnet-version
cancel-in-progress: true
jobs:
init:
runs-on: ubuntu-latest
outputs:
active-dotnet-version: ${{ steps.active-dotnet-version.outputs.value }}
branch: ${{ steps.set-branch-name.outputs.value }}
steps:
- uses: actions/checkout@v4
- name: Set branch name
id: set-branch-name
run: |
echo "value=bot/update-dotnet-version" >> $GITHUB_OUTPUT
- name: Get active .NET versions
id: active-dotnet-version
shell: pwsh
run: |
$activeVersions = ((((Invoke-WebRequest -Uri "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json" -UseBasicParsing | ConvertFrom-Json)."releases-index" | Where-Object { $_."product" -eq ".NET" -and ($_."support-phase" -eq "active" -or $_."support-phase" -eq "maintenance") | Sort-Object -Property channel-version -Descending } | Select -Property channel-version)."channel-version") -split "," | ForEach-Object { "net$_" }) -join ","
if ([string]::IsNullOrWhitespace($activeVersions)) {
exit 1
}
"value=$($activeVersions)" >> $env:GITHUB_OUTPUT
exit 0
- name: "Reset branches"
run: |
BRANCHES=(
"${{ steps.set-branch-name.outputs.value }}"
"${{ steps.set-branch-name.outputs.value }}/partial/EncryptedConfigValue.Module"
"${{ steps.set-branch-name.outputs.value }}/partial/EncryptedConfigValue.AspNetCore"
"${{ steps.set-branch-name.outputs.value }}/partial/EncryptedConfigValue.Cli"
"${{ steps.set-branch-name.outputs.value }}/partial/pipelines"
)
for BRANCH in "${BRANCHES[@]}"; do
is_branch_exists_origin=$(git ls-remote --heads origin $BRANCH | grep -q "refs/heads/$BRANCH" && echo true || echo false)
if [[ "$is_branch_exists_origin" == "true" ]]; then
git push origin --delete $BRANCH || { echo "Failed to delete branch $BRANCH on origin."; exit 1; }
fi
done
should-updated-targetframeworks:
needs: [init]
runs-on: ubuntu-latest
outputs:
module: ${{ steps.finalize.outputs.module }}
aspnetcore: ${{ steps.finalize.outputs.aspnetcore }}
cli: ${{ steps.finalize.outputs.cli }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/can-update-targetframeworks
id: should-update-targetframeworks-module
with:
project: EncryptedConfigValue.Module
target-dotnet-versions: ${{ needs.init.outputs.active-dotnet-version }}
- uses: ./.github/actions/can-update-targetframeworks
id: should-update-targetframeworks-aspnetcore
with:
project: EncryptedConfigValue.AspNetCore
target-dotnet-versions: ${{ needs.init.outputs.active-dotnet-version }}
- uses: ./.github/actions/can-update-targetframeworks
id: should-update-targetframeworks-cli
with:
project: EncryptedConfigValue.Cli
target-dotnet-versions: ${{ needs.init.outputs.active-dotnet-version }}
- name: Finalize
id: finalize
run: |
echo "module=${{ steps.should-update-targetframeworks-module.outputs.result }}" >> $GITHUB_OUTPUT
echo "aspnetcore=${{ steps.should-update-targetframeworks-aspnetcore.outputs.result }}" >> $GITHUB_OUTPUT
echo "cli=${{ steps.should-update-targetframeworks-cli.outputs.result }}" >> $GITHUB_OUTPUT
update-dotnet-module:
needs: [init, should-updated-targetframeworks]
if: needs.should-updated-targetframeworks.outputs.module == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
project: ${{ steps.set-project-name.outputs.value }}
branch: ${{ steps.set-branch-name.outputs.value }}
status: ${{ steps.set-status.outputs.value }}
steps:
- uses: actions/checkout@v4
- name: Set project name
id: set-project-name
run: |
echo "value=EncryptedConfigValue.Module" >> $GITHUB_OUTPUT
- name: Set branch name
id: set-branch-name
run: |
echo "value=${{ needs.init.outputs.branch }}/partial/${{ steps.set-project-name.outputs.value }}" >> $GITHUB_OUTPUT
- uses: ./.github/actions/setup-dotnet
- uses: ./.github/actions/setup-git
with:
branch: ${{ steps.set-branch-name.outputs.value }}
hard-reset: true
- uses: ./.github/actions/update-dotnet-version
with:
project: ${{ steps.set-project-name.outputs.value }}
target-dotnet-versions: ${{ needs.init.outputs.active-dotnet-version }}
- uses: ./.github/actions/update-dotnet-version
with:
project: ${{ steps.set-project-name.outputs.value }}.Test
target-dotnet-versions: ${{ needs.init.outputs.active-dotnet-version }}
- uses: ./.github/actions/commit-changes
with:
message: Update .NET version in ${{ steps.set-project-name.outputs.value }}
- uses: ./.github/actions/push-changes
with:
branch: ${{ steps.set-branch-name.outputs.value }}
force: true
- name: Set status
id: set-status
run: |
echo "value=true" >> $GITHUB_OUTPUT
update-dotnet-module-status-tracker:
needs: [update-dotnet-module]
if: always()
runs-on: ubuntu-latest
outputs:
completed: ${{ steps.set-status.outputs.value }}
steps:
- name: Set status
id: set-status
run: |
echo "value=${{needs.update-dotnet-module.outputs.status || 'false'}}" >> $GITHUB_OUTPUT
update-dotnet-aspnetcore:
needs: [init, should-updated-targetframeworks]
if: needs.should-updated-targetframeworks.outputs.aspnetcore == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
project: ${{ steps.set-project-name.outputs.value }}
branch: ${{ steps.set-branch-name.outputs.value }}
status: ${{ steps.set-status.outputs.value }}
steps:
- uses: actions/checkout@v4
- name: Set project name
id: set-project-name
run: |
echo "value=EncryptedConfigValue.AspNetCore" >> $GITHUB_OUTPUT
- name: Set branch name
id: set-branch-name
run: |
echo "value=${{ needs.init.outputs.branch }}/partial/${{ steps.set-project-name.outputs.value }}" >> $GITHUB_OUTPUT
- uses: ./.github/actions/setup-dotnet
- uses: ./.github/actions/setup-git
with:
branch: ${{ steps.set-branch-name.outputs.value }}
hard-reset: true
- uses: ./.github/actions/update-dotnet-version
with:
project: ${{ steps.set-project-name.outputs.value }}
target-dotnet-versions: ${{ needs.init.outputs.active-dotnet-version }}
- uses: ./.github/actions/update-dotnet-version
with:
project: ${{ steps.set-project-name.outputs.value }}.Test
target-dotnet-versions: ${{ needs.init.outputs.active-dotnet-version }}
- uses: ./.github/actions/commit-changes
with:
message: Update .NET version in ${{ steps.set-project-name.outputs.value }}
- uses: ./.github/actions/push-changes
with:
branch: ${{ steps.set-branch-name.outputs.value }}
force: true
- name: Set status
id: set-status
run: |
echo "value=true" >> $GITHUB_OUTPUT
update-dotnet-aspnetcore-status-tracker:
needs: [update-dotnet-aspnetcore]
if: always()
runs-on: ubuntu-latest
outputs:
completed: ${{ steps.set-status.outputs.value }}
steps:
- name: Set status
id: set-status
run: |
echo "value=${{needs.update-dotnet-aspnetcore.outputs.status || 'false'}}" >> $GITHUB_OUTPUT
update-dotnet-cli:
needs: [init, should-updated-targetframeworks]
if: needs.should-updated-targetframeworks.outputs.cli == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
project: ${{ steps.set-project-name.outputs.value }}
branch: ${{ steps.set-branch-name.outputs.value }}
status: ${{ steps.set-status.outputs.value }}
steps:
- uses: actions/checkout@v4
- name: Set project name
id: set-project-name
run: |
echo "value=EncryptedConfigValue.Cli" >> $GITHUB_OUTPUT
- name: Set branch name
id: set-branch-name
run: |
echo "value=${{ needs.init.outputs.branch }}/partial/${{ steps.set-project-name.outputs.value }}" >> $GITHUB_OUTPUT
- uses: ./.github/actions/setup-dotnet
- uses: ./.github/actions/setup-git
with:
branch: ${{ steps.set-branch-name.outputs.value }}
hard-reset: true
- uses: ./.github/actions/update-dotnet-version
with:
project: ${{ steps.set-project-name.outputs.value }}
target-dotnet-versions: ${{ needs.init.outputs.active-dotnet-version }}
- uses: ./.github/actions/update-dotnet-version
with:
project: ${{ steps.set-project-name.outputs.value }}.Test
target-dotnet-versions: ${{ needs.init.outputs.active-dotnet-version }}
- uses: ./.github/actions/commit-changes
with:
message: Update .NET version in ${{ steps.set-project-name.outputs.value }}
- uses: ./.github/actions/push-changes
with:
branch: ${{ steps.set-branch-name.outputs.value }}
force: true
- name: Set status
id: set-status
run: |
echo "value=true" >> $GITHUB_OUTPUT
update-dotnet-cli-status-tracker:
needs: [update-dotnet-cli]
if: always()
runs-on: ubuntu-latest
outputs:
completed: ${{ steps.set-status.outputs.value }}
steps:
- name: Set status
id: set-status
run: |
echo "value=${{needs.update-dotnet-cli.outputs.status || 'false'}}" >> $GITHUB_OUTPUT
update-pipelines:
needs: [init, should-updated-targetframeworks]
if: needs.should-updated-targetframeworks.outputs.module == 'true' || needs.should-updated-targetframeworks.outputs.aspnetcore == 'true' || needs.should-updated-targetframeworks.outputs.cli == 'true'
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.set-branch-name.outputs.value }}
status: ${{ steps.set-status.outputs.value }}
steps:
- uses: actions/checkout@v4
- name: Set branch name
id: set-branch-name
run: |
echo "value=${{ needs.init.outputs.branch }}/partial/pipelines" >> $GITHUB_OUTPUT
- uses: ./.github/actions/setup-git
with:
branch: ${{ steps.set-branch-name.outputs.value }}
hard-reset: true
- name: Update setup-dotnet action
shell: pwsh
run: |
$versionString = "${{ needs.init.outputs.active-dotnet-version }}"
write-host $versionString
$filePath = "./.github/actions/setup-dotnet/action.yml"
$versions = $versionString -split ',' | ForEach-Object { ($_ -replace 'net', '') + ".x" }
$yamlContent = Get-Content $filePath -Raw
$dotnetVersionPattern = "(?sm)dotnet-version:\s*\|.*?(?=\w+:|\z)"
$indentation = if ($yamlContent -match "([ \t]*)dotnet-version: \|") { "$($matches[1]) " } else { "" }
$newDotnetVersionSection = "dotnet-version: |`r`n${indentation}" + ($versions | ForEach-Object { "${indentation}$_" } | Out-String).Trim()
$updatedYamlContent = $yamlContent -replace $dotnetVersionPattern, $newDotnetVersionSection
Set-Content $filePath -Value $updatedYamlContent
- uses: ./.github/actions/commit-changes
with:
message: Update pipelines
- uses: ./.github/actions/push-changes
with:
branch: ${{ steps.set-branch-name.outputs.value }}
force: true
- name: Set status
id: set-status
run: |
echo "value=true" >> $GITHUB_OUTPUT
update-pipelines-status-tracker:
needs: [update-pipelines]
if: always()
runs-on: ubuntu-latest
outputs:
completed: ${{ steps.set-status.outputs.value }}
steps:
- name: Set status
id: set-status
run: |
echo "value=${{needs.update-pipelines.outputs.status || 'false'}}" >> $GITHUB_OUTPUT
collect:
needs: [
update-dotnet-module-status-tracker,
update-dotnet-aspnetcore-status-tracker,
update-dotnet-cli-status-tracker,
update-pipelines-status-tracker
]
if: always() && contains(needs.*.outputs.completed, 'true')
runs-on: ubuntu-latest
outputs:
result: ${{ steps.set-status.outputs.value }}
steps:
- name: Set status
id: set-status
run: |
values=(
'${{ needs.update-dotnet-module-status-tracker.outputs.completed || 'false' }}'
'${{ needs.update-dotnet-aspnetcore-status-tracker.outputs.completed || 'false' }}'
'${{ needs.update-dotnet-cli-status-tracker.outputs.completed || 'false' }}'
'${{ needs.update-pipelines-status-tracker.outputs.completed || 'false' }}'
)
result='false'
for value in "${values[@]}"; do
if [ "$value" == "true" ]; then
result='true'
break
fi
done
echo "value=$result" >> $GITHUB_OUTPUT
finalize:
needs: [
init,
collect
]
if: always() && needs.collect.outputs.result == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-git
with:
branch: ${{ needs.init.outputs.branch }}
hard-reset: true
- name: Merge
run: |
TARGET_BRANCH="${{ needs.init.outputs.branch }}"
PARTIAL_BRANCHES=(
"${{ needs.init.outputs.branch }}/partial/EncryptedConfigValue.Module"
"${{ needs.init.outputs.branch }}/partial/EncryptedConfigValue.AspNetCore"
"${{ needs.init.outputs.branch }}/partial/EncryptedConfigValue.Cli"
"${{ needs.init.outputs.branch }}/partial/pipelines"
)
for BRANCH in "${PARTIAL_BRANCHES[@]}"; do
is_branch_exists=$(git ls-remote --heads origin $BRANCH | grep -q "refs/heads/$BRANCH" && echo true || echo false)
if [[ "$is_branch_exists" == "true" ]]; then
git fetch origin "$BRANCH"
hash=$(git ls-remote origin "$BRANCH" | cut -f1)
git rebase "$hash"
echo "Rebase successful for $BRANCH."
fi
done
for BRANCH in "${PARTIAL_BRANCHES[@]}"; do
is_branch_exists_origin=$(git ls-remote --heads origin $BRANCH | grep -q "refs/heads/$BRANCH" && echo true || echo false)
if [[ "$is_branch_exists_origin" == "true" ]]; then
echo "Deleting branch $BRANCH on origin..."
git push origin --delete $BRANCH || { echo "Failed to delete branch $BRANCH on origin. Continuing."; }
fi
done
- uses: ./.github/actions/push-changes
with:
branch: ${{ needs.init.outputs.branch }}
force: true
- uses: ./.github/actions/put-pull-request
with:
GITHUB_TOKEN: ${{ secrets.PAT }}
title: Update .NET versions
body: This PR updates .NET version used in project and pipelines.
from: ${{ needs.init.outputs.branch }}
into: main