-
Notifications
You must be signed in to change notification settings - Fork 0
303 lines (282 loc) · 10.7 KB
/
dotnet.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
name: .NET
on:
push:
branches: [ "Development" ]
pull_request:
branches: [ "Development", "main" ]
env:
IMAGE_NAME: CargoHub
OWNER: "${{ github.repository_owner }}"
DOTNET_INSTALL_DIR: "./.dotnet"
jobs:
build:
runs-on: self-hosted
outputs:
BUILD_TIME: ${{ steps.build-time.outputs.time }}
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Cache NuGet packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore
- name: Add packages
run: |
dotnet add package Newtonsoft.Json
dotnet add package xunit
- name: Build
id: build-time
run: |
dotnet build --no-restore
echo "time=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
test:
needs: build
runs-on: self-hosted
outputs:
TEST_TIME: ${{ steps.test-time.outputs.time }}
COVERAGE: ${{ steps.coverage.outputs.percentage }}
UNIT_TEST_COVERAGE: ${{ steps.unit-test-coverage.outputs.percentage }}
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Cache .NET build output
uses: actions/cache@v3
with:
path: ~/.dotnet/
key: ${{ runner.os }}-dotnet-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-dotnet-
- name: Build the application
run: dotnet build --configuration Release
- name: Run unit tests with coverage
run: dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage" --results-directory ./coverage --verbosity normal
- name: Run application
run: dotnet run --no-build --configuration Release --urls=${{ secrets.LOCALHOST }} & sleep 5
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Cache Python dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-python-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-python-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install httpx pytest coverage
- name: Run integration tests V1
run: pytest "C#apiV1/Tests"
- name: Run integration tests V2
run: coverage run -m pytest "C#api/Tests"
- name: Generate code coverage report
id: coverage
run: |
# Generate the coverage report in multiple formats
coverage xml -o coverage.xml
coverage report > coverage-summary.txt
echo "Debug: Showing coverage-summary.txt content"
cat coverage-summary.txt
# Extract and store the coverage percentage
COVERAGE=$(coverage report | grep TOTAL | awk '{print $NF}')
echo "Debug: Coverage percentage is $COVERAGE"
echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT
# Store the full coverage report for later use
coverage report --format=markdown > coverage-report.md
# Debug: Show what files were created
ls -la
- name: Parse coverage by file
id: parse-coverage-file
run: |
echo "Debug: Starting coverage parsing"
python -c "
import os
print('Debug: Reading coverage-summary.txt')
with open('coverage-summary.txt', 'r') as f:
lines = f.readlines()
summary = []
for line in lines:
parts = line.split()
if len(parts) >= 4:
filename = parts[0]
coverage = parts[-1]
summary.append(f'{filename}: {coverage}')
print('Debug: Writing parsed-coverage-summary.txt')
with open('parsed-coverage-summary.txt', 'w') as report:
report.write('\n'.join(summary))
print('Debug: Coverage parsing complete')
"
- name: Upload Coverage Reports
uses: actions/upload-artifact@v4
with:
name: coverage-data
path: |
coverage-summary.txt
parsed-coverage-summary.txt
coverage.xml
coveragereport/**
retention-days: 1
- name: Cache Coverage Reports
uses: actions/cache@v3
with:
path: coverage/
key: ${{ runner.os }}-coverage-${{ github.run_id }}
- name: Set test Completion time
id: test-time
run: |
echo "time=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
release:
runs-on: self-hosted
if: github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main'
needs: [build, test]
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Git
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
- name: Generate release notes
run: |
git fetch --all --tags
# Get the date 2 weeks ago in ISO 8601 format
TWO_WEEKS_AGO=$(date -d '2 weeks ago' '+%Y-%m-%d' || date -v '-2w' '+%Y-%m-%d')
echo "Debug: Date 2 weeks ago is $TWO_WEEKS_AGO"
echo "# Release Notes" > release_notes.md
echo "## Branches merged into Development in the last 2 weeks:" >> release_notes.md
# Get merged branches in the last 2 weeks
MERGED_BRANCHES=$(git log --since="$TWO_WEEKS_AGO" --merges --pretty=format:"%s%n%b" origin/Development |
grep -E "Merge (branch|pull request)|into 'Development'" |
sed -E "s/Merge (branch|pull request) //g; s/ into Development//g; s/from //g; s/'//g; s/\"//g" |
sort -u)
echo "Merged branches: $MERGED_BRANCHES"
if [ -z "$MERGED_BRANCHES" ]; then
echo "No branches merged in the last 2 weeks." >> release_notes.md
else
echo "$MERGED_BRANCHES" | sed 's/^/- /' >> release_notes.md
fi
# Display the contents of the release notes
cat release_notes.md
- name: Upload release notes
uses: actions/upload-artifact@v4
with:
name: release-notes
path: release_notes.md
retention-days: 14
notify:
needs: [build, test]
runs-on: ubuntu-latest
steps:
- name: Download coverage data
uses: actions/download-artifact@v4
with:
name: coverage-data
path: ./coverage
- name: Debug coverage data
run: |
echo "Debug: Listing coverage directory contents"
ls -la ./coverage
echo "Debug: Content of coverage-summary.txt:"
cat ./coverage/coverage-summary.txt || echo "File not found"
- name: Parse coverage data
id: parse-coverage
run: |
cd ./coverage
if [ -f parsed-coverage-summary.txt ]; then
echo "Debug: Reading parsed-coverage-summary.txt"
COVERAGE_SUMMARY=$(cat parsed-coverage-summary.txt)
TOTAL_LINE=$(grep "TOTAL" coverage-summary.txt || echo "TOTAL 0 0 0%")
COVERAGE=$(echo $TOTAL_LINE | awk '{print $NF}')
echo "Debug: Coverage is $COVERAGE"
echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
echo "coverage_summary<<EOF" >> $GITHUB_OUTPUT
echo "$COVERAGE_SUMMARY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "Error: parsed-coverage-summary.txt not found"
echo "coverage=0%" >> $GITHUB_OUTPUT
echo "coverage_summary=No coverage data available" >> $GITHUB_OUTPUT
fi
- name: Determine coverage status
id: coverage-status
run: |
COVERAGE=$(echo ${{ steps.parse-coverage.outputs.coverage }} | sed 's/%//')
echo "Debug: Checking coverage value: $COVERAGE"
if (( $(echo "$COVERAGE >= 90" | bc -l) )); then
echo "status=good" >> $GITHUB_OUTPUT
echo "emoji=✅" >> $GITHUB_OUTPUT
echo "gif=https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExdjhrcmJsMzA4YmtwODZiZm00aGpmMzd0ZHUzMm9heWQ2NGc2NWZneSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/GSCWqj4qvwSFGDiR2z/giphy.gif" >> $GITHUB_OUTPUT
else
echo "status=bad" >> $GITHUB_OUTPUT
echo "emoji=❌" >> $GITHUB_OUTPUT
echo "gif=https://media.giphy.com/media/l1J9EdzfOSgfyueLm/giphy.gif" >> $GITHUB_OUTPUT
fi
- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: |
:rocket: Project Update Notification :rocket:
The project **${{ github.repository }}** has been updated.
:hammer_and_wrench: **Build Job**
- Completed at: ${{ needs.build.outputs.BUILD_TIME }}
:test_tube: **Test Job**
- Completed at: ${{ needs.test.outputs.TEST_TIME }}
:bar_chart: **Coverage Report** ${{ steps.coverage-status.outputs.emoji }}
- Overall Coverage: ${{ steps.parse-coverage.outputs.coverage }}
:page_facing_up: **Detailed Coverage by File
\`\`\`
${{ steps.parse-coverage.outputs.coverage_summary }}
\`\`\`
${{ steps.coverage-status.outputs.gif }}
:link: [View Commit](https://github.com/${{ github.repository }}/commit/${{ github.sha }})
:octocat: [View Workflow Run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
Branch: ${{ github.ref_name }}
Event: ${{ github.event_name }}
close_pr_on_failure:
needs: [build, test]
runs-on: ubuntu-latest
if: failure() && github.event_name == 'pull_request'
permissions:
pull-requests: write
steps:
- name: Close Pull Request
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
state: 'closed'
})
- name: Comment on Pull Request
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'This pull request has been automatically closed due to workflow failure. Please fix the issues and open a new pull request.'
})