Skip to content

Commit 57e0317

Browse files
authored
Merge pull request #1066 from Gijsreyn/fix-metadata-version
Fix metadata returning semantic versioning
2 parents a339349 + 681cb24 commit 57e0317

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

dsc/src/subcommand.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, parame
319319
}
320320
};
321321

322+
configurator.context.dsc_version = Some(env!("CARGO_PKG_VERSION").to_string());
323+
322324
if let ConfigSubCommand::Set { what_if , .. } = subcommand {
323325
if *what_if {
324326
configurator.context.execution_type = ExecutionKind::WhatIf;

dsc/tests/dsc_version.tests.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
Describe 'tests for metadata versioning' {
5+
It 'returns the correct dsc semantic version in metadata' {
6+
$config_yaml = @"
7+
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
8+
resources:
9+
- name: Echo
10+
type: Microsoft.DSC.Debug/Echo
11+
properties:
12+
output: 'Hello, World!'
13+
"@
14+
$out = $config_yaml | dsc config get -f - | ConvertFrom-Json
15+
$version = $out.metadata.'Microsoft.DSC'.version -as [System.Management.Automation.SemanticVersion]
16+
$version | Should -Not -BeNullOrEmpty
17+
$dscVersion = (dsc --version).Split(" ")[1]
18+
$version | Should -Be $dscVersion
19+
}
20+
}

dsc_lib/src/configure/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct Context {
2121
pub restart_required: Option<Vec<RestartRequired>>,
2222
pub process_expressions: bool,
2323
pub processing_parameter_defaults: bool,
24+
pub dsc_version: Option<String>,
2425
}
2526

2627
impl Context {
@@ -41,6 +42,7 @@ impl Context {
4142
restart_required: None,
4243
process_expressions: true,
4344
processing_parameter_defaults: false,
45+
dsc_version: None,
4446
}
4547
}
4648
}

dsc_lib/src/configure/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,15 @@ impl Configurator {
800800

801801
fn get_result_metadata(&self, operation: Operation) -> Metadata {
802802
let end_datetime = chrono::Local::now();
803+
let version = self
804+
.context
805+
.dsc_version
806+
.clone()
807+
.unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string());
803808
Metadata {
804809
microsoft: Some(
805810
MicrosoftDscMetadata {
806-
version: Some(env!("CARGO_PKG_VERSION").to_string()),
811+
version: Some(version),
807812
operation: Some(operation),
808813
execution_type: Some(self.context.execution_type.clone()),
809814
start_datetime: Some(self.context.start_datetime.to_rfc3339()),

0 commit comments

Comments
 (0)