1- name : Build & Publish Executables
1+ name : Build, Test & Publish
22
33on :
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
1116env :
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
1622jobs :
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 :
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 }}
0 commit comments