Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/dsc-lib-jsonschema/.clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
doc-valid-idents = ["IntelliSense", ".."]
doc-valid-idents = ["IntelliSense", "PowerShell", ".."]
16 changes: 16 additions & 0 deletions lib/dsc-lib-jsonschema/.versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"latestMajor": "V3",
"latestMinor": "V3_1",
"latestPatch": "V3_1_2",
"all": [
"V3",
"V3_1",
"V3_1_2",
"V3_1_1",
"V3_1_0",
"V3_0",
"V3_0_2",
"V3_0_1",
"V3_0_0"
]
}
144 changes: 144 additions & 0 deletions lib/dsc-lib-jsonschema/.versions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

<#
.SYNOPSIS
Generate the version info for the DSC project.

.DESCRIPTION
This script inspects the git tags for the project and uses them to construct data representing
those versions, saving it to `.versions.json` in the same directory as this script.

The data file contains every non-prerelease version tag as well as the latest major, minor, and
patch version releases.

The versions are saved as:

- `V<Major>`, like `V3`, for every major version number.
- `V<Major>_<Minor>`, like `V3_1`, for every minor version number.
- `V<Major>_<Minor>_<Patch>`, like `V3_1_0`, for every non-prerelease version number.

This data is used by `build.rs` to generate the contents for the `RecognizedSchemaVersion`
enum type definition and trait implementations.
#>

[CmdletBinding()]
param()

begin {
function Get-DscProjectTagVersion {
[cmdletbinding()]
[OutputType([semver])]
param()

process {
$null = git fetch --all --tags
git tag -l
| Where-Object -FilterScript {$_ -match '^v\d+(\.\d+){2}$' }
| ForEach-Object -Process { [semver]($_.Substring(1)) }
}
}

function ConvertTo-EnumName {
[CmdletBinding()]
[OutputType([string])]
param(
[Parameter(ValueFromPipeline)]
[semver[]]$Version,
[switch]$Major,
[switch]$Minor

)

process {
foreach ($v in $Version) {
if ($Major) {
'V{0}' -f $v.Major
} elseif ($Minor) {
'V{0}_{1}' -f $v.Major, $v.Minor
} else {
'V{0}_{1}_{2}' -f $v.Major, $v.Minor, $v.Patch
}
}
}
}

function Export-DscProjectTagVersion {
[cmdletbinding()]
param()

process {
$publishedVersions = Get-DscProjectTagVersion
| Sort-Object -Descending

[System.Collections.Generic.HashSet[semver]]$majorVersions = @()
[System.Collections.Generic.HashSet[semver]]$minorVersions = @()
[System.Collections.Generic.HashSet[semver]]$patchVersions = @()

foreach ($version in $publishedVersions) {
$null = $majorVersions.Add([semver]"$($version.Major)")
$null = $minorVersions.Add([semver]"$($version.Major).$($version.Minor)")
$null = $patchVersions.Add($version)
}

# Sort the versions with major version, then each child minor version and child patch versions.
[System.Collections.Generic.HashSet[string]]$allVersions = @()
foreach ($major in ($majorVersions | Sort-Object -Descending)) {
$null = $allVersions.Add(($major | ConvertTo-EnumName -Major))

$majorMinor = $minorVersions
| Where-Object { $_.Major -eq $major.Major }
| Sort-Object -Descending

foreach ($minor in $majorMinor) {
$null = $allVersions.Add(($minor | ConvertTo-EnumName -Minor))

$majorMinorPatch = $patchVersions
| Where-Object { $_.Major -eq $minor.Major -and $_.Minor -eq $minor.Minor }
| Sort-Object -Descending

foreach ($patch in $majorMinorPatch) {
$null = $allVersions.Add(($patch | ConvertTo-EnumName))
}
}
}

[string]$latestMajorVersion = $majorVersions
| Sort-Object -Descending
| Select-Object -First 1
| ConvertTo-EnumName -Major
[string]$latestMinorVersion = $minorVersions
| Sort-Object -Descending
| Select-Object -First 1
| ConvertTo-EnumName -Minor
[string]$latestPatchVersion = $patchVersions
| Sort-Object -Descending
| Select-Object -First 1
| ConvertTo-EnumName

$data = [ordered]@{
latestMajor = $latestMajorVersion
latestMinor = $latestMinorVersion
latestPatch = $latestPatchVersion
all = $allVersions
}

$dataJson = $data
| ConvertTo-Json
| ForEach-Object -Process { $_ -replace "`r`n", "`n"}

$dataPath = Join-Path -Path $PSScriptRoot -ChildPath '.versions.json'
$dataContent = Get-Content -Raw -Path $dataPath

if ($dataJson.Trim() -ne $dataContent.Trim()) {
$dataJson | Set-Content -Path $PSScriptRoot/.versions.json
}

$dataJson
}
}
}

process {
Export-DscProjectTagVersion
}
5 changes: 5 additions & 0 deletions lib/dsc-lib-jsonschema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rust-i18n = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
url = { workspace = true }
urlencoding = { workspace = true }
Expand All @@ -21,5 +22,9 @@ urlencoding = { workspace = true }
# Helps review complex comparisons, like schemas
pretty_assertions = { workspace = true }

[build-dependencies]
serde = { workspace = true }
serde_json = { workspace = true }

[lints.clippy]
pedantic = { level = "deny" }
Loading