-
Notifications
You must be signed in to change notification settings - Fork 207
Enhance customALGoFiles feature #2273
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
Open
Ole Wunschmann (OleWunschmann)
wants to merge
58
commits into
microsoft:main
Choose a base branch
from
OleWunschmann:enhance-customALGoFiles-feature
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
0d9e05e
Enhance customALGoFiles feature (#3)
OleWunschmann 73f4ef3
fixed typo
OleWunschmann bb38962
fixed function description
OleWunschmann 50ad11c
Fixed tests for ps5 and string-prefix check for folder traversal
OleWunschmann 7aa8766
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann f7496cc
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann 11e2efc
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann b021013
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann 025747e
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann dd1771a
Merge remote-tracking branch 'origin/main' into enhance-customALGoFil…
OleWunschmann 2d24972
Merge remote-tracking branch 'origin/main' into enhance-customALGoFil…
OleWunschmann 5976abe
Merge remote-tracking branch 'origin/main' into enhance-customALGoFil…
OleWunschmann 7fa3522
Extended settings schema and documentation for "destinationName"
OleWunschmann a5c5fb1
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann 181080e
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann c23a8ae
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann afce6d7
Potential fix for pull request finding
OleWunschmann 00d1902
Fixed copilot review comments
OleWunschmann ee510bd
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann c8ded0d
Fix copilot review comments
OleWunschmann 409371e
Cleanup
OleWunschmann 84a656e
Cleanup
OleWunschmann 8682d62
Fix copilot review comments
OleWunschmann 051d08a
Remove support for fileToRemove
OleWunschmann 1a037b8
Merge remote-tracking branch 'origin/main' into enhance-customALGoFil…
OleWunschmann d412a75
Fixed copilot review comment
OleWunschmann 6376e16
Fixed issues
OleWunschmann 73e159c
Cleanup
OleWunschmann cf71143
Fixed boundary escape for destinationFolder and destinationName
OleWunschmann f94fe4e
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann 61c640d
Fixed boundary escape for destinationName and typos
OleWunschmann ea2688e
Fixed boundry escape for wildcards and for linux
OleWunschmann aab09ca
Merge branch 'main' into enhance-customALGoFiles-feature
aholstrup1 0747977
Merge branch 'main' into enhance-customALGoFiles-feature
aholstrup1 fb60e90
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann 14ca702
Fix path comparisons with OS specific casings
OleWunschmann fd18fd4
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann 95d9cf4
Resolve symlinks/junctions
OleWunschmann d8495f7
Merge remote-tracking branch 'origin/main' into enhance-customALGoFil…
OleWunschmann 684ae30
Fix copilot review comments
OleWunschmann 6b0714b
Fix copilot review comment
OleWunschmann b7e2cd8
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann 448f661
Merge branch 'main' into enhance-customALGoFiles-feature
mazhelez 2f41252
Merge branch 'main' into enhance-customALGoFiles-feature
mazhelez 46293f7
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann 5d945c0
fix dangling links
OleWunschmann b42c085
reworked symlink/junction handling
OleWunschmann cf8671f
reworked symlink/junction handling and tests
OleWunschmann d9759ed
more rework
OleWunschmann 65911f2
add tests for template settings snapshot
OleWunschmann d8e4b54
read settings without context, handle path issues, cleanup
OleWunschmann ff032bd
fixed issues with literal paths, symlinks/junctions and case-sensitivity
OleWunschmann a1a20dc
Fix typo in comment for clarity
OleWunschmann 0b9dc8c
fix review comments
OleWunschmann a23d1fb
Merge branch 'main' into enhance-customALGoFiles-feature
OleWunschmann 60a175c
Fix review comments
OleWunschmann f9f9eb1
Fix review comments
OleWunschmann c54f757
fix e2e test
OleWunschmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
484 changes: 435 additions & 49 deletions
484
Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| Param( | ||
| Param( | ||
| [Parameter(HelpMessage = "The GitHub actor running the action", Mandatory = $false)] | ||
| [string] $actor, | ||
| [Parameter(HelpMessage = "Base64 encoded GhTokenWorkflow secret", Mandatory = $false)] | ||
|
|
@@ -51,8 +51,9 @@ if ($token) { | |
| # if $update is set to N, CheckForUpdates will only check for updates and output a warning if there are updates available | ||
| # if $downloadLatest is set to true, CheckForUpdates will download the latest version of the template repository, else it will use the templateSha setting in the .github/AL-Go-Settings file | ||
|
|
||
| # Get Repo settings as a hashtable (do NOT read any specific project settings, nor any specific workflow, user or branch settings) | ||
| $repoSettings = ReadSettings -buildMode '' -project '' -workflowName '' -userName '' -branchName '' | ConvertTo-HashTable -recurse | ||
| # Get repo settings independent of the build, project, workflow, user, branch, and trigger running this update. | ||
| # Repository-scoped and unconditional settings still apply. | ||
| $repoSettings = ReadSettings -buildMode '' -project '' -workflowName '' -userName '' -branchName '' -trigger '' | ConvertTo-HashTable -recurse | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed by 0b9dc8c |
||
| $templateSha = $repoSettings.templateSha | ||
|
|
||
| # If templateUrl has changed, download latest version of the template repository (ignore templateSha) | ||
|
|
@@ -113,6 +114,12 @@ if (-not $isDirectALGo) { | |
|
|
||
| # Get the list of projects in the current repository | ||
| $baseFolder = $ENV:GITHUB_WORKSPACE | ||
|
|
||
| if ($originalTemplateFolder) { | ||
| # Use current custom template settings for this run without changing the workspace before comparison. | ||
| $repoSettings = ReadSettingsWithCurrentCustomTemplateRepoSettings -baseFolder $baseFolder -customTemplateFolder $templateFolder | ||
| } | ||
|
|
||
| $projects = @(GetProjectsFromRepository -baseFolder $baseFolder -projectsFromSettings $repoSettings.projects) | ||
|
|
||
| $filesToInclude, $filesToExclude = GetFilesToUpdate -settings $repoSettings -projects $projects -baseFolder $baseFolder -templateFolder $templateFolder -originalTemplateFolder $originalTemplateFolder | ||
|
|
@@ -133,6 +140,14 @@ if ($projects.Count -gt 1) { | |
| Write-Host "Calculated dependency depth to be $depth" | ||
| } | ||
|
|
||
| # Prepare the list of template folders to be used for verification | ||
| $templateFolders = @($templateFolder) | ||
| $customTemplateFolder = '' | ||
| if ($originalTemplateFolder) { | ||
| $templateFolders += $originalTemplateFolder | ||
| $customTemplateFolder = $templateFolder | ||
| } | ||
|
|
||
| # Loop through all folders in CheckFiles and check if there are any files that needs to be updated | ||
| foreach($fileToInclude in $filesToInclude) { | ||
| $type = $fileToInclude.type | ||
|
|
@@ -141,17 +156,37 @@ foreach($fileToInclude in $filesToInclude) { | |
| if(-not $originalSrcPath) { | ||
| $originalSrcPath = $srcPath | ||
| } | ||
| $hasDistinctOriginalSource = -not (GetPathStringComparer).Equals($originalSrcPath, $srcPath) | ||
|
|
||
| # Skip files that do not physically resolve to themselves within the template folders | ||
| if (-not (Test-PathPhysicallyEqual -Path $srcPath -AnchorPaths $templateFolders)) { | ||
| OutputWarning "Skipping update for source file '$srcPath': source does not physically resolve to itself within the template folder(s). This may indicate a symlink/junction redirect." | ||
| continue | ||
| } | ||
| if ($hasDistinctOriginalSource) { | ||
| # Skip files with original files that do not physically resolve to themselves within the template folders | ||
| if (-not (Test-PathPhysicallyEqual -Path $originalSrcPath -AnchorPaths $templateFolders)) { | ||
| OutputWarning "Skipping update for source file '$srcPath': original source '$originalSrcPath' does not physically resolve to itself within the template folder(s). This may indicate a symlink/junction redirect." | ||
| continue | ||
| } | ||
| } | ||
|
|
||
| $dstPath = $fileToInclude.destinationFullPath | ||
|
|
||
| $dstFileExists = Test-Path -Path $dstPath -PathType Leaf | ||
| # Skip files with destinations that do not physically resolve to themselves within the base folder | ||
| if (-not (Test-PathPhysicallyEqual -Path $dstPath -AnchorPaths @($baseFolder))) { | ||
| OutputWarning "Skipping update for source file '$srcPath': destination '$dstPath' does not physically resolve to itself. This may indicate a symlink/junction redirect." | ||
| continue | ||
| } | ||
|
|
||
| $dstFileExists = Test-Path -LiteralPath $dstPath -PathType Leaf | ||
|
|
||
| Write-Host "Processing file: $srcPath -> $dstPath (type: $type)" | ||
|
|
||
| switch ($type) { | ||
| "workflow" { | ||
| # For workflow files, we might need to modify the file based on the settings | ||
| $srcContent = GetWorkflowContentWithChangesFromSettings -srcFile $originalSrcPath -repoSettings $repoSettings -depth $depth | ||
| $srcContent = GetWorkflowContentWithChangesFromSettings -srcFile $originalSrcPath -repoSettings $repoSettings -depth $depth -customTemplateFolder $customTemplateFolder | ||
| # Replace static placeholders | ||
| $srcContent = $srcContent.Replace('{TEMPLATEURL}', $templateUrl) | ||
| } | ||
|
|
@@ -170,7 +205,7 @@ foreach($fileToInclude in $filesToInclude) { | |
| ReplaceOwnerRepoAndBranch -srcContent ([ref]$srcContent) -templateOwner $templateOwner -templateBranch $templateBranch | ||
| } | ||
|
|
||
| if ($type -eq 'workflow' -and $originalSrcPath -ne $srcPath) { | ||
| if ($type -eq 'workflow' -and $hasDistinctOriginalSource) { | ||
| # Apply customizations from custom template repository | ||
| Write-Host "Apply customizations from custom template repository, file: $srcPath" | ||
| [Yaml]::ApplyTemplateCustomizations([ref] $srcContent, $srcPath) | ||
|
|
@@ -204,8 +239,8 @@ foreach($fileToInclude in $filesToInclude) { | |
|
|
||
| Push-Location -Path $baseFolder | ||
| # Remove files that are in $filesToExclude and exist in the repository | ||
| $removeFiles = $filesToExclude | Where-Object { $_ -and (Test-Path -Path $_.destinationFullPath -PathType Leaf) } | ForEach-Object { | ||
| $relativePath = Resolve-Path -Path $_.destinationFullPath -Relative | ||
| $removeFiles = $filesToExclude | Where-Object { $_ -and (Test-Path -LiteralPath $_.destinationFullPath -PathType Leaf) } | ForEach-Object { | ||
| $relativePath = Resolve-Path -LiteralPath $_.destinationFullPath -Relative | ||
|
Copilot marked this conversation as resolved.
|
||
| Write-Host "File marked for removal: $relativePath" | ||
| $relativePath | ||
| } | ||
|
|
@@ -256,16 +291,24 @@ else { | |
|
|
||
| invoke-git status | ||
|
|
||
| $dstRoot = (Get-Location).Path | ||
|
|
||
| # Update the files | ||
| # Calculate the release notes, while updating | ||
| $releaseNotes = "" | ||
| $updateFiles | ForEach-Object { | ||
| # Skip files that do not physically resolve to themselves within the destination root folder | ||
| if (-not (Test-PathPhysicallyEqual -Path (Join-Path $dstRoot $_.DstFile) -AnchorPaths @($dstRoot))) { | ||
| OutputWarning "Skipping update of '$($_.DstFile)': destination does not physically resolve to itself. This may indicate a symlink/junction redirect." | ||
| return | ||
| } | ||
|
|
||
| # Create the destination folder if it doesn't exist | ||
| $path = [System.IO.Path]::GetDirectoryName($_.DstFile) | ||
| if ($path -and -not (Test-Path -path $path -PathType Container)) { | ||
| if ($path -and -not (Test-Path -LiteralPath $path -PathType Container)) { | ||
| New-Item -Path $path -ItemType Directory | Out-Null | ||
| } | ||
| if (([System.IO.Path]::GetFileName($_.DstFile) -eq "RELEASENOTES.copy.md") -and (Test-Path $_.DstFile)) { | ||
| if (([System.IO.Path]::GetFileName($_.DstFile) -eq "RELEASENOTES.copy.md") -and (Test-Path -LiteralPath $_.DstFile)) { | ||
| # Read the release notes of the version currently installed | ||
| $oldReleaseNotes = Get-ContentLF -Path $_.DstFile | ||
| # Get the release notes of the new version (for the PR body) | ||
|
|
@@ -287,8 +330,14 @@ else { | |
| $releaseNotes = "No release notes available!" | ||
| } | ||
| $removeFiles | ForEach-Object { | ||
| # Skip files that do not physically resolve to themselves within the destination root folder | ||
| if (-not (Test-PathPhysicallyEqual -Path (Join-Path $dstRoot $_) -AnchorPaths @($dstRoot))) { | ||
| OutputWarning "Skipping removal of '$_': destination does not physically resolve to itself. This may indicate a symlink/junction redirect." | ||
| return | ||
| } | ||
|
|
||
| Write-Host "Remove $_" | ||
| Remove-Item (Join-Path (Get-Location).Path $_) -Force | ||
| Remove-Item -LiteralPath $_ -Force | ||
| } | ||
|
|
||
| # Update the templateUrl and templateSha in the repo settings file | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.