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
2 changes: 2 additions & 0 deletions dsc/src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, parame
}
};

configurator.context.dsc_version = Some(env!("CARGO_PKG_VERSION").to_string());

if let ConfigSubCommand::Set { what_if , .. } = subcommand {
if *what_if {
configurator.context.execution_type = ExecutionKind::WhatIf;
Expand Down
20 changes: 20 additions & 0 deletions dsc/tests/dsc_version.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

Describe 'tests for metadata versioning' {
It 'returns the correct dsc semantic version in metadata' {
$config_yaml = @"
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Echo
type: Microsoft.DSC.Debug/Echo
properties:
output: 'Hello, World!'
"@
$out = $config_yaml | dsc config get -f - | ConvertFrom-Json
$version = $out.metadata.'Microsoft.DSC'.version -as [System.Management.Automation.SemanticVersion]
$version | Should -Not -BeNullOrEmpty
$dscVersion = (dsc --version).Split(" ")[1]
$version | Should -Be $dscVersion
}
}
2 changes: 2 additions & 0 deletions dsc_lib/src/configure/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct Context {
pub restart_required: Option<Vec<RestartRequired>>,
pub process_expressions: bool,
pub processing_parameter_defaults: bool,
pub dsc_version: Option<String>,
}

impl Context {
Expand All @@ -41,6 +42,7 @@ impl Context {
restart_required: None,
process_expressions: true,
processing_parameter_defaults: false,
dsc_version: None,
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion dsc_lib/src/configure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,10 +800,15 @@ impl Configurator {

fn get_result_metadata(&self, operation: Operation) -> Metadata {
let end_datetime = chrono::Local::now();
let version = self
.context
.dsc_version
.clone()
.unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string());
Metadata {
microsoft: Some(
MicrosoftDscMetadata {
version: Some(env!("CARGO_PKG_VERSION").to_string()),
version: Some(version),
operation: Some(operation),
execution_type: Some(self.context.execution_type.clone()),
start_datetime: Some(self.context.start_datetime.to_rfc3339()),
Expand Down
Loading