Skip to content

Enhance customALGoFiles feature - #2273

Open
Ole Wunschmann (OleWunschmann) wants to merge 37 commits into
microsoft:mainfrom
OleWunschmann:enhance-customALGoFiles-feature
Open

Enhance customALGoFiles feature#2273
Ole Wunschmann (OleWunschmann) wants to merge 37 commits into
microsoft:mainfrom
OleWunschmann:enhance-customALGoFiles-feature

Conversation

@OleWunschmann

@OleWunschmann Ole Wunschmann (OleWunschmann) commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

❔What, Why & How

This pull request introduces significant improvements to the handling of custom template file inclusion and exclusion in AL-Go actions, focusing on robust path resolution, improved deduplication, and enhanced cross-platform compatibility. The changes also clarify and expand the documentation for settings, and add a new utility function for reading settings with custom templates.

Improvements to custom template file handling:

  • The current customALGoFiles settings from the custom template are now merged and used directly during updates, ensuring that the latest template configuration is always applied without waiting for a new update cycle.
  • Both filesToInclude and filesToExclude are now resolved against both the custom template and the original AL-Go template, ensuring that files added or removed upstream are properly propagated to consumer repositories.
  • A new destinationName property is added to filesToInclude, allowing files to be renamed when copied to the destination. This is reflected in both the schema and implementation.

**Path Handling and Cross-Platform Support

  • Introduced GetPathStringComparison and GetPathStringComparer utility functions to ensure path comparisons and deduplication are case-insensitive on Windows/macOS and case-sensitive on Linux, improving cross-platform reliability.
  • Updated ResolveFilePaths to canonicalize all paths, enforce that destination folders/files are within allowed directories, and use the new path comparison utilities for accurate and secure file operations.

Documentation and schema updates:

  • The schema and documentation for filesToInclude and filesToExclude have been updated to clarify their new behavior and the new destinationName property.

These changes make custom template management more robust, predictable, and safer for consumer repositories.

Related to discussion: #2227

✅ Checklist

  • Add tests (E2E, unit tests)
  • Update RELEASENOTES.md
  • Update documentation (e.g. for new settings or scenarios)
  • Add telemetry

Copilot AI review requested due to automatic review settings June 3, 2026 15:24
@OleWunschmann
Ole Wunschmann (OleWunschmann) requested a review from a team as a code owner June 3, 2026 15:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR enhances the customALGoFiles behavior during “Update AL-Go System Files”, adding support for unconditional removals (filesToRemove) and improving custom-template behavior by merging template settings directly and resolving files from the original AL-Go template where applicable.

Changes:

  • Add customALGoFiles.filesToRemove support end-to-end (schema, defaults, resolution logic, docs, and release notes).
  • Update CheckForUpdates to read template repo settings via ReadSettings and merge template settings during file resolution.
  • Expand automated coverage (unit + e2e) for include/exclude/remove resolution and custom-template propagation.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
e2eTests/scenarios/CustomTemplate/runtest.ps1 Extends e2e scenario to validate custom-template file include/exclude/remove propagation and workflow presence.
Tests/CheckForUpdates.Action.Test.ps1 Adds unit tests for destination-folder resolution and expanded GetFilesToUpdate behaviors (including filesToRemove).
Actions/CheckForUpdates/CheckForUpdates.ps1 Updates settings reading (incl. trigger) and wires template settings + filesToRemove into update/removal flow.
Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 Implements ResolveFilePathsInDestinationFolder and extends GetFilesToUpdate to produce include/exclude/remove lists.
Actions/.Modules/settings.schema.json Extends settings schema with customALGoFiles.filesToRemove and clarifying descriptions.
Actions/.Modules/ReadSettings.psm1 Adds default filesToRemove array under customALGoFiles.
Scenarios/settings.md Documents customALGoFiles.filesToRemove in settings reference.
Scenarios/CustomizingALGoForGitHub.md Adds conceptual docs + examples for original-template resolution and filesToRemove.
RELEASENOTES.md Documents enhanced customALGoFiles behavior and new filesToRemove.

Comment thread Tests/CheckForUpdates.Action.Test.ps1 Outdated
Comment thread Tests/CheckForUpdates.Action.Test.ps1 Outdated
Comment thread e2eTests/scenarios/CustomTemplate/runtest.ps1
Comment thread e2eTests/scenarios/CustomTemplate/runtest.ps1
Comment thread Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 Outdated
Comment thread Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1
Comment thread e2eTests/scenarios/CustomTemplate/runtest.ps1 Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comment thread Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 Outdated
Comment thread Scenarios/CustomizingALGoForGitHub.md Outdated
Comment thread Actions/.Modules/settings.schema.json Outdated
@OleWunschmann

Copy link
Copy Markdown
Contributor Author

Maria Zhelezova (@mazhelez) The failing PS5 tests should be fixed now.

Comment thread RELEASENOTES.md
Comment thread RELEASENOTES.md
Comment thread Actions/.Modules/settings.schema.json Outdated
Copilot AI review requested due to automatic review settings July 21, 2026 09:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1:1205

  • Removal destinations are not constrained to $baseFolder. A filesToRemove entry with a matching template file and destinationFolder = '..' produces a destinationFullPath outside the repository; CheckForUpdates.ps1 later converts it to a relative path and passes it to Remove-Item. Normalize every removal destination and reject paths that are not descendants of the repository root before returning this list.
        $filesToRemove += @(ResolveFilePaths -sourceFolder $originalTemplateFolder -destinationFolder $baseFolder -files $filesToRemoveUnresolved -projects $projects)
    }
    $filesToRemove += @(ResolveFilePaths -sourceFolder $templateFolder -originalSourceFolder $originalTemplateFolder -destinationFolder $baseFolder -files $filesToRemoveUnresolved -projects $projects)
    $filesToRemove += @(ResolveFilePathsInDestinationFolder -destinationFolder $baseFolder -files $filesToRemoveUnresolved -projects $projects)

Comment thread Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 Outdated
Comment thread Actions/CheckForUpdates/CheckForUpdates.ps1 Outdated
Comment thread Scenarios/CustomizingALGoForGitHub.md Outdated
Copilot AI review requested due to automatic review settings July 31, 2026 21:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Not ready to approve

Destination normalization rejects valid relative paths, and case-insensitive deduplication drops valid Linux files.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (3)

Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1:956

  • The destination file is canonicalized but $fileDestinationFolder is not. Consequently, valid relative folder paths such as . or scripts/../shared are treated as traversal and skipped because the normalized file path cannot start with the unnormalized folder string. Canonicalize the folder first and check that it remains under $destinationFolder; then retain the existing filename-boundary check.
                $fileDestinationFolder = Join-Path $destinationFolder $file.destinationFolder
                $fileDestinationFolder = Join-Path $fileDestinationFolder '' # Ensure file destination folder has a trailing slash for correct path resolution

                $fullFilePath.destinationFullPath = Join-Path $fileDestinationFolder $destinationName
                $fullFilePath.destinationFullPath = [System.IO.Path]::GetFullPath($fullFilePath.destinationFullPath) # Canonicalize the destination full path to an absolute path

Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1:928

  • $fileDestinationFolder is compared before it is canonicalized, while destinationFullPath is canonicalized. A valid relative path containing . or an internal .. (for example, destinationFolder: './scripts') therefore fails StartsWith and is skipped. Canonicalize the project and file destination folders first, then separately verify the project stays under the base folder and the file folder stays under the project folder before checking destinationName.

This issue also appears on line 952 of the same file.

                    $fileDestinationFolder = Join-Path $destinationFolder $project
                    $fileDestinationFolder = Join-Path $fileDestinationFolder $file.destinationFolder
                    $fileDestinationFolder = Join-Path $fileDestinationFolder '' # Ensure file destination folder has a trailing slash for correct path resolution

Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1:1141

  • Group-Object groups strings case-insensitively by default. On Linux, the new dual-template resolution can produce distinct destinations such as Foo.ps1 from the custom template and foo.ps1 from the original template, but this line drops one even though both paths are valid and distinct. Deduplicate with an OS-appropriate StringComparer, matching the path comparison used by ResolveFilePaths.
    $filesToInclude = @($filesToInclude | Group-Object { $_.destinationFullPath } | Sort-Object -Property Name | ForEach-Object { $_.Group[0] })
  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment on lines +955 to +959
$fullFilePath.destinationFullPath = Join-Path $fileDestinationFolder $destinationName
$fullFilePath.destinationFullPath = [System.IO.Path]::GetFullPath($fullFilePath.destinationFullPath) # Canonicalize the destination full path to an absolute path

# Check if the destination file is under the file destination folder
if (-not $fullFilePath.destinationFullPath.StartsWith($fileDestinationFolder, $pathComparison)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copilot Can you please elaborate on this finding? Can you share a full example of what could go wrong?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think Copilot has an issue with pull requests from forks.

As far as I know, the problem is: a supposedly valid destination path (i.e., no breakout from the repo/project folder) can reference a symbolic link that points to an invalid location (for example, outside the repo/project folder).
This is not currently checked and when the file is written, it follows the symlink and writes to the linked path instead of staying inside the repo/project.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Uff, that doesn't sound good.
Containment in the repo at least should be enforced. I suspect this hasn't been checked for before, but it'll be great if you could include it in your changes.

@mazhelez

Copy link
Copy Markdown
Collaborator

📦 Release Notes Update Required

AL-Go v9.2 has been released, and your changes to RELEASENOTES.md appear to be under that version's section.

Action needed: Please move your release notes entry to above the ## v9.2 heading so it will be included in the next release.

Example
## Changes to be included in the next release

- Your change here ✅

## v9.2

- Already released changes

Thank you for contributing to AL-Go! 🙏

@mazhelez

Copy link
Copy Markdown
Collaborator

Copilot resolve the merge conflicts in this pull request

@OleWunschmann

Ole Wunschmann (OleWunschmann) commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Maria Zhelezova (@mazhelez)
Please excuse the radio silence over the last four weeks.
I was on vacation and therefore couldn’t continue working on this pull request.

I’ve gone ahead and resolved the merge conflicts, since I suspect that Copilot struggled with the fact that the source branch comes from my fork.

I saw that there were already approvals, but there are still two Copilot comments open:

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 Outdated
@mazhelez

Copy link
Copy Markdown
Collaborator

Maria Zhelezova (Maria Zhelezova (@mazhelez)) Please excuse the radio silence over the last four weeks. I was on vacation and therefore couldn’t continue working on this pull request.

I’ve gone ahead and resolved the merge conflicts, since I suspect that Copilot struggled with the fact that the source branch comes from my fork.

I saw that there were already approvals, but there are still two Copilot comments open:

Welcome back! I hope your vacation was splendid!

On the comments: I resolved the first one. As for the second one, I'll need to take a proper look.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1
$upperCaseFolder = Join-Path $templateFolder 'CaseFolder'
$lowerCaseFolder = Join-Path $templateFolder 'casefolder'
$upperCaseFile = Join-Path $upperCaseFolder 'script.ps1'
$lowerCaseFile = Join-Path $lowerCaseFolder 'script.ps1'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ole Wunschmann (@OleWunschmann) can you please address this one? Suppress, if needed.

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.

7 participants