Skip to content

Maintaining the Currency of Recently Added and Updated Samples#1727

Merged
marcelwgn merged 8 commits intomicrosoft:mainfrom
Zakariathr22:recently-added-&-updated-samples
Jan 28, 2025
Merged

Maintaining the Currency of Recently Added and Updated Samples#1727
marcelwgn merged 8 commits intomicrosoft:mainfrom
Zakariathr22:recently-added-&-updated-samples

Conversation

@Zakariathr22
Copy link
Contributor

@Zakariathr22 Zakariathr22 commented Jan 14, 2025

Description

This PR addresses the issue of outdated samples in the "Recently Added" and "Recently Updated" sections of the homepage, main change are:

  • 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.
  • Set the recently updated and added samples in ControlInfoData.json

Motivation and Context

  • It proposes a process for regularly verifying and updating these sections to reflect the latest changes made to the gallery.
  • By ensuring that only the most current and relevant samples are displayed, this update will improve user experience, highlight community contributions, and provide better visibility for recent additions and improvements.
  • Closes Keeping Recently Added and Updated Samples Up to Date #1726

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.ps1 script identifies and lists files in the ControlPages directory 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.ps1 script identifies and lists files in the ControlPages directory 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
image

Scripts results

  • First script
    image
  • Second script
    image

Types of changes

  • 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)

@Zakariathr22
Copy link
Contributor Author

@marcelwgn @niels9001 Could you please provide a quick review of this?

@karkarl
Copy link
Collaborator

karkarl commented Jan 15, 2025

Thanks for the contribution @Zakariathr22, this is fantastic!

Instead of setting IsUpdated to false, can you update the script to simply remove the entire line? Also if you can check in the script too under some ./tools/ directory, that'll be great!

@Zakariathr22
Copy link
Contributor Author

@karkarl
Sorry, I didn't mention that depending on the results of these two scripts I changed in the ControlInfoData.json file manually; they are just displaying the latest added and updated samples.

Also if you can check in the script too under some ./tools/ directory, that'll be great!

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!

@niels9001
Copy link
Collaborator

/azp run

1 similar comment
@marcelwgn
Copy link
Contributor

/azp run

@marcelwgn
Copy link
Contributor

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.
@Zakariathr22
Copy link
Contributor Author

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!

Done!

@niels9001 niels9001 self-requested a review January 25, 2025 09:18
@niels9001
Copy link
Collaborator

/azp run

Copy link
Contributor

@marcelwgn marcelwgn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@marcelwgn
Copy link
Contributor

/azp run

Copy link
Contributor

@marcelwgn marcelwgn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making these changes. Ive made some adjustments to the scripts and the readme, PR is ready to merge now :)

@marcelwgn marcelwgn merged commit 0783597 into microsoft:main Jan 28, 2025
1 check passed
@Zakariathr22 Zakariathr22 deleted the recently-added-&-updated-samples branch January 28, 2025 09:37
@Zakariathr22
Copy link
Contributor Author

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?

image

@marcelwgn
Copy link
Contributor

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?

@Zakariathr22
Copy link
Contributor Author

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?

I ran the script from both the Tools folder and the Visual Studio Terminal. Even with PowerShell 7, I’m still seeing the same result on my end.
image

@Zakariathr22
Copy link
Contributor Author

@marcelwgn I had updated the scripts:
If these scripts work on your machine the same way they do on mine, then it’s the best solution. I can go ahead and create a PR for it.

# 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"

@marcelwgn
Copy link
Contributor

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

@Zakariathr22
Copy link
Contributor Author

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.

marcelwgn pushed a commit that referenced this pull request Jan 29, 2025
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keeping Recently Added and Updated Samples Up to Date

4 participants