Skip to content

Commit 1fa3d71

Browse files
(MAINT) Enable generating/testing docs in CI
This change updates the build helpers module to enable separately generating documentation for Rust crates and testing the examples in that documentation. It also adds a new workflow job for generating and testing documentation separately from the rest of the build and test scripts. While these jobs failing won't prevent the continued unit/integration/acceptance tests, it will still fail the build. This should help ensure that any examples in our documentation remain valid. It _doesn't_ test to ensure that public APIs are documented, only that the documentation that exists is minimally valid.
1 parent 2d79dc2 commit 1fa3d71

File tree

3 files changed

+113
-12
lines changed

3 files changed

+113
-12
lines changed

.github/workflows/rust.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@ defaults:
1919
shell: pwsh
2020

2121
jobs:
22+
docs:
23+
strategy:
24+
matrix:
25+
platform: [ubuntu-latest, macos-latest, windows-latest]
26+
runs-on: ${{matrix.platform}}
27+
steps:
28+
- uses: actions/checkout@v5
29+
- name: Install prerequisites
30+
run: ./build.new.ps1 -SkipBuild -Clippy -Verbose
31+
- name: Generate documentation
32+
run: ./build.new.ps1 -RustDocs -Verbose
33+
- name: Test documentation
34+
run: |-
35+
$testParams = @{
36+
SkipBuild = $true
37+
RustDocs = $true
38+
Test = $true
39+
ExcludeRustTests = $true
40+
ExcludePesterTests = $true
41+
Verbose = $true
42+
}
43+
./build.new.ps1 @testParams
2244
linux-build:
2345
runs-on: ubuntu-latest
2446
steps:

build.helpers.psm1

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,14 +1229,62 @@ function Copy-BuildArtifact {
12291229
}
12301230
#endregion Build project functions
12311231

1232+
#region Documenting project functions
1233+
function Export-RustDocs {
1234+
[CmdletBinding()]
1235+
param(
1236+
[DscProjectDefinition[]]$Project,
1237+
[ValidateSet('current','aarch64-pc-windows-msvc','x86_64-pc-windows-msvc','aarch64-apple-darwin','x86_64-apple-darwin','aarch64-unknown-linux-gnu','aarch64-unknown-linux-musl','x86_64-unknown-linux-gnu','x86_64-unknown-linux-musl')]
1238+
$Architecture = 'current',
1239+
[switch]$Release,
1240+
[switch]$IncludeDependencies
1241+
)
1242+
1243+
begin {
1244+
$flags = @($Release ? '-r' : $null)
1245+
if ($Architecture -ne 'current') {
1246+
$flags += '--target'
1247+
$flags += $Architecture
1248+
} else {
1249+
$memberGroup = if ($IsLinux) {
1250+
'Linux'
1251+
} elseif ($IsMacOS) {
1252+
'macOS'
1253+
} elseif ($IsWindows) {
1254+
'Windows'
1255+
}
1256+
Set-DefaultWorkspaceMemberGroup -MemberGroup $memberGroup
1257+
}
1258+
if (-not $IncludeDependencies) {
1259+
$flags += '--no-deps'
1260+
}
1261+
}
1262+
1263+
process {
1264+
$members = Get-DefaultWorkspaceMemberGroup
1265+
Write-Verbose -Verbose "Exporting documentation for rust projects: [$members]"
1266+
cargo doc @flags
1267+
1268+
if ($null -ne $LASTEXITCODE -and $LASTEXITCODE -ne 0) {
1269+
Write-Error "Last exit code is $LASTEXITCODE, 'cargo doc' failed"
1270+
}
1271+
}
1272+
1273+
clean {
1274+
Reset-DefaultWorkspaceMemberGroup
1275+
}
1276+
}
1277+
#endregion Documenting project functions
1278+
12321279
#region Test project functions
12331280
function Test-RustProject {
12341281
[CmdletBinding()]
12351282
param(
12361283
[DscProjectDefinition[]]$Project,
12371284
[ValidateSet('current','aarch64-pc-windows-msvc','x86_64-pc-windows-msvc','aarch64-apple-darwin','x86_64-apple-darwin','aarch64-unknown-linux-gnu','aarch64-unknown-linux-musl','x86_64-unknown-linux-gnu','x86_64-unknown-linux-musl')]
12381285
$Architecture = 'current',
1239-
[switch]$Release
1286+
[switch]$Release,
1287+
[switch]$Docs
12401288
)
12411289

12421290
begin {
@@ -1254,11 +1302,18 @@ function Test-RustProject {
12541302
}
12551303
Set-DefaultWorkspaceMemberGroup -MemberGroup $memberGroup
12561304
}
1305+
if ($Docs) {
1306+
$flags += '--doc'
1307+
}
12571308
}
12581309

