Repository navigation
213 lines (193 loc) · 11.4 KB
/
Copy pathci.yml
File metadata and controls
213 lines (193 loc) · 11.4 KB
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
# Continuous integration for PDFStream.NET.
#
# On every push and pull request this workflow builds the solution, runs the tests for both target
# frameworks (net8.0-windows and net10.0-windows), packs the NuGet package and publishes the test-print
# sample as one self-contained exe. The package and the sample are only kept as artifacts of the run:
# nothing is published to NuGet or anywhere else, and the workflow uses no secrets.
#
# Every command runs from the repository root, because global.json there switches "dotnet test" to
# Microsoft Testing Platform. That is why the test steps use --project and --framework (and never the
# old VSTest --filter option).
name: CI
on:
push:
pull_request:
permissions:
contents: read
# A newer push to the same branch, or a new commit on the same pull request, makes a run that is still going
# pointless, so it is cancelled. Runs for different refs never cancel each other.
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# No usage data leaves the build: the .NET CLI and Microsoft Testing Platform both honour these.
DOTNET_CLI_TELEMETRY_OPTOUT: '1'
TESTINGPLATFORM_TELEMETRY_OPTOUT: '1'
DOTNET_NOLOGO: '1'
jobs:
build-test-pack:
name: Build, test and pack (windows-latest)
runs-on: windows-latest
# A stuck print or test run (for example a printer dialog nobody can close) fails after 30 minutes instead of
# holding a runner for GitHub's default of six hours.
timeout-minutes: 30
defaults:
run:
shell: pwsh
steps:
- name: Check out the repository
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Install the .NET SDKs
uses: actions/setup-dotnet@v6
with:
# The .NET 10 SDK builds both targets and runs the tests through Microsoft Testing Platform;
# the .NET 8 install brings the runtime the net8.0-windows tests run on.
dotnet-version: |
8.0.x
10.0.x
- name: Show the .NET SDK in use
run: dotnet --version
# Reports, never fails. Eight facade tests and the eight real-print tests need the
# "Microsoft Print to PDF" printer and skip themselves (with a reason) when it is missing, so this
# step and the skipped-test report below make a silent skip visible.
- name: Report the printer the real-print tests need
continue-on-error: true
run: |
try {
$printer = Get-Printer -Name 'Microsoft Print to PDF' -ErrorAction SilentlyContinue
if ($printer) {
"Microsoft Print to PDF is installed on this runner (driver: $($printer.DriverName)). The tests that print to it will run."
} else {
"::warning title=Printer missing::Microsoft Print to PDF is not installed on this runner. The facade and real-print tests that need it will be skipped; see the skipped-test report."
}
$spooler = Get-Service -Name Spooler -ErrorAction SilentlyContinue
"Print Spooler service: $(if ($spooler) { $spooler.Status } else { 'not found' })"
} catch {
"::warning title=Printer check failed::Could not check the printers: $($_.Exception.Message)"
}
exit 0
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test (net8.0-windows)
run: >-
dotnet test --project tests/PDFStream.NET.Tests/PDFStream.NET.Tests.csproj
--framework net8.0-windows --configuration Release --no-build
--results-directory artifacts/test-results
--report-xunit-trx --report-xunit-trx-filename net8.0-windows.trx
- name: Test (net10.0-windows)
run: >-
dotnet test --project tests/PDFStream.NET.Tests/PDFStream.NET.Tests.csproj
--framework net10.0-windows --configuration Release --no-build
--results-directory artifacts/test-results
--report-xunit-trx --report-xunit-trx-filename net10.0-windows.trx
# Reports, never fails: counts the skipped tests in each framework's results and lists them with
# the reason each test gave, in the log and on the run's summary page.
- name: Report skipped tests
if: always()
continue-on-error: true
run: |
try {
$lines = @('### Test results', '')
$files = @(Get-ChildItem artifacts/test-results -Filter *.trx -ErrorAction SilentlyContinue)
if ($files.Count -eq 0) { $lines += 'No test result files were found.' }
foreach ($file in $files) {
[xml]$trx = Get-Content $file.FullName -Raw
$results = @($trx.TestRun.Results.UnitTestResult)
$passed = @($results | Where-Object { $_.outcome -eq 'Passed' }).Count
$failed = @($results | Where-Object { $_.outcome -eq 'Failed' }).Count
$skipped = @($results | Where-Object { $_.outcome -eq 'NotExecuted' })
$lines += "**$($file.BaseName)**: $($results.Count) tests, $passed passed, $failed failed, $($skipped.Count) skipped"
foreach ($test in $skipped) {
$reason = "$($test.Output.StdOut)".Trim()
$lines += "- skipped: $($test.testName)$(if ($reason) { " ($reason)" })"
}
if ($skipped.Count -gt 0) { "::warning title=Skipped tests::$($skipped.Count) tests were skipped on $($file.BaseName)." }
$lines += ''
}
$lines | ForEach-Object { $_ }
if ($env:GITHUB_STEP_SUMMARY) { $lines | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append -Encoding utf8 }
} catch {
"::warning title=Skipped-test report failed::$($_.Exception.Message)"
}
exit 0
- name: Upload the test results
if: always()
uses: actions/upload-artifact@v7
with:
name: test-results
path: artifacts/test-results
if-no-files-found: warn
- name: Pack the NuGet package
run: dotnet pack src/PDFStream.NET/PDFStream.NET.csproj --configuration Release --no-build --output artifacts/package
# Fails the run if the package lost its licence, notices, readme, metadata or PDFium dependency, or
# picked up a file type that has no business in it (keys, certificates, settings, scripts).
- name: Check the package contents
run: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
# The version being released: VersionPrefix plus VersionSuffix in Directory.Build.props. A version published
# on nuget.org is permanent, so the check pins it exactly. Change it together with that file when a new
# version is released.
$expectedVersion = '1.0.0-rc.1'
# The package id, the assembly and the namespace are all PDFStream.NET, so the file is
# PDFStream.NET.<version>.nupkg and its manifest PDFStream.NET.nuspec. Exactly one must exist.
$packages = @(Get-ChildItem artifacts/package -Filter 'PDFStream.NET.*.nupkg' | Where-Object { $_.Name -notlike '*.snupkg' })
if ($packages.Count -ne 1) { throw "Expected one PDFStream.NET.$expectedVersion.nupkg, found $($packages.Count): $($packages.Name -join ', ')" }
if ($packages[0].Name -cne "PDFStream.NET.$expectedVersion.nupkg") { throw "The package file is '$($packages[0].Name)', not PDFStream.NET.$expectedVersion.nupkg" }
$package = $packages[0]
$zip = [IO.Compression.ZipFile]::OpenRead($package.FullName)
try {
$entries = @($zip.Entries | ForEach-Object { $_.FullName })
$manifest = $zip.Entries | Where-Object { $_.FullName -ceq 'PDFStream.NET.nuspec' }
if (-not $manifest) { throw 'The package has no PDFStream.NET.nuspec.' }
$reader = [IO.StreamReader]::new($manifest.Open())
[xml]$nuspec = $reader.ReadToEnd()
$reader.Dispose()
} finally { $zip.Dispose() }
$problems = @()
foreach ($required in 'LICENSE', 'THIRD-PARTY-NOTICES.md', 'README.md', 'lib/net8.0-windows7.0/PDFStream.NET.dll', 'lib/net10.0-windows7.0/PDFStream.NET.dll') {
if ($entries -cnotcontains $required) { $problems += "missing file: $required" }
}
$metadata = $nuspec.package.metadata
if ($metadata.id -cne 'PDFStream.NET') { $problems += "the package id is '$($metadata.id)', not PDFStream.NET" }
if ($metadata.title -cne 'PDFStream.NET') { $problems += "the package title is '$($metadata.title)', not PDFStream.NET" }
if ($metadata.version -cne $expectedVersion) { $problems += "the package version is '$($metadata.version)', not $expectedVersion" }
if ($metadata.license.'#text' -ne 'MIT') { $problems += 'the licence expression is not MIT' }
if ($metadata.readme -ne 'README.md') { $problems += 'the package readme is not README.md' }
if ($metadata.authors -ne 'P4 Software') { $problems += 'the authors are not P4 Software' }
if ($metadata.repository.url -cne 'https://github.com/P4Software/PDFStream.NET') { $problems += 'the repository URL is missing or wrong' }
foreach ($group in @($metadata.dependencies.group)) {
$pdfium = @($group.dependency | Where-Object { $_.id -ceq 'bblanchon.PDFium.Win32' })
if ($pdfium.Count -ne 1) { $problems += "$($group.targetFramework) does not depend on bblanchon.PDFium.Win32 (pdfium.dll)" }
# The exact PDFium build that was tested (the nuspec writes it as "160.0.8165", which NuGet reads as "160.0.8165 or newer").
elseif ($pdfium[0].version -cne '160.0.8165') { $problems += "$($group.targetFramework) depends on bblanchon.PDFium.Win32 $($pdfium[0].version), not 160.0.8165" }
}
$unexpected = @($entries | Where-Object { $_ -match '\.(snk|pfx|p12|pem|key|cer|ps1|cmd|bat|json|config)$' })
if ($unexpected.Count -gt 0) { $problems += "unexpected files: $($unexpected -join ', ')" }
"Package: $($package.Name)"; $entries | Sort-Object | ForEach-Object { " $_" }
if ($problems.Count -gt 0) { $problems | ForEach-Object { "::error title=Package check::$_" }; exit 1 }
'The PDFStream.NET package has the licence, the third-party notices, the readme, the metadata and the PDFium dependency.'
- name: Upload the NuGet package
uses: actions/upload-artifact@v7
with:
name: PDFStream.NET-nuget-package
path: artifacts/package
if-no-files-found: error
# One exe that includes the .NET runtime and pdfium.dll, so a person can double-click it on a
# machine without .NET installed. Not trimmed: the settings reader relies on reflection.
- name: Publish the test-print sample (win-x64, self-contained, single file)
run: >-
dotnet publish samples/PDFStream.NET.TestPrint/PDFStream.NET.TestPrint.csproj
--framework net10.0-windows --configuration Release --runtime win-x64 --self-contained true
-p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:DebugType=embedded
-p:PublishDocumentationFiles=false
--output artifacts/testprint
- name: Upload the test-print sample
uses: actions/upload-artifact@v7
with:
name: PDFStream.NET.TestPrint-win-x64
path: artifacts/testprint
if-no-files-found: error