Maintaining the Currency of Recently Added and Updated Samples#1727
Conversation
|
@marcelwgn @niels9001 Could you please provide a quick review of this? |
|
Thanks for the contribution @Zakariathr22, this is fantastic! Instead of setting |
|
@karkarl
I've set the scripts codes in the PR. Feel free to go ahead with it if you think it would improve things (as I may not be available in these few days 😊) Thanks again for your feedback! |
|
/azp run |
1 similar comment
|
/azp run |
|
Thank you for this amazing contribution! If you are up for it, I would love to have the script included in the repo as @karkarl mentioned. Additionally, I think it would be good to have the scripts get the last tag and filters through the commits for "recently updated" that way. Again thank you for all your help! |
…dedSamples.ps1 and Get-LatestUpdatedSamples.ps1 - Created a new "Tools" folder to organize utility scripts. - Moved two PowerShell scripts into the "Tools" folder: 1. "Get-LatestAddedSamples.ps1" - Script for listing and sorting files based on their first commit date. 2. "Get-LatestUpdatedSamples.ps1" - Script for listing and sorting modified files based on their last commit date. These scripts help track file changes and updates based on commit history.
Done! |
|
/azp run |
marcelwgn
left a comment
There was a problem hiding this comment.
Thank you for adding the scripts, I think it would be good to add some documentation on what they do. Maybe a readme.md inside the tools? Also, I think I would put the tools folder at the root of the repository
…ccessing ControlPages
… to Tools folder documentation
|
/azp run |
|
Hey @marcelwgn, Thank you for the adjustments and suggestions, I’m glad the PR was merged. However, it seems there’s a small issue with the new code as it isn’t displaying results. Could we revert the last changes for now while we look into it? |
|
Hmm thats odd, both scripts works fine on my machine. From which folder did you run the scripts? And can you see if this issue also persists when running using Powershell 7? |
|
@marcelwgn I had updated the scripts: # Define the folder containing the WinUIGallery relative to the script location
$WinUIGalleryFolder = Join-Path -Path $PSScriptRoot -ChildPath "..\WinUIGallery"
# Change directory to the WinUIGallery folder
Set-Location -Path $WinUIGalleryFolder
# Define the folder containing the control pages
$currentFolder = "ControlPages"
# Retrieve the list of files in the folder with their details
$filesWithDetails = git ls-tree -r HEAD --name-only $currentFolder | ForEach-Object {
$file = $_ # Current file path from the git tree
# Check if the file is directly under the $currentFolder and not in subdirectories
if ($file -match "^$currentFolder/[^/]+$") {
# Get the date of the first commit where the file was added (diff-filter A means "added")
$firstAddCommit = git log --diff-filter=A --reverse --format="%ai" -- $file | Select-Object -First 1
# If the file has an add commit (i.e., it's not a new file)
if ($firstAddCommit) {
# Create a custom object with file name and its first added commit date
[PSCustomObject]@{
File = $file.Substring($currentFolder.Length + 1) # Remove the folder path to get the file name
FirstAddCommitDate = $firstAddCommit # Date of the first commit where the file was added
}
}
}
}
# Sort the files by their first add commit date in descending order (most recent first)
$sortedFiles = $filesWithDetails | Sort-Object FirstAddCommitDate -Descending
# Create a hashtable to cache processed file base names to avoid duplicates
$cachedBaseNames = @{ }
# Initialize the output string for the latest added samples
$LatestAddeddSamples = "Latest Added Samples:`n"
# Process the sorted files
$sortedFiles | ForEach-Object {
# Remove file extensions and standardize the file name
$fileName = $_.File -replace '\.xaml\.cs$', '' -replace '\.xaml$', ''
$fileName = $fileName -replace 'Page$', ''
$date = $_.FirstAddCommitDate
# Add the file to the output if it hasn't been cached yet (to avoid duplicates)
if (-not $cachedBaseNames.Contains($fileName)) {
$cachedBaseNames[$fileName] = $true # Mark the file name as cached
$LatestAddeddSamples += $fileName + " (" + $date + ")`n" # Append the file name to the output list
}
}
# Output the list of the latest added samples
Write-Output $LatestAddeddSamples
# Wait for the user to press Enter before closing the PowerShell window
Read-Host -Prompt "Press Enter to exit"# Define the folder containing the WinUIGallery relative to the script location
$WinUIGalleryFolder = Join-Path -Path $PSScriptRoot -ChildPath "..\WinUIGallery"
# Change directory to the WinUIGallery folder
Set-Location -Path $WinUIGalleryFolder
# Define the folder containing the control pages
$currentFolder = "ControlPages"
# Retrieve the list of files in the folder with their details
$filesWithDetails = git ls-tree -r HEAD --name-only $currentFolder | ForEach-Object {
$file = $_ # Current file path from the git tree
# Check if the file is directly under the $currentFolder and not in subdirectories
if ($file -match "^$currentFolder/[^/]+$") {
# Get the last commit date for the file
$lastCommitDate = git log -1 --format="%ai" -- $file
# Get the commit status for the file (checks if it was modified in the last commit)
$commitStatus = git log -1 --name-status -- $file | Select-String -Pattern "^M" | ForEach-Object { $_.Line.Split()[0] }
# If the file was modified ("M"), create a custom object with file details
if ($commitStatus -eq "M") {
[PSCustomObject]@{
File = $file.Substring($currentFolder.Length + 1) # Trim the folder path to get the file name
LastCommitDate = $lastCommitDate # Last commit date for the file
}
}
}
}
# Sort the files by the last commit date in descending order
$sortedFiles = $filesWithDetails | Sort-Object LastCommitDate -Descending
# Create a hashtable to cache processed file base names to avoid duplicates
$cachedBaseNames = @{ }
# Initialize the output string for the latest updated samples
$LatestUpdatedSamples = "Latest Updated Samples:`n"
# Process the sorted files
$sortedFiles | ForEach-Object {
# Remove file extensions and standardize the file name
$fileName = $_.File -replace '\.xaml\.cs$', '' -replace '\.xaml$', ''
$fileName = $fileName -replace 'Page$', ''
$date = $_.LastCommitDate
# Add the file to the output if it hasn't been cached yet
if (-not $cachedBaseNames.Contains($fileName)) {
$cachedBaseNames[$fileName] = $true # Mark the file name as cached
$LatestUpdatedSamples += $fileName + " (" + $date + ")`n" # Append the file name to the output
}
}
# Output the list of latest updated samples
Write-Output $LatestUpdatedSamples
# Wait for the user to press Enter before closing the PowerShell window
Read-Host -Prompt "Press Enter to exit" |
|
Hmm I think without changing directory, you cant invoke git. It would be great if you could create a PR for this! Ideally, we would cd back to were the user was before we changed the directory |
PR #1731 addresses the issue. |
…1731) <!--- Provide a general summary of your changes in the Title above --> ## Description Resolving the issue referenced in #1727 ## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here. --> ## How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## Screenshots (if appropriate): ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change)


