Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add a comment to the PR when there are any changes that would change what's cached on windows VHDs #5994

Merged
merged 44 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
359afaf
add lists
timmy-wright Mar 6, 2025
fe0ee7e
fix bug in script
timmy-wright Mar 6, 2025
e7a1f5f
add github pipeline
timmy-wright Mar 6, 2025
25515f7
import module
timmy-wright Mar 6, 2025
8f01c25
slashes
timmy-wright Mar 6, 2025
acab0a9
switch to pwsh
timmy-wright Mar 6, 2025
5a314f7
tweaks
timmy-wright Mar 6, 2025
c9ca145
tweaks
timmy-wright Mar 6, 2025
515ae18
script no exist in master
timmy-wright Mar 6, 2025
4e21cb9
fixes
timmy-wright Mar 6, 2025
ed8fff0
tweak
timmy-wright Mar 6, 2025
f195e19
use git diff
timmy-wright Mar 6, 2025
bd5eafb
set git config
timmy-wright Mar 6, 2025
06d1cfb
set git config
timmy-wright Mar 6, 2025
f067e70
set git config
timmy-wright Mar 6, 2025
fdd6aa1
add diff as comment
timmy-wright Mar 6, 2025
89da4da
cd
timmy-wright Mar 6, 2025
19912da
clean up cd
timmy-wright Mar 6, 2025
4ccbc40
echo diff
timmy-wright Mar 6, 2025
5b4b4ab
echo diff
timmy-wright Mar 6, 2025
4d44283
path
timmy-wright Mar 6, 2025
39c2f9d
fix directory
timmy-wright Mar 6, 2025
f24f41f
upload
timmy-wright Mar 6, 2025
78d2c30
file
timmy-wright Mar 6, 2025
f0e75eb
mkdir -p
timmy-wright Mar 6, 2025
15523c1
mkdir -p
timmy-wright Mar 6, 2025
6049b7f
md file
timmy-wright Mar 6, 2025
6a6cbd3
quotes
timmy-wright Mar 6, 2025
e9db2d2
space
timmy-wright Mar 6, 2025
166408e
have as list
timmy-wright Mar 6, 2025
b8108da
whitespace
timmy-wright Mar 6, 2025
c1d5abe
better test of sorting
timmy-wright Mar 6, 2025
0fe2e2c
add reg key to list
timmy-wright Mar 6, 2025
4da4caa
use right helpers file
timmy-wright Mar 6, 2025
1420d23
grant permissions
timmy-wright Mar 6, 2025
72a0891
echo diff content
timmy-wright Mar 6, 2025
e42d560
append
timmy-wright Mar 6, 2025
8929974
change components.json to see diff
timmy-wright Mar 6, 2025
35b0277
revert components.json
timmy-wright Mar 6, 2025
e8a5381
add comment for no diff
timmy-wright Mar 6, 2025
6b98cee
change components for testing
timmy-wright Mar 6, 2025
cc68a77
revert change components for testing
timmy-wright Mar 6, 2025
b134404
update text
timmy-wright Mar 6, 2025
61994ab
remove unnecessary steps
timmy-wright Mar 6, 2025
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
61 changes: 61 additions & 0 deletions .github/workflows/validate-windows-ut.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Perform a Pester test from the parts/windows/*.tests.ps1 file
shell: powershell
run: |
Expand All @@ -21,3 +23,62 @@ jobs:
run: |
Install-Module -Name powershell-yaml -Force
Invoke-Pester staging/cse/windows/*.tests.ps1 -Passthru

compare-components-output:
name: Compare components.json for each windows VHD
runs-on: windows-latest
permissions:
pull-requests: write
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
ref: master
path: master
fetch-depth: 1

- name: Check out repository code
uses: actions/checkout@v4
with:
path: pr
fetch-depth: 1

- name: Produce vhd files - master
shell: pwsh
run: |
cd pr
mkdir vhd_files

pwsh -c vhdbuilder/scripts/windows/generate_cached_stuff_list.ps1 vhd_files vhdbuilder/packer/windows/components_json_helpers.ps1 ../master/vhdbuilder/packer/windows/windows_settings.json ../master/parts/common/components.json

git add vhd_files
git config user.email "[email protected]"
git config user.name "Your Name"
git commit -m "versions of files from master"

pwsh -c vhdbuilder/scripts/windows/generate_cached_stuff_list.ps1 vhd_files vhdbuilder/packer/windows/components_json_helpers.ps1 vhdbuilder/packer/windows/windows_settings.json parts/common/components.json

mkdir -p ../.github/workflows
$diffFile = "../.github/workflows/diff.md"

git diff --quiet
if ( $LASTEXITCODE -eq "0" ) {
Write-Output "No changes to cached containers or packages on Windows VHDs" > $diffFile
} else {
Write-Output "Changes cached containers or packages on windows VHDs" > $diffFile
Write-Output "" >> $diffFile
Write-Output '```diff' >> $diffFile
git diff >> $diffFile
Write-Output '```' >> $diffFile
}

dir $diffFile
Get-Content $diffFile

- name: Add comment to PR
uses: NejcZdovc/comment-pr@v2
with:
file: "diff.md"
identifier: "WINDOWS_VHD_CONTENT_DIFF"
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
2 changes: 1 addition & 1 deletion parts/parts.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package parts provides the the embedded templates used in Linux and Windows systems.
// Package parts provides the embedded templates used in Linux and Windows systems.
package parts

import "embed"
Expand Down
25 changes: 25 additions & 0 deletions vhdbuilder/packer/windows/components_json_helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,29 @@ function GetDefenderUpdateInfoUrl {
)

return $windowsSettingsContent.WindowsDefenderInfo.DefenderUpdateInfoUrl
}

function GetAllCachedThings {
Param(
[Parameter(Mandatory = $true)][Object]
$componentsJsonContent,
[Parameter(Mandatory = $true)][Object]
$windowsSettingsContent
)

$items = GetComponentsFromComponentsJson $componentsJsonContent
$packages = GetPackagesFromComponentsJson $componentsJsonContent
$regKeys = GetRegKeysToApply $windowsSettingsContent

foreach ($packageName in $packages.keys) {
foreach ($package in $packages[$packageName]) {
$items += $packageName + ": " + $package
}
}

foreach ($regKey in $regKeys) {
$items += $regKey.Path + "\" + $regKey.Name + "=" + $regKey.Value
}

return ($items | Sort-Object)
}
107 changes: 105 additions & 2 deletions vhdbuilder/packer/windows/components_json_helpers.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,109 @@ Describe 'SafeReplaceString' {



Describe 'Tests of GetAllCachedThings ' {
BeforeEach {
$windowsSettingsTestString = '{
"WindowsBaseVersions": {
"2019": {
"base_image_sku": "2019-Datacenter-Core-smalldisk",
"windows_image_name": "windows-2019",
"base_image_version": "17763.6893.250210",
"patches_to_apply": [{"id": "patchid", "url": "patch_url"}]
},
"23H2-gen2": {
"base_image_sku": "2019-Datacenter-Core-smalldisk",
"windows_image_name": "windows-2019",
"base_image_version": "17763.6893.250210",
"patches_to_apply": [{"id": "patchid", "url": "patch_url"}]
}
},
"WindowsRegistryKeys": [
{
"Comment": "Enables DNS resolution of SMB shares for containerD: # https://github.com/kubernetes-sigs/windows-gmsa/issues/30#issuecomment-802240945",
"WindowsSkuMatch": "*",
"Path": "HKLM:\\SYSTEM\\CurrentControlSet\\Services\\hns\\State",
"Name": "EnableCompartmentNamespace",
"Value": "1",
"Type": "DWORD"
}
]
}'
$windowsSettings = echo $windowsSettingsTestString | ConvertFrom-Json

$componentsJsonTestString = '{
"ContainerImages": [
{
"downloadURL": "mcr.microsoft.com/container/with/seperate/win/and/linux/versions:*",
"amd64OnlyVersions": [],
"multiArchVersionsV2": [],
"windowsVersions": [
{
"renovateTag": "registry=https://mcr.microsoft.com, name=oss/kubernetes/pause",
"latestVersion": "win-version"
},{
"renovateTag": "registry=https://mcr.microsoft.com, name=oss/kubernetes/pause",
"latestVersion": "other-version"
}
]
}],
"Packages": [
{
"windowsDownloadLocation": "c:\\akse-cache\\",
"downloadLocation": null,
"downloadUris": {
"windows": {
"default": {
"versionsV2": [
{
"renovateTag": "<DO_NOT_UPDATE>",
"latestVersion": "0.0.50",
"previousLatestVersion": "0.0.51"
}
],
"downloadURL": "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v${version}.zip"
}
}
}
}
]}'
$componentsJson = echo $componentsJsonTestString | ConvertFrom-Json
}

it 'has a component in it' {
$windowsSku = "2019-containerd"

$allpackages = GetAllCachedThings $componentsJson $windowsSettings

$allpackages | Should -Contain "mcr.microsoft.com/container/with/seperate/win/and/linux/versions:win-version"
}

it 'has a package in it' {
$windowsSku = "2019-containerd"

$allpackages = GetAllCachedThings $componentsJson $windowsSettings

$allpackages | Should -Contain "c:\akse-cache\: https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v0.0.50.zip"
}

it 'has a reg key in it' {
$windowsSku = "2019-containerd"

$allpackages = GetAllCachedThings $componentsJson $windowsSettings

$allpackages | Should -Contain "HKLM:\SYSTEM\CurrentControlSet\Services\hns\State\EnableCompartmentNamespace=1"
}

it 'is sorted' {
$windowsSku = "2019-containerd"

$allpackages = GetAllCachedThings $componentsJson $windowsSettings

$allpackages | Should -Be ( $allpackages | Sort-Object )
}
}


Describe 'GetWindowsDefenderInfo' {
BeforeEach {
$testString = '{
Expand Down Expand Up @@ -560,7 +663,7 @@ Describe 'Gets The Versions' {
)
$componentsJson.ContainerImages[0].downloadURL = "mcr.microsoft.com/oss/kubernetes/autoscaler/`${CPU_ARCH}/addon-resizer:*"

$CPU_ARCH="x86"
$CPU_ARCH = "x86"
$components = GetComponentsFromComponentsJson $componentsJson

$components | Should -HaveCount 1
Expand All @@ -575,7 +678,7 @@ Describe 'Gets The Versions' {
)
$componentsJson.ContainerImages[0].downloadURL = "mcr.microsoft.com/oss/kubernetes/autoscaler/`${varvarvar}/addon-resizer:*"

$varvarvar="x86"
$varvarvar = "x86"
$components = GetComponentsFromComponentsJson $componentsJson

$components | Should -HaveCount 1
Expand Down
65 changes: 65 additions & 0 deletions vhdbuilder/scripts/windows/generate_cached_stuff_list.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

param(
[string]
$outputDirParam,
[string]
$helpersFileParam,
[string]
$windowsSettingsFileParam,
[string]
$componentsJsonFileParam
)

$HelpersFile = "vhdbuilder/packer/windows/components_json_helpers.ps1"
$WindowsSettingsFile = "vhdbuilder/packer/windows/windows_settings.json"
$ComponentsJsonFile = "parts/common/components.json"
$outputDir = "temp"

if (![string]::IsNullOrEmpty($outputDirParam))
{
Write-Output "Setting output dir to to to $outputDirParam"
$outputDir = $outputDirParam
} else {
Write-Output "using default output dir: $outputDir"
}

if (![string]::IsNullOrEmpty($helpersFileParam))
{
Write-Output "Setting helpers file to $helpersFileParam"
$HelpersFile = $helpersFileParam
} else {
Write-Output "using default helpers file: $HelpersFile"
}

if (![string]::IsNullOrEmpty($windowsSettingsFileParam))
{
Write-Output "Setting windows settings file to $windowsSettingsFileParam"
$WindowsSettingsFile = $windowsSettingsFileParam
} else {
Write-Output "using default windows settings: $WindowsSettingsFile"
}

if (![string]::IsNullOrEmpty($componentsJsonFileParam))
{
Write-Output "Setting components json file to to $componentsJsonFileParam"
$ComponentsJsonFile = $componentsJsonFileParam
} else {
Write-Output "using default components json: $ComponentsJsonFile"
}

. "$HelpersFile"

$componentsJson = Get-Content $ComponentsJsonFile | Out-String | ConvertFrom-Json
$windowsSettingsJson = Get-Content $WindowsSettingsFile | Out-String | ConvertFrom-Json
$BaseVersions = GetWindowsBaseVersions $windowsSettingsJson

foreach ($WindowsSku in $BaseVersions)
{
$cachedThings = GetAllCachedThings $componentsJson $windowsSettingsJson

$fileName = "${outputDir}/${WindowsSku}.txt"
Write-Output "Creating file $fileName"
Write-Output $WindowsSku > $fileName

echo $cachedThings | ConvertTo-Json | Write-Output >> $fileName
}
Loading