Skip to content

Commit 1f6adbb

Browse files
authored
Merge pull request #1203 from michaeltlombardi/maint/main/separate-testing
(MAINT) Separately generate and test documentation
2 parents ce56e6f + 1fa3d71 commit 1f6adbb

File tree

11 files changed

+162
-12
lines changed

11 files changed

+162
-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

grammars/tree-sitter-dscexpression/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ include = [
1818

1919
[lib]
2020
path = "bindings/rust/lib.rs"
21+
doctest = false
2122

2223
[dependencies]
2324
tree-sitter-rust = { workspace = true }

grammars/tree-sitter-ssh-server-config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
//! Provides helper functions for working with VS Code's extended JSON Schema keywords with
5+
//! [`schemars::Schema`] instances.
6+
//!
7+
//! The `get_keyword_as_*` functions simplify retrieving the value of a keyword for a given type.
8+
//! If the schema defines the keyword with the expected type, those functions return a reference to
9+
//! that value as the correct type. If the keyword doesn't exist or has the wrong value type, the
10+
//! functions return [`None`].
11+
//!
12+
//! The rest of the utility methods work with specific keywords, like `$id` and `$defs`.
13+
14+
use core::{clone::Clone, iter::Iterator, option::Option::None};
15+
use std::string::String;
16+
17+
use schemars::Schema;
18+
use serde_json::{Map, Number, Value};
19+
use url::{Position, Url};
20+
21+
type Array = Vec<Value>;
22+
type Object = Map<String, Value>;
23+
24+
pub trait VSCodeSchemaExtensions {
25+
fn has_markdown_description(&self) -> bool;
26+
}
27+
28+
impl VSCodeSchemaExtensions for Schema {
29+
fn has_markdown_description(&self) -> bool {
30+
self.get("markdownDescription").is_some()
31+
}
32+
}

lib/dsc-lib-osinfo/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name = "dsc-lib-osinfo"
33
version = "1.0.0"
44
edition = "2021"
55

6+
[lib]
7+
doctest = false
8+
69
[dependencies]
710
os_info = { workspace = true }
811
serde = { workspace = true }

lib/dsc-lib-pal/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ name = "dsc-lib-pal"
55
version = "0.1.0"
66
edition = "2021"
77

8+
[lib]
9+
doctest = false
10+
811
[build-dependencies]
912
cc = { workspace = true }

lib/dsc-lib-registry/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ available-locales = ["en-us"]
88
default-locale = "en-us"
99
load-path = "locales"
1010

11+
[lib]
12+
doctest = false
13+
1114
[dependencies]
1215
crossterm = { workspace = true }
1316
registry = { workspace = true }

lib/dsc-lib-security_context/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name = "dsc-lib-security_context"
33
version = "0.1.0"
44
edition = "2021"
55

6+
[lib]
7+
doctest = false
8+
69
[target.'cfg(target_os = "windows")'.dependencies]
710
is_elevated = { workspace = true }
811

0 commit comments

Comments
 (0)