Exclude path from clean

This commit is contained in:
Gregory Bonaert 2025-04-09 17:24:36 +02:00
parent 85e6279cec
commit 9a73efb9ba
6 changed files with 28 additions and 5 deletions

View file

@ -1,5 +1,9 @@
[![Build and Test](https://github.com/actions/checkout/actions/workflows/test.yml/badge.svg)](https://github.com/actions/checkout/actions/workflows/test.yml) [![Build and Test](https://github.com/actions/checkout/actions/workflows/test.yml/badge.svg)](https://github.com/actions/checkout/actions/workflows/test.yml)
Changes compared to https://github.com/actions/checkout:
- Can exclude path when cleaning repository
# Checkout V4 # Checkout V4
This action checks-out your repository under `$GITHUB_WORKSPACE`, so your workflow can access it. This action checks-out your repository under `$GITHUB_WORKSPACE`, so your workflow can access it.
@ -77,7 +81,10 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
# Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching # Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching
# Default: true # Default: true
clean: '' clean: ''
# Path to exclude from cleaning
exclude_from_clean: ''
# Partially clone against a given filter. Overrides sparse-checkout if set. # Partially clone against a given filter. Overrides sparse-checkout if set.
# Default: null # Default: null
filter: '' filter: ''

View file

@ -57,7 +57,7 @@ export interface IGitCommandManager {
submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void> submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void>
submoduleStatus(): Promise<boolean> submoduleStatus(): Promise<boolean>
tagExists(pattern: string): Promise<boolean> tagExists(pattern: string): Promise<boolean>
tryClean(): Promise<boolean> tryClean(exclude_from_clean: string | undefined): Promise<boolean>
tryConfigUnset(configKey: string, globalConfig?: boolean): Promise<boolean> tryConfigUnset(configKey: string, globalConfig?: boolean): Promise<boolean>
tryDisableAutomaticGarbageCollection(): Promise<boolean> tryDisableAutomaticGarbageCollection(): Promise<boolean>
tryGetFetchUrl(): Promise<string> tryGetFetchUrl(): Promise<string>
@ -434,8 +434,13 @@ class GitCommandManager {
return !!output.stdout.trim() return !!output.stdout.trim()
} }
async tryClean(): Promise<boolean> { async tryClean(exclude_from_clean: string | undefined): Promise<boolean> {
const output = await this.execGit(['clean', '-ffdx'], true) let output
if (exclude_from_clean === undefined) {
output = await this.execGit(['clean', '-ffdx'], true)
} else {
output = await this.execGit(['clean', '-ffdx', '-e', exclude_from_clean], true)
}
return output.exitCode === 0 return output.exitCode === 0
} }

View file

@ -11,6 +11,7 @@ export async function prepareExistingDirectory(
repositoryPath: string, repositoryPath: string,
repositoryUrl: string, repositoryUrl: string,
clean: boolean, clean: boolean,
exclude_from_clean: string | undefined,
ref: string ref: string
): Promise<void> { ): Promise<void> {
assert.ok(repositoryPath, 'Expected repositoryPath to be defined') assert.ok(repositoryPath, 'Expected repositoryPath to be defined')
@ -90,7 +91,7 @@ export async function prepareExistingDirectory(
// Clean // Clean
if (clean) { if (clean) {
core.startGroup('Cleaning the repository') core.startGroup('Cleaning the repository')
if (!(await git.tryClean())) { if (!(await git.tryClean(exclude_from_clean))) {
core.debug( core.debug(
`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For further investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.` `The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For further investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`
) )

View file

@ -70,6 +70,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
settings.repositoryPath, settings.repositoryPath,
repositoryUrl, repositoryUrl,
settings.clean, settings.clean,
settings.exclude_from_clean,
settings.ref settings.ref
) )
} }

View file

@ -29,6 +29,11 @@ export interface IGitSourceSettings {
*/ */
clean: boolean clean: boolean
/**
* Indicates path to exclude when cleaning
*/
exclude_from_clean: string | undefined
/** /**
* The filter determining which objects to include * The filter determining which objects to include
*/ */

View file

@ -82,6 +82,10 @@ export async function getInputs(): Promise<IGitSourceSettings> {
result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE' result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE'
core.debug(`clean = ${result.clean}`) core.debug(`clean = ${result.clean}`)
// Clean
result.exclude_from_clean = core.getInput('exclude_from_clean')
core.debug(`exclude_from_clean = ${result.exclude_from_clean}`)
// Filter // Filter
const filter = core.getInput('filter') const filter = core.getInput('filter')
if (filter) { if (filter) {