Skip to content

Commit b98d9c6

Browse files
committed
update workflow
1 parent 19637a0 commit b98d9c6

File tree

2 files changed

+184
-4
lines changed

2 files changed

+184
-4
lines changed

.github/workflows/build.yml

Lines changed: 120 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,103 @@
1-
name: Build & Publish Executables
1+
name: Build, Test & Publish
22

33
on:
44
push:
55
branches:
66
- master
7+
- main
78
tags:
89
- 'v*.*.*'
10+
pull_request:
11+
branches:
12+
- master
13+
- main
914
workflow_dispatch:
1015

1116
env:
1217
CONFIGURATION: Release
1318
PROJECT_PATH: src/PrintZPL.Host/PrintZPL.Host.csproj
19+
TEST_PROJECT_PATH: tests/PrintZPL.Tests/PrintZPL.Tests.csproj
1420
FRAMEWORK: net8.0
1521

1622
jobs:
23+
test:
24+
runs-on: ubuntu-latest
25+
name: Test & Code Quality
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Setup .NET 8 SDK
32+
uses: actions/setup-dotnet@v4
33+
with:
34+
dotnet-version: '8.0.x'
35+
36+
- name: Cache NuGet packages
37+
uses: actions/cache@v4
38+
with:
39+
path: ~/.nuget/packages
40+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
41+
restore-keys: ${{ runner.os }}-nuget-
42+
43+
- name: Restore dependencies
44+
run: dotnet restore
45+
46+
- name: Build solution
47+
run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore
48+
49+
- name: Run tests
50+
run: dotnet test --configuration ${{ env.CONFIGURATION }} --no-build --verbosity normal --collect:"XPlat Code Coverage"
51+
52+
- name: Upload test results
53+
uses: actions/upload-artifact@v4
54+
if: always()
55+
with:
56+
name: test-results
57+
path: |
58+
**/TestResults/**/*.xml
59+
**/TestResults/**/*.trx
60+
**/TestResults/**/*.coverage
61+
62+
- name: Generate code coverage report
63+
run: |
64+
dotnet tool install -g dotnet-reportgenerator-globaltool
65+
reportgenerator -reports:"**/coverage.cobertura.xml" -targetdir:"coverage" -reporttypes:Html
66+
if: always()
67+
68+
- name: Upload coverage reports
69+
uses: actions/upload-artifact@v4
70+
if: always()
71+
with:
72+
name: coverage-report
73+
path: coverage/
74+
75+
security:
76+
runs-on: ubuntu-latest
77+
name: Security & Vulnerability Check
78+
79+
steps:
80+
- name: Checkout repository
81+
uses: actions/checkout@v4
82+
83+
- name: Setup .NET 8 SDK
84+
uses: actions/setup-dotnet@v4
85+
with:
86+
dotnet-version: '8.0.x'
87+
88+
- name: Restore dependencies
89+
run: dotnet restore
90+
91+
- name: Check for vulnerable packages
92+
run: dotnet list package --vulnerable --include-transitive
93+
94+
- name: Check for deprecated packages
95+
run: dotnet list package --deprecated
96+
1797
publish:
1898
runs-on: ubuntu-latest
99+
needs: [test, security]
100+
if: success()
19101
strategy:
20102
fail-fast: false
21103
matrix:
@@ -26,9 +108,9 @@ jobs:
26108

27109
steps:
28110
- name: Checkout repository
29-
uses: actions/checkout@v3
111+
uses: actions/checkout@v4
30112

31-
- name: Setup .NET 6 SDK
113+
- name: Setup .NET 8 SDK
32114
uses: actions/setup-dotnet@v4
33115
with:
34116
dotnet-version: '8.0.x'
@@ -51,7 +133,18 @@ jobs:
51133
--self-contained true \
52134
/p:PublishSingleFile=true \
53135
/p:PublishTrimmed=true \
54-
/p:TrimMode=Link
136+
/p:TrimMode=Link \
137+
/p:EnableCompressionInSingleFile=true
138+
139+
- name: Test published executable (${{ matrix.runtime }})
140+
run: |
141+
PUBLISH_DIR="src/PrintZPL.Host/bin/${{ env.CONFIGURATION }}/${{ env.FRAMEWORK }}/${{ matrix.runtime }}/publish"
142+
if [[ "${{ matrix.runtime }}" == "win-x64" ]]; then
143+
echo "Skipping Windows executable test on Linux runner"
144+
else
145+
chmod +x "$PUBLISH_DIR/PrintZPL.Host"
146+
timeout 10s "$PUBLISH_DIR/PrintZPL.Host" --console || true
147+
fi
55148
56149
- name: Zip published output (${{ matrix.runtime }})
57150
run: |
@@ -65,3 +158,26 @@ jobs:
65158
with:
66159
name: PrintZPL-${{ matrix.runtime }}
67160
path: PrintZPL-${{ matrix.runtime }}.zip
161+
162+
release:
163+
runs-on: ubuntu-latest
164+
needs: publish
165+
if: startsWith(github.ref, 'refs/tags/v')
166+
167+
steps:
168+
- name: Download all artifacts
169+
uses: actions/download-artifact@v4
170+
with:
171+
pattern: PrintZPL-*
172+
merge-multiple: true
173+
174+
- name: Create GitHub Release
175+
uses: softprops/action-gh-release@v1
176+
with:
177+
files: |
178+
PrintZPL-*.zip
179+
generate_release_notes: true
180+
draft: false
181+
prerelease: false
182+
env:
183+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Test & Validation
2+
3+
on:
4+
pull_request:
5+
branches: [ master, main ]
6+
push:
7+
branches: [ master, main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup .NET 8
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: '8.0.x'
21+
22+
- name: Cache dependencies
23+
uses: actions/cache@v4
24+
with:
25+
path: ~/.nuget/packages
26+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
27+
restore-keys: ${{ runner.os }}-nuget-
28+
29+
- name: Restore dependencies
30+
run: dotnet restore
31+
32+
- name: Build
33+
run: dotnet build --configuration Release --no-restore
34+
35+
- name: Test
36+
run: dotnet test --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage" --logger trx
37+
38+
- name: Publish test results
39+
uses: dorny/test-reporter@v1
40+
if: always()
41+
with:
42+
name: .NET Tests
43+
path: '**/*.trx'
44+
reporter: dotnet-trx
45+
46+
- name: Code Coverage Report
47+
uses: irongut/[email protected]
48+
with:
49+
filename: '**/coverage.cobertura.xml'
50+
badge: true
51+
fail_below_min: true
52+
format: markdown
53+
hide_branch_rate: false
54+
hide_complexity: true
55+
indicators: true
56+
output: both
57+
thresholds: '60 80'
58+
59+
- name: Add Coverage PR Comment
60+
uses: marocchino/sticky-pull-request-comment@v2
61+
if: github.event_name == 'pull_request'
62+
with:
63+
recreate: true
64+
path: code-coverage-results.md

0 commit comments

Comments
 (0)