Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions __tests__/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ describe('Search', () => {
})

it('Hidden files ignored by default', async () => {
const warningSpy = jest.spyOn(core, 'warning')
const searchPath = path.join(root, '**/*')
const searchResult = await findFilesToUpload(searchPath)

Expand All @@ -394,14 +395,19 @@ describe('Search', () => {
expect(searchResult.filesToUpload).not.toContain(
fileInHiddenFolderInFolderA
)
expect(warningSpy).toHaveBeenCalledWith(
expect.stringMatching(/Set include-hidden-files to true to include these files.$/)
)
})

it('Hidden files included', async () => {
const warningSpy = jest.spyOn(core, 'warning')
const searchPath = path.join(root, '**/*')
const searchResult = await findFilesToUpload(searchPath, true)

expect(searchResult.filesToUpload).toContain(hiddenFile)
expect(searchResult.filesToUpload).toContain(fileInHiddenFolderPath)
expect(searchResult.filesToUpload).toContain(fileInHiddenFolderInFolderA)
expect(warningSpy).not.toHaveBeenCalled()
})
})
23 changes: 22 additions & 1 deletion src/shared/search.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as glob from '@actions/glob'
import * as path from 'path'
import {debug, info} from '@actions/core'
import {debug, info, warning} from '@actions/core'
import {stat} from 'fs'
import {dirname} from 'path'
import {promisify} from 'util'
Expand Down Expand Up @@ -90,6 +90,27 @@ export async function findFilesToUpload(
)
const rawSearchResults: string[] = await globber.glob()

/*
Check for hidden files by comparing results with includeHiddenFiles=true
*/
if (!includeHiddenFiles) {
const globberWithHidden = await glob.create(
searchPath,
getDefaultGlobOptions(true)
)
const rawSearchResultsWithHidden = await globberWithHidden.glob()

const hiddenFiles = rawSearchResultsWithHidden.filter(
file => !rawSearchResults.includes(file)
)

if (hiddenFiles.length > 0) {
warning(
`The path "${searchPath}" excluded ${hiddenFiles.length} hidden files. Set include-hidden-files to true to include these files.`
)
}
}

/*
Files are saved with case insensitivity. Uploading both a.txt and A.txt will files to be overwritten
Detect any files that could be overwritten for user awareness
Expand Down