This commit is contained in:
Mai Nakagawa 2025-05-02 10:25:09 +09:00 committed by GitHub
commit cd93a24ea2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View file

@ -386,6 +386,7 @@ describe('Search', () => {
}) })
it('Hidden files ignored by default', async () => { it('Hidden files ignored by default', async () => {
const warningSpy = jest.spyOn(core, 'warning')
const searchPath = path.join(root, '**/*') const searchPath = path.join(root, '**/*')
const searchResult = await findFilesToUpload(searchPath) const searchResult = await findFilesToUpload(searchPath)
@ -394,14 +395,19 @@ describe('Search', () => {
expect(searchResult.filesToUpload).not.toContain( expect(searchResult.filesToUpload).not.toContain(
fileInHiddenFolderInFolderA fileInHiddenFolderInFolderA
) )
expect(warningSpy).toHaveBeenCalledWith(
expect.stringMatching(/Set include-hidden-files to true to include these files.$/)
)
}) })
it('Hidden files included', async () => { it('Hidden files included', async () => {
const warningSpy = jest.spyOn(core, 'warning')
const searchPath = path.join(root, '**/*') const searchPath = path.join(root, '**/*')
const searchResult = await findFilesToUpload(searchPath, true) const searchResult = await findFilesToUpload(searchPath, true)
expect(searchResult.filesToUpload).toContain(hiddenFile) expect(searchResult.filesToUpload).toContain(hiddenFile)
expect(searchResult.filesToUpload).toContain(fileInHiddenFolderPath) expect(searchResult.filesToUpload).toContain(fileInHiddenFolderPath)
expect(searchResult.filesToUpload).toContain(fileInHiddenFolderInFolderA) expect(searchResult.filesToUpload).toContain(fileInHiddenFolderInFolderA)
expect(warningSpy).not.toHaveBeenCalled()
}) })
}) })

View file

@ -1,6 +1,6 @@
import * as glob from '@actions/glob' import * as glob from '@actions/glob'
import * as path from 'path' import * as path from 'path'
import {debug, info} from '@actions/core' import {debug, info, warning} from '@actions/core'
import {stat} from 'fs' import {stat} from 'fs'
import {dirname} from 'path' import {dirname} from 'path'
import {promisify} from 'util' import {promisify} from 'util'
@ -90,6 +90,27 @@ export async function findFilesToUpload(
) )
const rawSearchResults: string[] = await globber.glob() 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 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 Detect any files that could be overwritten for user awareness