Description
This PR addresses the issue of outdated samples in the "Recently Added" and "Recently Updated" sections of the homepage, main change are:
Toolsfolder to organize utility scripts.Toolsfolder:Get-LatestAddedSamples.ps1- Script for listing and sorting files based on their first commit date.Get-LatestUpdatedSamples.ps1- Script for listing and sorting modified files based on their last commit date.ControlInfoData.jsonMotivation and Context
How Has This Been Tested?
Manually Tested
How Were the Samples Selected?
I hope this approach will be adopted and implemented with every new release.
For Latest Updated Samples:
The
Get-LatestUpdatedSamples.ps1script identifies and lists files in theControlPagesdirectory that have been modified, along with their last commit dates. It processes each file, retrieves the date of its last commit, and sorts them by commit date in descending order. The script outputs the names of these files, excluding their extensions and standardizing their names by removing specific suffixes.Based on the results of this script, the latest 15 updated samples are:
TreeView,ListView,TeachingTip,TitleBar,ScrollView,FilePicker,CompactSizing,ScratchPad,CaptureElementPreview,SplitView,NumberBox,TabView,MenuFlyout,XamlUICommand,AutoSuggestBox.For Latest Added Samples:
The
Get-LatestAddedSamples.ps1script identifies and lists files in theControlPagesdirectory that have been added to the repository, along with their first commit dates. It processes each file, retrieves the date of its initial commit, and compiles a list of these files sorted by their first commit date in descending order. The script outputs the names of these files, excluding their extensions and standardizing their names by removing specific suffixes.Based on the results of this script, the latest 10 added samples are:
Popup,ScratchPad,MapControl,SelectorBar,CaptureElementPreview,AnnotatedScrollBar,ItemsView,ScrollView,InfoBadge,Viewbox.Screenshots:
Home page

Scripts results
Types of changes