Skip to content

Improvement for supporting images where the image version is not recognized #23

@buisz

Description

@buisz

Hi,

Today I discovered that using this image:

    "visStudio_2022_Pro_win11-m365-gen2": {
        "publisher": "microsoftvisualstudio",
        "offer": "visualstudioplustools",
        "sku": "vs-2022-pro-general-win11-m365-gen2",
        "version": "latest"
    }

Results in a date format not recognized by the Get-SHRLatestImageVersion.ps1. This is because the RegEx expects a year format of 24 instead of 2024. But the Image Version provided above results in 2024, resulting in an error when running the Function App.

So I changed this code:

if ($azImageVersion -match "\d+\.\d+\.(?<Year>\d{2})(?<Month>\d{2})(?<Day>\d{2})") {
    $azImageDate = Get-Date -Date ("20{0}-{1}-{2}" -f $Matches.Year, $Matches.Month, $Matches.Day)
    Write-PSFMessage -Level Host -Message "Image date is {0}" -StringValues $azImageDate
}
else {
    throw "Image version does not match expected format. Could not extract image date."
}

With this code:

if ($azImageVersion -match "^(?<Year>\d{2}|\d{4})\.(?<Month>\d{2})\.(?<Day>\d{2})$") {
    if ($Matches.Year.Length -eq 2) {
        $year = (Get-Date -Format "yyyy").Substring(0,2) + $Matches.Year
    } else {
        $year = $Matches.Year
    }
    $azImageDate = Get-Date -Date ("{0}-{1}-{2}" -f $year, $Matches.Month, $Matches.Day)
    Write-PSFMessage -Level Host -Message "Image date is {0}" -StringValues $azImageDate
} else {
    throw "Image version does not match expected format. Could not extract image date."
}

Perhaps you can use it in this project or provide me with feedback to even solve this in a better way?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions