Skip to content
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

Add glob option to ignore hidden files #1791

Merged
merged 10 commits into from
Aug 15, 2024
Merged
3 changes: 3 additions & 0 deletions packages/glob/RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# @actions/glob Releases

### 0.5.0
- Added `excludeHiddenFiles` option, which is disabled by default to preserve existing behavior [#1791: Add glob option to ignore hidden files](https://github.com/actions/toolkit/pull/1791)

### 0.4.0
- Pass in the current workspace as a parameter to HashFiles [#1318](https://github.com/actions/toolkit/pull/1318)

Expand Down
22 changes: 21 additions & 1 deletion packages/glob/__tests__/internal-globber.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ describe('globber', () => {
expect(itemPaths).toEqual([])
})

it('returns hidden files', async () => {
it('returns hidden files by default', async () => {
// Create the following layout:
// <root>
// <root>/.emptyFolder
Expand All @@ -734,6 +734,26 @@ describe('globber', () => {
])
})

it('ignores hidden files when excludeHiddenFiles is set', async () => {
// Create the following layout:
// <root>
// <root>/.emptyFolder
// <root>/.file
// <root>/.folder
// <root>/.folder/file
const root = path.join(getTestTemp(), 'ignores-hidden-files')
await createHiddenDirectory(path.join(root, '.emptyFolder'))
await createHiddenDirectory(path.join(root, '.folder'))
await createHiddenFile(path.join(root, '.file'), 'test .file content')
await fs.writeFile(
path.join(root, '.folder', 'file'),
'test .folder/file content'
)

const itemPaths = await glob(root, {excludeHiddenFiles: true})
expect(itemPaths).toEqual([root])
})

it('returns normalized paths', async () => {
// Create the following layout:
// <root>/hello/world.txt
Expand Down
2 changes: 1 addition & 1 deletion packages/glob/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/glob/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@actions/glob",
"version": "0.4.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you update the releases file if you are going to bump in this pr as well
https://github.com/actions/toolkit/blob/main/packages/glob/RELEASES.md

Copy link
Collaborator

Choose a reason for hiding this comment

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

No other changes outside of this, some test fixes, and package bumps for security reasons
https://github.com/actions/toolkit/commits/main/packages/glob

"version": "0.5.0",
"preview": true,
"description": "Actions glob lib",
"keywords": [
Expand Down
8 changes: 7 additions & 1 deletion packages/glob/src/internal-glob-options-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export function getOptions(copy?: GlobOptions): GlobOptions {
followSymbolicLinks: true,
implicitDescendants: true,
matchDirectories: true,
omitBrokenSymbolicLinks: true
omitBrokenSymbolicLinks: true,
excludeHiddenFiles: false
}

if (copy) {
Expand All @@ -32,6 +33,11 @@ export function getOptions(copy?: GlobOptions): GlobOptions {
result.omitBrokenSymbolicLinks = copy.omitBrokenSymbolicLinks
core.debug(`omitBrokenSymbolicLinks '${result.omitBrokenSymbolicLinks}'`)
}

if (typeof copy.excludeHiddenFiles === 'boolean') {
result.excludeHiddenFiles = copy.excludeHiddenFiles
core.debug(`excludeHiddenFiles '${result.excludeHiddenFiles}'`)
}
}

return result
Expand Down
9 changes: 9 additions & 0 deletions packages/glob/src/internal-glob-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,13 @@ export interface GlobOptions {
* @default true
*/
omitBrokenSymbolicLinks?: boolean

/**
* Indicates whether to exclude hidden files (files and directories starting with a `.`).
* This does not apply to Windows files and directories with the hidden attribute unless
* they are also prefixed with a `.`.
*
* @default false

Choose a reason for hiding this comment

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

Don't we want the default behavior to be to exclude?

Copy link
Member Author

Choose a reason for hiding this comment

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

We want the default to be exclude for the action that consumes this library, I don't think we need or should make a breaking change in this library.

Choose a reason for hiding this comment

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

Makes sense for changes to the glob package to be backward compatible but just curious, what other actions use this package? Are there any actions other than upload-artifact where we would want to pass true?

Choose a reason for hiding this comment

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

nit: the comment should read "Indicates whether to exclude hidden files.."

Copy link
Member Author

Choose a reason for hiding this comment

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

Are there any actions other than upload-artifact where we would want to pass true?

https://github.com/actions/toolkit/network/dependents?owner=actions&dependent_type=REPOSITORY&owner=actions

I see actions/deploy-pages, actions/upload-artifact, and actions/download-artifact.

*/
excludeHiddenFiles?: boolean
}
5 changes: 5 additions & 0 deletions packages/glob/src/internal-globber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ export class DefaultGlobber implements Globber {
continue
}

// Hidden file or directory?

Choose a reason for hiding this comment

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

What upload-artifact version(s) is this code path exercised in?

Copy link
Contributor

Choose a reason for hiding this comment

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

if (options.excludeHiddenFiles && path.basename(item.path).match(/^\./)) {
continue
}

// Directory
if (stats.isDirectory()) {
// Matched
Expand Down
Loading