12591310
process {
12601311
$members = Get-DefaultWorkspaceMemberGroup
1261-
Write-Verbose -Verbose "Testing rust projects: [$members]"
1312+
if ($Docs) {
1313+
Write-Verbose -Verbose "Testing documentation for rust projects: [$members]"
1314+
} else {
1315+
Write-Verbose -Verbose "Testing rust projects: [$members]"
1316+
}
12621317
cargo test @flags
12631318

12641319
if ($null -ne $LASTEXITCODE -and $LASTEXITCODE -ne 0) {

build.new.ps1

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ param(
9797
[switch]$UseCFSAuth,
9898
[switch]$Clean,
9999
[switch]$CacheRustBuild,
100+
[switch]$RustDocs,
100101
[switch]$Quiet
101102
)
102103

@@ -221,18 +222,31 @@ process {
221222
if (!$SkipBuild) {
222223
$progressParams.Activity = 'Building the projects'
223224
Write-BuildProgress @progressParams
224-
$buildParams = @{
225-
Project = $BuildData.Projects
226-
Architecture = $Architecture
227-
Release = $Release
228-
Clean = $Clean
229-
}
230225
Write-BuildProgress @progressParams -Status 'Generating grammar bindings'
231226
Export-GrammarBinding -Project $BuildData.Projects @VerboseParam
232-
Write-BuildProgress @progressParams -Status 'Compiling Rust'
233-
Build-RustProject @buildParams -Audit:$Audit -Clippy:$Clippy @VerboseParam
234-
Write-BuildProgress @progressParams -Status "Copying build artifacts"
235-
Copy-BuildArtifact @buildParams -ExecutableFile $BuildData.PackageFiles.Executable @VerboseParam
227+
228+
if ($RustDocs) {
229+
$progressParams.Activity = 'Generating Rust documentation'
230+
Write-BuildProgress @progressParams
231+
232+
$docsParams = @{
233+
Project = $BuildData.Projects
234+
Architecture = $Architecture
235+
Release = $Release
236+
}
237+
Export-RustDocs @docsParams @VerboseParam
238+
} else {
239+
$buildParams = @{
240+
Project = $BuildData.Projects
241+
Architecture = $Architecture
242+
Release = $Release
243+
Clean = $Clean
244+
}
245+
Write-BuildProgress @progressParams -Status 'Compiling Rust'
246+
Build-RustProject @buildParams -Audit:$Audit -Clippy:$Clippy @VerboseParam
247+
Write-BuildProgress @progressParams -Status "Copying build artifacts"
248+
Copy-BuildArtifact @buildParams -ExecutableFile $BuildData.PackageFiles.Executable @VerboseParam
249+
}
236250
}
237251

238252
# Ensure PATH includes the output artifacts after building and before testing.
@@ -255,6 +269,16 @@ process {
255269
Write-BuildProgress @progressParams -Status "Testing Rust projects"
256270
Test-RustProject @rustTestParams @VerboseParam
257271
}
272+
if ($RustDocs) {
273+
$docTestParams = @{
274+
Project = $BuildData.Projects
275+
Architecture = $Architecture
276+
Release = $Release
277+
Docs = $true
278+
}
279+
Write-BuildProgress @progressParams -Status "Testing documentation for Rust projects"
280+
Test-RustProject @docTestParams @VerboseParam
281+
}
258282
if (-not $ExcludePesterTests) {
259283
$installParams = @{
260284
UsingADO = $usingADO

0 commit comments

Comments
 (0)