Skip to content

Commit 5076954

Browse files
authored
Merge pull request #598 from actions/joshmgross/exclude-hidden-files
Exclude hidden files by default
2 parents 834a144 + d52396a commit 5076954

19 files changed

+372
-143
lines changed

Diff for: .licenses/npm/@actions/glob.dep.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ There is also a new sub-action, `actions/upload-artifact/merge`. For more info,
6464
Due to how Artifacts are created in this new version, it is no longer possible to upload to the same named Artifact multiple times. You must either split the uploads into multiple Artifacts with different names, or only upload once. Otherwise you _will_ encounter an error.
6565

6666
3. Limit of Artifacts for an individual job. Each job in a workflow run now has a limit of 500 artifacts.
67+
4. With `v4.4` and later, hidden files are excluded by default.
6768

6869
For assistance with breaking changes, see [MIGRATION.md](docs/MIGRATION.md).
6970

@@ -107,6 +108,12 @@ For assistance with breaking changes, see [MIGRATION.md](docs/MIGRATION.md).
107108
# Does not fail if the artifact does not exist.
108109
# Optional. Default is 'false'
109110
overwrite:
111+
112+
# Whether to include hidden files in the provided path in the artifact
113+
# The file contents of any hidden files in the path should be validated before
114+
# enabled this to avoid uploading sensitive information.
115+
# Optional. Default is 'false'
116+
include-hidden-files:
110117
```
111118
112119
### Outputs

Diff for: __tests__/search.test.ts

+52
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
@@ -93,6 +107,14 @@ describe('Search', () => {
93107
recursive: true
94108
})
95109

110+
await fs.mkdir(
111+
path.join(root, '.hidden-folder', 'folder-in-hidden-folder'),
112+
{recursive: true}
113+
)
114+
await fs.mkdir(path.join(root, 'folder-a', '.hidden-folder-in-folder-a'), {
115+
recursive: true
116+
})
117+
96118
await fs.writeFile(searchItem1Path, 'search item1 file')
97119
await fs.writeFile(searchItem2Path, 'search item2 file')
98120
await fs.writeFile(searchItem3Path, 'search item3 file')
@@ -110,10 +132,19 @@ describe('Search', () => {
110132
await fs.writeFile(amazingFileInFolderHPath, 'amazing file')
111133

112134
await fs.writeFile(lonelyFilePath, 'all by itself')
135+
136+
await fs.writeFile(hiddenFile, 'hidden file')
137+
await fs.writeFile(fileInHiddenFolderPath, 'file in hidden directory')
138+
await fs.writeFile(fileInHiddenFolderInFolderA, 'file in hidden directory')
113139
/*
114140
Directory structure of files that get created:
115141
root/
142+
.hidden-folder/
143+
folder-in-hidden-folder/
144+
file.txt
116145
folder-a/
146+
.hidden-folder-in-folder-a/
147+
file.txt
117148
folder-b/
118149
folder-c/
119150
search-item1.txt
@@ -136,6 +167,7 @@ describe('Search', () => {
136167
folder-j/
137168
folder-k/
138169
lonely-file.txt
170+
.hidden-file.txt
139171
search-item5.txt
140172
*/
141173
})
@@ -352,4 +384,24 @@ describe('Search', () => {
352384
)
353385
expect(searchResult.filesToUpload.includes(lonelyFilePath)).toEqual(true)
354386
})
387+
388+
it('Hidden files ignored by default', async () => {
389+
const searchPath = path.join(root, '**/*')
390+
const searchResult = await findFilesToUpload(searchPath)
391+
392+
expect(searchResult.filesToUpload).not.toContain(hiddenFile)
393+
expect(searchResult.filesToUpload).not.toContain(fileInHiddenFolderPath)
394+
expect(searchResult.filesToUpload).not.toContain(
395+
fileInHiddenFolderInFolderA
396+
)
397+
})
398+
399+
it('Hidden files included', async () => {
400+
const searchPath = path.join(root, '**/*')
401+
const searchResult = await findFilesToUpload(searchPath, true)
402+
403+
expect(searchResult.filesToUpload).toContain(hiddenFile)
404+
expect(searchResult.filesToUpload).toContain(fileInHiddenFolderPath)
405+
expect(searchResult.filesToUpload).toContain(fileInHiddenFolderInFolderA)
406+
})
355407
})

Diff for: action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ inputs:
4040
If false, the action will fail if an artifact for the given name already exists.
4141
Does not fail if the artifact does not exist.
4242
default: 'false'
43+
include-hidden-files:
44+
description: >
45+
If true, hidden files will be included in the artifact.
46+
If false, hidden files will be excluded from the artifact.
47+
default: 'false'
4348

4449
outputs:
4550
artifact-id:

0 commit comments

Comments
 (0)