Skip to content

Conversation

@TravisEz13
Copy link
Member

Summary

This PR creates a new reusable composite action for retrieving changed files and refactors two existing actions to use it, eliminating duplicate code and improving security.

Changes

1. New Get-Changed-Files Action

  • Created .github/actions/infrastructure/get-changed-files/ composite action
  • Supports both pull_request and push events
  • Optional filtering by file pattern (e.g., *.md, .github/)
  • Full pagination support - fetches ALL changed files (no 100-file limit)
  • Returns JSON array of file paths for easy consumption
  • Includes comprehensive README with usage examples

2. Refactored Markdownlinks Action

  • Now uses get-changed-files with ilter: '*.md'
  • Reduced from 108 lines 77 lines (29% reduction)
  • Eliminated 31 lines of duplicate file retrieval code
  • Uses secure environment variable instead of direct string interpolation

3. Refactored Path-Filters Action

  • Now uses get-changed-files for PR events
  • Reduced from 130 lines 123 lines
  • Eliminated 15+ lines of duplicate pagination logic
  • Fixed JSON security issue: now uses romJSON() instead of unsafe JSON.parse()
  • Added detailed logging for filter analysis
  • Proper escaping prevents potential code injection from filenames

Benefits

Code Reuse: Eliminates ~60 lines of duplicate code across actions
Maintainability: Centralizes file retrieval logic in one place - future changes only need to be made once
Security: Fixes JSON injection vulnerability in path-filters
Consistency: All actions using changed files will behave identically
Completeness: Full pagination ensures no files are missed in large PRs
Clarity: Better logging and documentation

Testing

  • YAML syntax validated
  • No linting errors
  • All actions maintain backward compatibility
  • Changes follow existing patterns in the codebase

Related

This is part of splitting up PR #26350 into smaller, more manageable chunks. This PR contains the foundation (reusable action) and refactoring work, while the merge conflict checker will come in a separate PR.

- Create new .github/actions/infrastructure/get-changed-files composite action
  - Supports both pull_request and push events
  - Optional filtering by file pattern (e.g., '*.md', '.github/')
  - Full pagination support (fetches all changed files, not just first 100)
  - Returns JSON array of file paths for easy consumption

- Refactor markdownlinks action to use get-changed-files
  - Reduced from 108 lines to 77 lines (29% reduction)
  - Eliminated 31 lines of duplicate file retrieval code
  - Uses secure environment variable instead of direct string interpolation

- Refactor path-filters action to use get-changed-files
  - Reduced from 130 lines to 123 lines
  - Eliminated 15+ lines of duplicate pagination logic
  - Fixed JSON security issue: now uses fromJSON() instead of unsafe JSON.parse()
  - Added detailed logging for filter analysis
  - Proper escaping prevents potential code injection from filenames

Benefits:
- Eliminates ~60 lines of duplicate code across actions
- Centralizes file retrieval logic in one place
- Improves security with proper JSON handling
- Ensures consistent behavior across all actions using changed files
- Full pagination ensures no files are missed in large PRs
Copilot AI review requested due to automatic review settings October 30, 2025 20:51
@TravisEz13 TravisEz13 requested review from a team and jshigetomi as code owners October 30, 2025 20:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new reusable composite action get-changed-files to centralize the logic for fetching changed files in PRs and push events, and refactors existing actions to use it. This eliminates code duplication, improves security by using environment variables instead of direct string interpolation, and adds pagination support to handle PRs with more than 100 changed files.

Key changes:

  • Created a new get-changed-files action with pagination support, filtering capabilities, and security improvements
  • Refactored path-filters action to use the new get-changed-files action and pass data via environment variables
  • Updated markdownlinks action to use the new get-changed-files action for consistency

Reviewed Changes

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

File Description
.github/actions/infrastructure/get-changed-files/action.yml New reusable action that fetches changed files with pagination support, filtering, and hash verification
.github/actions/infrastructure/get-changed-files/README.md Documentation for the new action including usage examples, inputs, outputs, and limitations
.github/actions/infrastructure/path-filters/action.yml Refactored to use get-changed-files action and receive data via environment variables for security; added detailed logging and removed redundant PowerShell output step
.github/actions/infrastructure/markdownlinks/action.yml Updated to use get-changed-files action with filtering instead of inline GitHub API calls

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member Author

@TravisEz13 TravisEz13 left a comment

Choose a reason for hiding this comment

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

LGTM

TravisEz13 and others added 6 commits October 30, 2025 13:55
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@TravisEz13 TravisEz13 added CL-BuildPackaging Indicates that a PR should be marked as a build or packaging change in the Change Log CL-Tools Indicates that a PR should be marked as a tools change in the Change Log and removed CL-BuildPackaging Indicates that a PR should be marked as a build or packaging change in the Change Log labels Oct 30, 2025
@TravisEz13 TravisEz13 enabled auto-merge (squash) October 30, 2025 21:24
@TravisEz13 TravisEz13 merged commit a936884 into PowerShell:master Oct 30, 2025
37 of 38 checks passed
@microsoft-github-policy-service
Copy link
Contributor

microsoft-github-policy-service bot commented Oct 30, 2025

📣 Hey @@TravisEz13, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

SIRMARGIN pushed a commit to SIRMARGIN/PowerShell that referenced this pull request Dec 12, 2025
…owerShell#26355)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport-7.4.x-Migrated BackPort-7.5.x-Consider Backport-7.6.x-Migrated CL-Tools Indicates that a PR should be marked as a tools change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants