Skip to content

Commit c2f516e

Browse files
committed
Update workflow
1 parent e598de0 commit c2f516e

File tree

8 files changed

+108
-525
lines changed

8 files changed

+108
-525
lines changed

.github/workflows/build.yml

Lines changed: 85 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build, Test & Publish
1+
name: Build & Publish
22

33
on:
44
push:
@@ -16,24 +16,21 @@ on:
1616
env:
1717
CONFIGURATION: Release
1818
PROJECT_PATH: src/PrintZPL.Host/PrintZPL.Host.csproj
19-
TEST_PROJECT_PATH: tests/PrintZPL.Tests/PrintZPL.Tests.csproj
2019
FRAMEWORK: net8.0
2120

2221
jobs:
23-
test:
22+
build:
2423
runs-on: ubuntu-latest
25-
name: Test & Code Quality
24+
name: Build & Validate
2625

2726
steps:
2827
- name: Checkout repository
2928
uses: actions/checkout@v4
3029

31-
- name: Setup .NET 8 & 9
30+
- name: Setup .NET 8
3231
uses: actions/setup-dotnet@v4
3332
with:
34-
dotnet-version: |
35-
8.0.x
36-
9.0.x
33+
dotnet-version: '8.0.x'
3734

3835
- name: Cache NuGet packages
3936
uses: actions/cache@v4
@@ -48,49 +45,96 @@ jobs:
4845
- name: Build solution
4946
run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore
5047

51-
- name: Run tests
52-
run: dotnet test --configuration ${{ env.CONFIGURATION }} --no-build --verbosity normal --collect:"XPlat Code Coverage"
48+
- name: Check for vulnerable packages
49+
run: dotnet list package --vulnerable --include-transitive
5350

54-
- name: Upload test results
55-
uses: actions/upload-artifact@v4
56-
if: always()
51+
- name: Check for deprecated packages
52+
run: dotnet list package --deprecated
53+
54+
publish:
55+
runs-on: ubuntu-latest
56+
needs: [build]
57+
if: success()
58+
strategy:
59+
fail-fast: false
60+
matrix:
61+
runtime:
62+
- win-x64
63+
- linux-x64
64+
- osx-x64
65+
66+
steps:
67+
- name: Checkout repository
68+
uses: actions/checkout@v4
69+
70+
- name: Setup .NET 8
71+
uses: actions/setup-dotnet@v4
72+
with:
73+
dotnet-version: '8.0.x'
74+
75+
- name: Cache NuGet packages
76+
uses: actions/cache@v4
5777
with:
58-
name: test-results
59-
path: |
60-
**/TestResults/**/*.xml
61-
**/TestResults/**/*.trx
62-
**/TestResults/**/*.coverage
78+
path: ~/.nuget/packages
79+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
80+
restore-keys: ${{ runner.os }}-nuget-
81+
82+
- name: Restore dependencies
83+
run: dotnet restore "${{ env.PROJECT_PATH }}"
84+
85+
- name: Publish single-file executable (${{ matrix.runtime }})
86+
run: |
87+
dotnet publish "${{ env.PROJECT_PATH }}" \
88+
-c ${{ env.CONFIGURATION }} \
89+
-r ${{ matrix.runtime }} \
90+
--self-contained true \
91+
/p:PublishSingleFile=true \
92+
/p:PublishTrimmed=true \
93+
/p:TrimMode=Link \
94+
/p:EnableCompressionInSingleFile=true
95+
96+
- name: Test published executable (${{ matrix.runtime }})
97+
run: |
98+
PUBLISH_DIR="src/PrintZPL.Host/bin/${{ env.CONFIGURATION }}/${{ env.FRAMEWORK }}/${{ matrix.runtime }}/publish"
99+
if [[ "${{ matrix.runtime }}" == "win-x64" ]]; then
100+
echo "Skipping Windows executable test on Linux runner"
101+
else
102+
chmod +x "$PUBLISH_DIR/PrintZPL.Host"
103+
timeout 10s "$PUBLISH_DIR/PrintZPL.Host" --console || true
104+
fi
63105
64-
- name: Generate code coverage report
106+
- name: Zip published output (${{ matrix.runtime }})
65107
run: |
66-
dotnet tool install -g dotnet-reportgenerator-globaltool
67-
reportgenerator -reports:"**/coverage.cobertura.xml" -targetdir:"coverage" -reporttypes:Html
68-
if: always()
108+
PUBLISH_DIR="src/PrintZPL.Host/bin/${{ env.CONFIGURATION }}/${{ env.FRAMEWORK }}/${{ matrix.runtime }}/publish"
109+
ZIP_NAME="PrintZPL-${{ matrix.runtime }}.zip"
110+
cd "$PUBLISH_DIR"
111+
zip -r "${{ github.workspace }}/$ZIP_NAME" .
69112
70-
- name: Upload coverage reports
113+
- name: Upload artifact for ${{ matrix.runtime }}
71114
uses: actions/upload-artifact@v4
72-
if: always()
73115
with:
74-
name: coverage-report
75-
path: coverage/
116+
name: PrintZPL-${{ matrix.runtime }}
117+
path: PrintZPL-${{ matrix.runtime }}.zip
76118

