Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new preserve-local-changes option to the GitHub Actions checkout process that allows users to preserve local files that are not tracked by Git during checkout. The feature addresses issues where local files created before checkout would be lost.
- Adds
preserve-local-changesinput parameter with default value offalse - Implements file preservation logic that stores local files in memory before checkout and restores untracked files after checkout
- Updates interfaces, documentation, and workflow examples to support the new feature
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| action.yml | Adds new preserve-local-changes input parameter with documentation |
| README.md | Documents the new feature with usage examples |
| src/input-helper.ts | Parses the new input parameter from action configuration |
| src/git-source-settings.ts | Adds preserveLocalChanges property to the settings interface |
| src/git-source-provider.ts | Implements core file preservation logic during checkout |
| src/git-directory-helper.ts | Modifies directory cleanup to respect preserve settings |
| src/git-command-manager.ts | Updates checkout method to support custom options |
|
|
||
| // List and store local files before checkout | ||
| const fs = require('fs') | ||
| const path = require('path') |
There was a problem hiding this comment.
Import statements should be at the top of the file using ES6 import syntax instead of require() within function scope.
| const path = require('path') |
| for (const [filePath, content] of localFiles.entries()) { | ||
| // Check if file exists in git using a child process instead of git.execGit | ||
| const { exec } = require('@actions/exec') | ||
| let exitCode = 0 |
There was a problem hiding this comment.
Import statements should be at the top of the file using ES6 import syntax instead of require() within function scope.
| let exitCode = 0 | |
| let exitCode = 0 |
| } | ||
| }) | ||
| return results | ||
| } |
There was a problem hiding this comment.
Using synchronous file operations (readFileSync, readdirSync, statSync) can block the event loop. Consider using async versions with await to maintain performance in Node.js applications.
|
|
||
| const localFilesList = listFilesRecursively(workspacePath) | ||
| core.info(`Found ${localFilesList.length} local files to preserve:`) | ||
| localFilesList.forEach(file => core.info(` - ${file}`)) |
There was a problem hiding this comment.
Reading all files into memory simultaneously could cause high memory usage for repositories with large files. Consider implementing a streaming approach or processing files in batches.
| localFilesList.forEach(file => core.info(` - ${file}`)) | |
| // Store only file path, not content | |
| results.push(relativePath) | |
| } | |
| }) | |
| return results | |
| } | |
| const localFilesList = listFilesRecursively(workspacePath) | |
| localFilesList.forEach(file => localFilePaths.push(file)) | |
| core.info(`Found ${localFilePaths.length} local files to preserve:`) | |
| localFilePaths.forEach(file => core.info(` - ${file}`)) |
src/git-directory-helper.ts
Outdated
| // We still need to make sure we have a git repository to work with | ||
| if (!git) { | ||
| core.info(`Initializing git repository to prepare for checkout with preserved changes`) | ||
| await fs.promises.mkdir(path.join(repositoryPath, '.git'), { recursive: true }) |
There was a problem hiding this comment.
Creating only the .git directory is insufficient to initialize a proper Git repository. This should use git init command or proper Git initialization to create all necessary Git metadata files.
| await fs.promises.mkdir(path.join(repositoryPath, '.git'), { recursive: true }) | |
| await new Promise<void>((resolve, reject) => { | |
| execFile('git', ['init'], { cwd: repositoryPath }, (error) => { | |
| if (error) { | |
| reject(error) | |
| } else { | |
| resolve() | |
| } | |
| }) | |
| }) |
Makes preserve-local-changes option work consistently in all scenarios, including when repository URL changes. Updates warning message to correctly reflect this behavior.
New option for the GitHub Actions checkout process, allowing users to preserve local files that are not tracked by Git during a checkout. The changes span documentation, configuration, and implementation, ensuring users can opt-in to this behavior via a new
preserve-local-changesinput. The implementation carefully handles file restoration and updates relevant interfaces and workflow examples.For this #2216 & this #2054
You can test it with this branch/workflow file: