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

chore: improve auto PR comments when windows cached things change #5998

Merged
merged 18 commits into from
Mar 6, 2025
71 changes: 71 additions & 0 deletions .github/workflows/check-windows-packages-change.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Make windows components change PR review comment
on: pull_request

jobs:
compare-components-output:
name: Compare components.json and windows_settings.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
id: makeDiff
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

$diffFile = "../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 --unified=0 >> $diffFile
Write-Output '```' >> $diffFile

dir $diffFile
Get-Content $diffFile
}

- name: remove comment from PR
# Removing and then adding the comment means that the comment will always appear at the bottom of the PR.
uses: thollander/actions-comment-pull-request@v3
with:
mode: delete
comment-tag: "WINDOWS_VHD_CONTENT_DIFF"
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Add comment to PR
uses: thollander/actions-comment-pull-request@v3
if: ${{ hashFiles('diff.md') != '' }}
with:
file-path: "diff.md"
comment-tag: "WINDOWS_VHD_CONTENT_DIFF"
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
59 changes: 0 additions & 59 deletions .github/workflows/validate-windows-ut.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,62 +23,3 @@ 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}}
Loading