Skip to content

Commit afc7e4a

Browse files
authored
Exclude hidden files by default backport
1 parent a8a3f3a commit afc7e4a

File tree

8 files changed

+178
-69
lines changed

8 files changed

+178
-69
lines changed

__tests__/search.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ const lonelyFilePath = path.join(
6161
'lonely-file.txt'
6262
)
6363

64+
const hiddenFile = path.join(root, '.hidden-file.txt')
65+
const fileInHiddenFolderPath = path.join(
66+
root,
67+
'.hidden-folder',
68+
'folder-in-hidden-folder',
69+
'file.txt'
70+
)
71+
const fileInHiddenFolderInFolderA = path.join(
72+
root,
73+
'folder-a',
74+
'.hidden-folder-in-folder-a',
75+
'file.txt'
76+
)
77+
6478
describe('Search', () => {
6579
beforeAll(async () => {
6680
// mock all output so that there is less noise when running tests
@@ -92,6 +106,13 @@ describe('Search', () => {
92106
await fs.mkdir(path.join(root, 'folder-h', 'folder-j', 'folder-k'), {
93107
recursive: true
94108
})
109+
await fs.mkdir(
110+
path.join(root, '.hidden-folder', 'folder-in-hidden-folder'),
111+
{recursive: true}
112+
)
113+
await fs.mkdir(path.join(root, 'folder-a', '.hidden-folder-in-folder-a'), {
114+
recursive: true
115+
})
95116

96117
await fs.writeFile(searchItem1Path, 'search item1 file')
97118
await fs.writeFile(searchItem2Path, 'search item2 file')
@@ -110,10 +131,19 @@ describe('Search', () => {
110131
await fs.writeFile(amazingFileInFolderHPath, 'amazing file')
111132

112133
await fs.writeFile(lonelyFilePath, 'all by itself')
134+
135+
await fs.writeFile(hiddenFile, 'hidden file')
136+
await fs.writeFile(fileInHiddenFolderPath, 'file in hidden directory')
137+
await fs.writeFile(fileInHiddenFolderInFolderA, 'file in hidden directory')
113138
/*
114139
Directory structure of files that get created:
115140
root/
141+
.hidden-folder/
142+
folder-in-hidden-folder/
143+
file.txt
116144
folder-a/
145+
.hidden-folder-in-folder-a/
146+
file.txt
117147
folder-b/
118148
folder-c/
119149
search-item1.txt
@@ -136,6 +166,7 @@ describe('Search', () => {
136166
folder-j/
137167
folder-k/
138168
lonely-file.txt
169+
.hidden-file.txt
139170
search-item5.txt
140171
*/
141172
})
@@ -352,4 +383,24 @@ describe('Search', () => {
352383
)
353384
expect(searchResult.filesToUpload.includes(lonelyFilePath)).toEqual(true)
354385
})
386+
387+
it('Hidden files ignored by default', async () => {
388+
const searchPath = path.join(root, '**/*')
389+
const searchResult = await findFilesToUpload(searchPath)
390+
391+
expect(searchResult.filesToUpload).not.toContain(hiddenFile)
392+
expect(searchResult.filesToUpload).not.toContain(fileInHiddenFolderPath)
393+
expect(searchResult.filesToUpload).not.toContain(
394+
fileInHiddenFolderInFolderA
395+
)
396+
})
397+
398+
it('Hidden files included', async () => {
399+
const searchPath = path.join(root, '**/*')
400+
const searchResult = await findFilesToUpload(searchPath, true)
401+
402+
expect(searchResult.filesToUpload).toContain(hiddenFile)
403+
expect(searchResult.filesToUpload).toContain(fileInHiddenFolderPath)
404+
expect(searchResult.filesToUpload).toContain(fileInHiddenFolderInFolderA)
405+
})
355406
})

dist/index.js

Lines changed: 102 additions & 53 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"dependencies": {
3232
"@actions/artifact": "^1.1.2",
3333
"@actions/core": "^1.10.0",
34-
"@actions/glob": "^0.3.0",
34+
"@actions/glob": "^0.5.0",
3535
"@actions/io": "^1.1.2"
3636
},
3737
"devDependencies": {

src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ export enum Inputs {
33
Name = 'name',
44
Path = 'path',
55
IfNoFilesFound = 'if-no-files-found',
6-
RetentionDays = 'retention-days'
6+
RetentionDays = 'retention-days',
7+
IncludeHiddenFiles = 'include-hidden-files'
78
}
89

910
export enum NoFileOptions {

src/input-helper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export function getInputs(): UploadInputs {
1111

1212
const ifNoFilesFound = core.getInput(Inputs.IfNoFilesFound)
1313
const noFileBehavior: NoFileOptions = NoFileOptions[ifNoFilesFound]
14+
const includeHiddenFiles = core.getBooleanInput(Inputs.IncludeHiddenFiles)
1415

1516
if (!noFileBehavior) {
1617
core.setFailed(
@@ -25,7 +26,8 @@ export function getInputs(): UploadInputs {
2526
const inputs = {
2627
artifactName: name,
2728
searchPath: path,
28-
ifNoFilesFound: noFileBehavior
29+
ifNoFilesFound: noFileBehavior,
30+
includeHiddenFiles
2931
} as UploadInputs
3032

3133
const retentionDaysStr = core.getInput(Inputs.RetentionDays)

src/search.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ export interface SearchResult {
1111
rootDirectory: string
1212
}
1313

14-
function getDefaultGlobOptions(): glob.GlobOptions {
14+
function getDefaultGlobOptions(includeHiddenFiles: boolean): glob.GlobOptions {
1515
return {
1616
followSymbolicLinks: true,
1717
implicitDescendants: true,
18-
omitBrokenSymbolicLinks: true
18+
omitBrokenSymbolicLinks: true,
19+
excludeHiddenFiles: !includeHiddenFiles
1920
}
2021
}
2122

@@ -80,12 +81,12 @@ function getMultiPathLCA(searchPaths: string[]): string {
8081

8182
export async function findFilesToUpload(
8283
searchPath: string,
83-
globOptions?: glob.GlobOptions
84+
includeHiddenFiles?: boolean
8485
): Promise<SearchResult> {
8586
const searchResults: string[] = []
8687
const globber = await glob.create(
8788
searchPath,
88-
globOptions || getDefaultGlobOptions()
89+
getDefaultGlobOptions(includeHiddenFiles || false)
8990
)
9091
const rawSearchResults: string[] = await globber.glob()
9192

src/upload-inputs.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ export interface UploadInputs {
2020
* Duration after which artifact will expire in days
2121
*/
2222
retentionDays: number
23+
24+
/**
25+
* Whether or not to include hidden files in the artifact
26+
*/
27+
includeHiddenFiles: boolean
2328
}

0 commit comments

Comments
 (0)