-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (145 loc) · 5.16 KB
/
build.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
name: Build
on:
push:
branches:
- "*"
- "*/*"
- "**"
- "!main"
workflow_dispatch:
concurrency:
group: build
cancel-in-progress: true
env:
GHA_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
jobs:
build:
name: Build
runs-on: windows-latest
permissions:
pull-requests: write
steps:
- name: Update PR with comment (build started)
uses: mshick/add-pr-comment@v2
with:
refresh-message-position: true
message-id: "begin"
message: |
**Build:** :beginner: [Build started](${{ env.GHA_URL }})
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for changes in Src/ directory
uses: dorny/paths-filter@v3
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:
refresh-message-position: true
message-id: "begin"
message: |
**Build:** :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:
refresh-message-position: true
message-id: "begin"
message: |
**Build:** :alien: [Not building ${{ env.solution }}.sln](${{ env.GHA_URL }}), no source files changed.
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: 21
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Build solution
run: dotnet build -c Release -v m -fl1 "/flp1:logFile=msbuild.errors.log;errorsonly" -fl2 "/flp2:logFile=msbuild.warnings.log;warningsonly"
- name: Run tests
run: dotnet test -c Release --no-build --no-restore
- name: Upload artifact warnings release
uses: actions/upload-artifact@v4
if: steps.changes.outputs.src == 'true'
with:
name: msbuild-warnings-release
path: |
msbuild.warnings.log
- name: Upload artifact errors release
uses: actions/upload-artifact@v4
if: failure() && steps.changes.outputs.src == 'true'
with:
name: msbuild-errors-release
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
uses: mshick/add-pr-comment@v2
if: steps.changes.outputs.src == 'true'
with:
refresh-message-position: true
message-id: "version"
message: |
**Build:** :dart: [Build succeeded](${{ env.GHA_URL }})
- name: Update PR with comment
uses: mshick/add-pr-comment@v2
if: always() && steps.changes.outputs.src == 'true'
with:
refresh-message-position: true
message-id: "final"
message: |
**Build:** :white_check_mark: [Successfully builded](${{ env.GHA_URL }}) **${{ env.solution }}.sln**.
**Warnings:** :warning:
```
${{ steps.warnings.outputs.contents }}
```
message-failure: |
**Build:** :x: [Failed](${{ env.GHA_URL }})
**Errors:** :no_entry:
```
${{ steps.errors.outputs.contents }}
```
message-cancelled: |
**Build:** :o: [Cancelled](${{ env.GHA_URL }})