Skip to content

Skip .DS_Store folder and swp files (ViM) in the build command #2471

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

Merged
merged 6 commits into from
Mar 24, 2025

Conversation

mrodm
Copy link
Contributor

@mrodm mrodm commented Mar 13, 2025

Closes #2463

Add exceptions to skip some hidden files when running elastic-package build.
This PR skips the copy to the build directory (and zip file) the following files (using glob patterns):

  • .DS_Store files created in macOS
  • .*.swp files created by ViM

How to test this PR locally

cd /path/to/repo/elastic-package

# Ensure that previous build files and folders are deleted
rm -rf build/packages/apache/
rm -rf build/packages/apache-999.999.999.zip

# Update some test package including the undesired hidden files
cd test/packages/parallel/apache

touch data_stream/access/.DS_Store
touch data_stream/access/.file.swp

# it should finish successfully the build process
elastic-package build -v

# those files or folders must be kept in the current package directory
ls -la data_stream/access

# the contents in the build directory must not have those files/folders
ls -la ../../../../build/packages/apache/999.999.999/data_stream/access

@mrodm mrodm self-assigned this Mar 13, 2025
Comment on lines 28 to 35
regexesFiles := []*regexp.Regexp{}
for _, regexFile := range skippedFiles {
r, err := regexp.Compile(regexFile)
if err != nil {
return fmt.Errorf("failed to compile regex %q: %w", r, err)
}
regexesFiles = append(regexesFiles, r)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pre-compile all regexes before calling to the Walk() function

Copy link
Member

Choose a reason for hiding this comment

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

Maybe this function can directly receive compiled regexps. Or would it be enough to use glob patterns instead of regexes?

Copy link
Contributor Author

@mrodm mrodm Mar 24, 2025

Choose a reason for hiding this comment

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

Updated the code to use glob patterns instead of regexes: b91048e

As everything should be file names glob, patterns should be enough.

}

// CopyWithoutDev method copies files from the source to the destination, but skips _dev directories and empty folders.
func CopyWithoutDev(sourcePath, destinationPath string) error {
return CopyWithSkipped(sourcePath, destinationPath, []string{"_dev", "build", ".git"})
return CopyWithSkipped(sourcePath, destinationPath, []string{"_dev", "build", ".git"}, []string{"\\.DS_Store", "\\..*\\.swp"})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added support to skip files based on their file names if they match some of these regexes.

@mrodm
Copy link
Contributor Author

mrodm commented Mar 13, 2025

/test

@mrodm
Copy link
Contributor Author

mrodm commented Mar 14, 2025

/test

@mrodm mrodm marked this pull request as ready for review March 14, 2025 10:59
@mrodm mrodm requested a review from a team March 14, 2025 10:59
}

// CopyWithoutDev method copies files from the source to the destination, but skips _dev directories and empty folders.
func CopyWithoutDev(sourcePath, destinationPath string) error {
return CopyWithSkipped(sourcePath, destinationPath, []string{"_dev", "build", ".git"})
return CopyWithSkipped(sourcePath, destinationPath, []string{"_dev", "build", ".git"}, []string{"^\\.DS_Store$", "^\\..*\\.swp$"})
Copy link
Member

@jsoriano jsoriano Mar 24, 2025

Choose a reason for hiding this comment

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

Nit. Move these lists of dirs and patterns to variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created const definitions here b91048e

Comment on lines 28 to 35
regexesFiles := []*regexp.Regexp{}
for _, regexFile := range skippedFiles {
r, err := regexp.Compile(regexFile)
if err != nil {
return fmt.Errorf("failed to compile regex %q: %w", r, err)
}
regexesFiles = append(regexesFiles, r)
}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this function can directly receive compiled regexps. Or would it be enough to use glob patterns instead of regexes?

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @mrodm

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Thanks 👍

@mrodm mrodm merged commit e1c3a16 into elastic:main Mar 24, 2025
3 checks passed
@mrodm mrodm deleted the add_exceptions_for_build branch March 24, 2025 16:37
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.

elastic-package build could exclude .DS_Store files gracefully on macOS
3 participants