-
Notifications
You must be signed in to change notification settings - Fork 28
Add --dir flag to specify subfolder for workflow installation #3459
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
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this 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 adds support for specifying a custom subdirectory under .github/workflows/ when adding workflows via the --dir flag. Users can now organize workflows into subdirectories like .github/workflows/shared/ or .github/workflows/custom/.
Key changes:
- Added
--dirflag to theaddcommand to specify a custom workflow subdirectory - Updated all function signatures in the workflow addition flow to accept and propagate the
workflowDirparameter - Added path validation to prevent absolute paths and path traversal attacks
- Updated tests to pass the new empty string parameter for backward compatibility
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/cli/add_command.go | Core implementation: adds --dir flag, validates path input, and routes workflows to custom subdirectories |
| pkg/cli/trial_command.go | Updates AddWorkflows call to include empty workflowDir parameter |
| pkg/cli/add_wildcard_test.go | Updates addWorkflowWithTracking test calls with empty workflowDir parameter |
| pkg/cli/add_gitattributes_test.go | Updates addWorkflowsNormal test calls with empty workflowDir parameter |
| pkg/cli/add_current_repo_test.go | Updates AddWorkflows test calls with empty workflowDir parameter |
| .github/workflows/super-linter-report.lock.yml | Removes fetch-depth: 0 from checkout action (unrelated change) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| workflowDir = filepath.Clean(workflowDir) | ||
| // Ensure the path is under .github/workflows | ||
| if !strings.HasPrefix(workflowDir, ".github/workflows") { | ||
| // If user provided a subdirectory name, prepend .github/workflows/ | ||
| githubWorkflowsDir = filepath.Join(gitRoot, ".github/workflows", workflowDir) | ||
| } else { | ||
| githubWorkflowsDir = filepath.Join(gitRoot, workflowDir) | ||
| } |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Path traversal vulnerability: filepath.Clean does not prevent path traversal attacks. An attacker could provide --dir ../../../etc which after cleaning becomes ../../../etc, bypassing the .github/workflows prefix check and writing workflows outside the repository. After filepath.Clean, you must validate that the cleaned path does not start with .. or contain .. segments to prevent directory traversal. Add validation like: if strings.Contains(workflowDir, \"..\") { return fmt.Errorf(\"workflow directory cannot contain '..' path elements\") }
| - name: Checkout repository | ||
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 | ||
| with: | ||
| persist-credentials: false |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change: The removal of fetch-depth: 0 from the checkout action appears unrelated to the PR's purpose of adding the --dir flag. This change should either be explained in the PR description or moved to a separate commit/PR.
| persist-credentials: false | |
| persist-credentials: false | |
| fetch-depth: 0 |
The
addcommand hardcoded workflows to.github/workflows/. This prevents organizing workflows into subdirectories for better structure.Changes
CLI Interface:
--dir(-d) flag to specify target subdirectory.github/workflows/.github/workflowsused as-isImplementation:
workflowDirparameter through:AddWorkflows()→addWorkflowsNormal()→addWorkflowsWithPR()→addWorkflowWithTracking().github/workflows/(default).github/workflows/{name}/.github/workflows/{path}/Example:
All existing tests updated to pass new parameter. Backward compatible.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.