Skip to content

Commit f4fcdff

Browse files
(GH-538) Move DscRepoSchema into dsc-lib-jsonschema
Prior to this change, types in `dsc-lib` depended on the`DscRepoSchema` trait defined in the same crate for generating the set of recognized schema URIs and validating them. This change migrates this JSON Schema specific code into the `dsc-lib-jsonschema` crate for better organization and reuse, since this is actually required for any schema published from the DSC repository, even if those crates don't depend on `dsc-lib`. This migration also takes advantage of some improvements in code organization for compilation and testing, migrating the separate related types, like `SchemaForm` and `SchemaUriPrefix`, into their own private modules with the parent module re-exporting those types. Finally, this migration also incorporates a build script, which checks the git tags for the project to generate the variants for the `RecognizedSchemaVersion` enum. Prior to this implementation, the developers were required to manually update the enum definition prior to every release. This change does _not_ update any other crates to use the new implementation. A separate, future change will modify the other crates.
1 parent 988cef2 commit f4fcdff

File tree

15 files changed

+1232
-1
lines changed

15 files changed

+1232
-1
lines changed

Cargo.lock

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
doc-valid-idents = ["IntelliSense", ".."]
1+
doc-valid-idents = ["IntelliSense", "PowerShell", ".."]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"latestMajor": "V3",
3+
"latestMinor": "V3_1",
4+
"latestPatch": "V3_1_2",
5+
"all": [
6+
"V3",
7+
"V3_1_2",
8+
"V3_1_1",
9+
"V3_1_0",
10+
"V3_1",
11+
"V3_0_2",
12+
"V3_0_1",
13+
"V3_0_0",
14+
"V3_0"
15+
]
16+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
<#
5+
.SYNOPSIS
6+
Generate the version info for the DSC project.
7+
8+
.DESCRIPTION
9+
This script inspects the git tags for the project and uses them to construct data representing
10+
those versions, saving it to `.versions.json` in the same directory as this script.
11+
12+
The data file contains every non-prerelease version tag as well as the latest major, minor, and
13+
patch version releases.
14+
15+
The versions are saved as:
16+
17+
- `V<Major>`, like `V3`, for every major version number.
18+
- `V<Major>_<Minor>`, like `V3_1`, for every minor version number.
19+
- `V<Major>_<Minor>_<Patch>`, like `V3_1_0`, for every non-prerelease version number.
20+
21+
This data is used by `build.rs` to generate the contents for the `RecognizedSchemaVersion`
22+
enum type definition and trait implementations.
23+
#>
24+
25+
[CmdletBinding()]
26+
param()
27+
28+
begin {
29+
function Get-DscProjectTagVersion {
30+
[cmdletbinding()]
31+
[OutputType([semver])]
32+
param()
33+
34+
process {
35+
$null = git fetch --all --tags
36+
git tag -l
37+
| Where-Object -FilterScript {$_ -match '^v\d+(\.\d+){2}$' }
38+
| ForEach-Object -Process { [semver]($_.Substring(1)) }
39+
}
40+
}
41+
42+
function Export-DscProjectTagVersion {
43+
[cmdletbinding()]
44+
param()
45+
46+
process {
47+
$publishedVersions = Get-DscProjectTagVersion
48+
| Sort-Object -Descending
49+
50+
[System.Collections.Generic.HashSet[string]]$majorVersions = @()
51+
[System.Collections.Generic.HashSet[string]]$minorVersions = @()
52+
[System.Collections.Generic.HashSet[string]]$patchVersions = @()
53+
54+
foreach ($version in $publishedVersions) {
55+
$null = $majorVersions.Add("V$($version.Major)")
56+
$null = $minorVersions.Add("V$($version.Major)_$($version.Minor)")
57+
$null = $patchVersions.Add("V$($version.Major)_$($version.Minor)_$($version.Patch)")
58+
}
59+
60+
$allVersions = @($majorVersions | Sort-Object -Descending) +
61+
@($minorVersions + $patchVersions | Sort-Object -Descending)
62+
63+
$data = [ordered]@{
64+
latestMajor = $majorVersions | Sort-Object -Descending | Select-Object -First 1
65+
latestMinor = $minorVersions | Sort-Object -Descending | Select-Object -First 1
66+
latestPatch = $patchVersions | Sort-Object -Descending | Select-Object -First 1
67+
all = $allVersions
68+
}
69+
70+
$dataJson = $data
71+
| ConvertTo-Json
72+
| ForEach-Object -Process { $_ -replace "`r`n", "`n"}
73+
74+
$dataPath = Join-Path -Path $PSScriptRoot -ChildPath '.versions.json'
75+
$dataContent = Get-Content -Raw -Path $dataPath
76+
77+
if ($dataJson.Trim() -ne $dataContent.Trim()) {
78+
$dataJson | Set-Content -Path $PSScriptRoot/.versions.json
79+
}
80+
81+
$dataJson
82+
}
83+
}
84+
}
85+
86+
process {
87+
Export-DscProjectTagVersion
88+
}

lib/dsc-lib-jsonschema/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rust-i18n = { workspace = true }
1313
schemars = { workspace = true }
1414
serde = { workspace = true }
1515
serde_json = { workspace = true }
16+
thiserror = { workspace = true }
1617
tracing = { workspace = true }
1718
url = { workspace = true }
1819
urlencoding = { workspace = true }
@@ -21,5 +22,9 @@ urlencoding = { workspace = true }
2122
# Helps review complex comparisons, like schemas
2223
pretty_assertions = { workspace = true }
2324

25+
[build-dependencies]
26+
serde = { workspace = true }
27+
serde_json = { workspace = true }
28+
2429
[lints.clippy]
2530
pedantic = { level = "deny" }

0 commit comments

Comments
 (0)