77-
security:
119+
release:
78120
runs-on: ubuntu-latest
79-
name: Security & Vulnerability Check
121+
needs: publish
122+
if: startsWith(github.ref, 'refs/tags/v')
80123

81124
steps:
82-
- name: Checkout repository
83-
uses: actions/checkout@v4
84-
85-
- name: Setup .NET 8 & 9
86-
uses: actions/setup-dotnet@v4
125+
- name: Download all artifacts
126+
uses: actions/download-artifact@v4
87127
with:
88-
dotnet-version: |
89-
8.0.x
90-
9.0.x
91-
92-
- name: Restore dependencies
93-
run: dotnet restore
128+
pattern: PrintZPL-*
129+
merge-multiple: true
94130

95-
- name: Check for vulnerable packages
96-
run: dotnet list package --vulner
131+
- name: Create GitHub Release
132+
uses: softprops/action-gh-release@v1
133+
with:
134+
files: |
135+
PrintZPL-*.zip
136+
generate_release_notes: true
137+
draft: false
138+
prerelease: false
139+
env:
140+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test & Validation
1+
name: Build & Validation
22

33
on:
44
pull_request:
@@ -7,19 +7,18 @@ on:
77
branches: [ master, main ]
88

99
jobs:
10-
test:
10+
build:
1111
runs-on: ubuntu-latest
12+
timeout-minutes: 5
1213

1314
steps:
1415
- name: Checkout code
1516
uses: actions/checkout@v4
1617

17-
- name: Setup .NET 8 & 9
18+
- name: Setup .NET 8
1819
uses: actions/setup-dotnet@v4
1920
with:
20-
dotnet-version: |
21-
8.0.x
22-
9.0.x
21+
dotnet-version: '8.0.x'
2322

2423
- name: Cache dependencies
2524
uses: actions/cache@v4
@@ -34,33 +33,8 @@ jobs:
3433
- name: Build
3534
run: dotnet build --configuration Release --no-restore
3635

37-
- name: Test
38-
run: dotnet test --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage" --logger trx
36+
- name: Check for vulnerable packages
37+
run: dotnet list package --vulnerable --include-transitive
3938

40-
- name: Publish test results
41-
uses: dorny/test-reporter@v1
42-
if: always()
43-
with:
44-
name: .NET Tests
45-
path: '**/*.trx'
46-
reporter: dotnet-trx
47-
48-
- name: Code Coverage Report
49-
uses: irongut/[email protected]
50-
with:
51-
filename: '**/coverage.cobertura.xml'
52-
badge: true
53-
fail_below_min: true
54-
format: markdown
55-
hide_branch_rate: false
56-
hide_complexity: true
57-
indicators: true
58-
output: both
59-
thresholds: '60 80'
60-
61-
- name: Add Coverage PR Comment
62-
uses: marocchino/sticky-pull-request-comment@v2
63-
if: github.event_name == 'pull_request'
64-
with:
65-
recreate: true
66-
path: code-coverage-results.md
39+
- name: Check for deprecated packages
40+
run: dotnet list package --deprecated

