-
Notifications
You must be signed in to change notification settings - Fork 0
253 lines (220 loc) · 8.82 KB
/
build-bump-version.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
name: Build & Bump Version
on:
push:
branches:
- '*'
- '*/*'
- '**'
- '!main'
paths-ignore:
- "**/Properties/AssemblyInfo.cs"
- "**/Properties/Version.txt"
workflow_dispatch:
concurrency:
group: bump-version
cancel-in-progress: true
env:
GHA_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
jobs:
updateVersion:
name: Build & Patch
runs-on: self-hosted
permissions:
pull-requests: write
steps:
- name: Generate a token
id: generate_token
uses: tibdex/[email protected]
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Update PR with comment (build started)
uses: mshick/add-pr-comment@v2
with:
repo-token: ${{ steps.generate_token.outputs.token }}
refresh-message-position: true
message-id: 'begin'
message: |
**Build debug & Version bump:** :beginner: [Build started](${{ env.GHA_URL }})
- name: Generate check
uses: LouisBrunner/[email protected]
id: generate_check
if: always()
with:
token: ${{ steps.generate_token.outputs.token }}
name: 'Build & Bump Version'
status: 'in_progress'
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ steps.generate_token.outputs.token }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Check for changes in Src/ directory
uses: dorny/paths-filter@v2
id: changes
with:
filters: |
src:
- "Src/**"
- name: Set solution name
run: |
echo "solution=$([io.path]::GetFileNameWithoutExtension($(Get-ChildItem -Path .\* -Include *.sln)))" | Out-File -FilePath $env:GITHUB_ENV -Append
echo "projectPath=$((Get-ChildItem -Path .\Src\ -Directory | Select-Object -First 1).Name)" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Update PR with comment (build started solution)
uses: mshick/add-pr-comment@v2
if: steps.changes.outputs.src == 'true'
with:
repo-token: ${{ steps.generate_token.outputs.token }}
refresh-message-position: true
message-id: 'begin'
message: |
**Build debug & Version bump:** :beginner: [Building ${{ env.solution }}.sln](${{ env.GHA_URL }})
- name: Update PR with comment (build started solution)
uses: mshick/add-pr-comment@v2
if: steps.changes.outputs.src == 'false'
with:
repo-token: ${{ steps.generate_token.outputs.token }}
refresh-message-position: true
message-id: 'begin'
message: |
**Build debug & Version bump:** :alien: [Not building ${{ env.solution }}.sln](${{ env.GHA_URL }}), no source files changed.
- name: Add MSBuild to PATH
uses: microsoft/[email protected]
if: steps.changes.outputs.src == 'true'
with:
msbuild-architecture: x64
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: Setup Nuget
uses: nuget/setup-nuget@v1
if: steps.changes.outputs.src == 'true'
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: Restore NuGet packages
if: steps.changes.outputs.src == 'true'
run: nuget restore "${{ env.solution }}.sln"
- name: Build Debug
if: steps.changes.outputs.src == 'true'
run: msbuild "${{ env.solution }}.sln" /p:Configuration=Debug -verbosity:detailed -flp1:"logfile=msbuild.errors.log;errorsonly" -flp2:"logfile=msbuild.warnings.log;warningsonly"
- name: Set version from the file
if: steps.changes.outputs.src == 'true'
run: |
echo "version=$(type Src/${{ env.projectPath }}/Properties/Version.txt)" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Upload artifact warnings debug
uses: actions/upload-artifact@v3
if: steps.changes.outputs.src == 'true'
with:
name: msbuild-warnings-debug
path: |
msbuild.warnings.log
- name: Upload artifact errors debug
uses: actions/upload-artifact@v3
if: failure() && steps.changes.outputs.src == 'true'
with:
name: msbuild-errors-debug
path: |
msbuild.errors.log
- name: Read msbuild.warnings.log
uses: guibranco/github-file-reader-action-v2@latest
if: steps.changes.outputs.src == 'true'
id: warnings
with:
path: msbuild.warnings.log
- name: Read msbuild.errors.log
uses: guibranco/github-file-reader-action-v2@latest
if: failure() && steps.changes.outputs.src == 'true'
id: errors
with:
path: msbuild.errors.log
- name: Update PR with comment (version)
uses: mshick/add-pr-comment@v2
if: steps.changes.outputs.src == 'true'
with:
repo-token: ${{ steps.generate_token.outputs.token }}
refresh-message-position: true
message-id: 'version'
message: |
**Build debug & Version bump:** :dart: [Build succeeded](${{ env.GHA_URL }}) - New version: ${{ env.version }}
- name: Set check as successfully before new commit
uses: LouisBrunner/[email protected]
if: success()
with:
token: ${{ steps.generate_token.outputs.token }}
conclusion: 'success'
check_id: ${{ steps.generate_check.outputs.check_id }}
output: |
{"summary":"New version: ${{ env.version }}"}
- name: Set check as "action required" before new commit
uses: LouisBrunner/[email protected]
if: failure()
with:
token: ${{ steps.generate_token.outputs.token }}
conclusion: 'action_required'
action_url: ${{ env.GHA_URL }}
check_id: ${{ steps.generate_check.outputs.check_id }}
output: |
{"summary": "Build failed!"}
- name: Setup GIT
if: steps.changes.outputs.src == 'true'
run: |
git config user.name "net-framework-updater[bot]"
git config user.email "136581072+net-framework-updater[bot]@users.noreply.github.com"
git config --global --add --bool push.autoSetupRemote true
- name: Commit and Push
if: steps.changes.outputs.src == 'true'
run: |
git add .
git commit -a -m "Version bump (CI)"
echo "sha1=$(git rev-parse HEAD)" | Out-File -FilePath $env:GITHUB_ENV -Append
git push
- name: Update PR with comment
uses: mshick/add-pr-comment@v2
if: always() && steps.changes.outputs.src == 'true'
with:
repo-token: ${{ steps.generate_token.outputs.token }}
refresh-message-position: true
message-id: 'final'
message: |
**Build debug & Version bump:** :white_check_mark: [Successfully builded and patched](${{ env.GHA_URL }}) **${{ env.solution }}.sln**.
**Version:** :hash: ${{ env.version }}
**Warnings:** :warning:
```
${{ steps.warnings.outputs.contents }}
```
message-failure: |
**Build debug & Version bump:** :x: [Failed](${{ env.GHA_URL }})
**Errors:** :no_entry:
```
${{ steps.errors.outputs.contents }}
```
message-cancelled: |
**Build debug & Version bump:** :o: [Cancelled](${{ env.GHA_URL }})
- name: Set check as successfully after a new commit
uses: LouisBrunner/[email protected]
if: steps.changes.outputs.src == 'true'
with:
token: ${{ steps.generate_token.outputs.token }}
conclusion: 'success'
name: 'Build & Bump Version'
output: |
{"summary":"New version: ${{ env.version }}"}
- name: Update check run status (Success)
uses: guibranco/[email protected]
if: success() && steps.changes.outputs.src == 'true'
with:
authToken: ${{ steps.generate_token.outputs.token }}
context: 'Build & Bump Version'
description: 'Build ${{ env.solution}}.sln - Version: ${{ env.version }}'
state: 'success'
sha: ${{ env.sha1 }}
target_url: ${{ env.GHA_URL }}
- name: Update check run status (Failure or Cancellation)
uses: guibranco/[email protected]
if: failure() || cancelled()
with:
authToken: ${{ steps.generate_token.outputs.token }}
context: 'Build & Bump Version'
description: ${{ job.status }}
state: 'failure'
sha: ${{ github.event.pull_request.head.sha || github.sha }}
target_url: ${{ env.GHA_URL }}