PrintZPL.sln

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrintZPL.Host", "src\PrintZ
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrintZPL.Core", "src\PrintZPL.Core\PrintZPL.Core.csproj", "{27D994E9-ADBE-4C6A-9E12-675DB9E25B4E}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrintZPL.Tests", "tests\PrintZPL.Tests\PrintZPL.Tests.csproj", "{F7B4B493-9944-5E38-80C0-89818CEF115A}"
11-
EndProject
1210
Global
1311
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1412
Debug|Any CPU = Debug|Any CPU
@@ -23,10 +21,6 @@ Global
2321
{27D994E9-ADBE-4C6A-9E12-675DB9E25B4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
2422
{27D994E9-ADBE-4C6A-9E12-675DB9E25B4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
2523
{27D994E9-ADBE-4C6A-9E12-675DB9E25B4E}.Release|Any CPU.Build.0 = Release|Any CPU
26-
{F7B4B493-9944-5E38-80C0-89818CEF115A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27-
{F7B4B493-9944-5E38-80C0-89818CEF115A}.Debug|Any CPU.Build.0 = Debug|Any CPU
28-
{F7B4B493-9944-5E38-80C0-89818CEF115A}.Release|Any CPU.ActiveCfg = Release|Any CPU
29-
{F7B4B493-9944-5E38-80C0-89818CEF115A}.Release|Any CPU.Build.0 = Release|Any CPU
3024
EndGlobalSection
3125
GlobalSection(SolutionProperties) = preSolution
3226
HideSolutionNode = FALSE

README.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
# PrintZPL
22

33
## Description
4-
PrintZPL is a lightweight web service to discover Zebra printers via mDNS and send ZPL templates over TCP using simple HTTP calls.
54

6-
## Installation
7-
8-
### Pre-reqs
5+
This service allows you to discover Zebra printers and send/print ZPL templates by using HTTP POST requests.
96

10-
- [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0)
7+
## Installation
118

129
### Download and run as service
1310

14-
- [PrintZPL-win-x64](https://github.com/Tim-Maes/PrintZPL/actions/runs/14935544402/artifacts/3096169978) for Windows
15-
- [PrintZPL-linux-x64](https://github.com/Tim-Maes/PrintZPL/actions/runs/14935544402/artifacts/3096169686) for Linux
16-
- [PrintZPL-osx-x65](https://github.com/Tim-Maes/PrintZPL/actions/runs/14935544402/artifacts/3096170002) for macOS
11+
- [PrintZPL-win-x64](https://github.com/Tim-Maes/PrintZPL/actions/runs/7247084396/artifacts/1121113118) for Windows
12+
- [PrintZPL-linux-x64](https://github.com/Tim-Maes/PrintZPL/actions/runs/7247084396/artifacts/1121113116) for Linux
13+
- [PrintZPL-osx-x65](https://github.com/Tim-Maes/PrintZPL/actions/runs/7247084396/artifacts/1121113117) for MaxOS
1714

1815
## The API
1916

@@ -46,7 +43,6 @@ Using these parameters you can send a ZPL template to a printer:
4643
"Port": "6101"
4744
}
4845
```
49-
5046
### Print ZPL Label with data
5147

5248
You can also send data parameters to process a template that has placeholders for data and specify a delimiter.
@@ -66,13 +62,12 @@ For example, if you use the `$` delimiter in your ZPL template, you can send the
6662
}
6763
```
6864

69-
`$Greeting]$` and `$Name$` will be replaced by `Hello` and `World` respectively.
65+
`$Greeting$` and `$Name$` will be replaced by `Hello` and `World` respectively.
7066

7167
### Print ZPL Labels in batch
7268

7369
Url: `http://localhost:9001/batch-print/from-zpl`
7470
You can send a batch of ZPL templates to a printer by using the following request:
75-
7671
```json
7772
{
7873
"PrintRequests":
@@ -106,12 +101,15 @@ You can send a batch of ZPL templates to a printer by using the following reques
106101
### Building the project
107102

108103
### Prerequisites
109-
- .NET 6 SDK
104+
105+
- .NET 8 SDK
106+
110107
```bash
111-
dotnet build
108+
- dotnet build
112109
```
113110

114111
### Running the project
112+
115113
```bash
116114
dotnet run
117115
```
@@ -123,23 +121,20 @@ This will start a web server on port 9001.
123121
Run this command in the project folder
124122

125123
**Windows**
126-
127124
```bash
128125
dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true --self-contained true
129126
```
130-
131127
**Linux**
132128

133129
```bash
134130
dotnet publish -r linux-x64 -c Release /p:PublishSingleFile=true --self-contained true
135131
```
136-
137132
**MacOs**
138133

139134
```bash
140135
dotnet publish -r osx-x64 -c Release /p:PublishSingleFile=true --self-contained true
141136
```
142137

143-
You'll find the output .exe in `bin\Release\net6.0\win-x64\publish`
138+
You'll find the output .exe in `bin\Release\net8.0\win-x64\publish` (or the corresponding folder for your target platform).
144139

145140

src/PrintZPL.Core/Services/PrintService.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public async Task PrintZPL(string zplString, string printerIpAddress, int port,
3131
template = _templateService.PopulateZplTemplate(data, zplString, delimiter);
3232
}
3333

34-
// Ensure ZPL ends with proper line ending for better printer compatibility
3534
if (!template.EndsWith("\n"))
3635
{
3736
template += "\n";
@@ -41,9 +40,8 @@ public async Task PrintZPL(string zplString, string printerIpAddress, int port,
4140
{
4241
using var client = new TcpClient();
4342

44-
// Set connection timeout for better Linux compatibility
45-
client.ReceiveTimeout = 5000; // 5 seconds
46-
client.SendTimeout = 5000; // 5 seconds
43+
client.ReceiveTimeout = 5000;
44+
client.SendTimeout = 5000;
4745

4846
_logger.LogDebug("Connecting to printer at {IpAddress}:{Port}", printerIpAddress, port);
4947

@@ -53,7 +51,6 @@ public async Task PrintZPL(string zplString, string printerIpAddress, int port,
5351

5452
using var stream = client.GetStream();
5553

56-
// Use explicit UTF-8 encoding and disable auto-flush for better control
5754
using var writer = new StreamWriter(stream, Encoding.UTF8, bufferSize: 1024, leaveOpen: false)
5855
{
5956
AutoFlush = false
@@ -62,7 +59,6 @@ public async Task PrintZPL(string zplString, string printerIpAddress, int port,
6259
await writer.WriteAsync(template);
6360
await writer.FlushAsync();
6461

65-
// Ensure all data is sent over the network
6662
await stream.FlushAsync();
6763

6864
_logger.LogInformation("ZPL sent to printer successfully. Data length: {Length} characters", template.Length);

0 commit comments

Comments
 (0)