add support for multiple paths in path input variable
This allows users to provide multiple filepaths to include in their action, whether they're files or folders.
This commit is contained in:
+28
-12
@@ -23,6 +23,7 @@ let createTempDirMock: jest.SpyInstance
|
||||
let isDirectoryMock: jest.SpyInstance
|
||||
let createArchivesMock: jest.SpyInstance
|
||||
let removeDirMock: jest.SpyInstance
|
||||
let bundleFilesintoDirectoryMock: jest.SpyInstance
|
||||
|
||||
// Mock the GHCR Client
|
||||
let publishOCIArtifactMock: jest.SpyInstance
|
||||
@@ -45,6 +46,9 @@ describe('action', () => {
|
||||
.spyOn(fsHelper, 'createArchives')
|
||||
.mockImplementation()
|
||||
removeDirMock = jest.spyOn(fsHelper, 'removeDir').mockImplementation()
|
||||
bundleFilesintoDirectoryMock = jest
|
||||
.spyOn(fsHelper, 'bundleFilesintoDirectory')
|
||||
.mockImplementation()
|
||||
|
||||
// GHCR Client mocks
|
||||
publishOCIArtifactMock = jest
|
||||
@@ -97,7 +101,7 @@ describe('action', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('fails if path is not a directory', async () => {
|
||||
it('fails if multiple paths are provided and staging files fails', async () => {
|
||||
// Mock the environment
|
||||
process.env.GITHUB_REPOSITORY = 'test/test'
|
||||
github.context.eventName = 'release'
|
||||
@@ -109,23 +113,24 @@ describe('action', () => {
|
||||
}
|
||||
getInputMock.mockImplementation((name: string) => {
|
||||
if (name === 'path') {
|
||||
return 'not-a-directory'
|
||||
return 'directory1 directory2'
|
||||
} else if (name === 'registry') {
|
||||
return 'https://ghcr.io'
|
||||
}
|
||||
return ''
|
||||
})
|
||||
|
||||
isDirectoryMock.mockImplementation(() => false)
|
||||
isDirectoryMock.mockImplementation(() => true)
|
||||
|
||||
bundleFilesintoDirectoryMock.mockImplementation(() => {
|
||||
throw new Error('Something went wrong')
|
||||
})
|
||||
|
||||
// Run the action
|
||||
await main.run()
|
||||
|
||||
// Check the results
|
||||
expect(isDirectoryMock).toHaveBeenCalledWith('not-a-directory')
|
||||
expect(setFailedMock).toHaveBeenCalledWith(
|
||||
'The path not-a-directory is not a directory. Please provide a path to a valid directory.'
|
||||
)
|
||||
expect(setFailedMock).toHaveBeenCalledWith('Something went wrong')
|
||||
})
|
||||
|
||||
it('fails if an error is thrown from dependent code', async () => {
|
||||
@@ -167,16 +172,20 @@ describe('action', () => {
|
||||
})
|
||||
|
||||
it('successfully uploads if the release tag is a semver without v prefix', async () => {
|
||||
await testHappyPath('1.0.0')
|
||||
await testHappyPath('1.0.0', 'test')
|
||||
})
|
||||
|
||||
it('successfully uploads if the release tag is a semver with v prefix', async () => {
|
||||
await testHappyPath('v1.0.0')
|
||||
await testHappyPath('v1.0.0', 'test')
|
||||
})
|
||||
|
||||
it('successfully uploads if multiple paths are provided', async () => {
|
||||
await testHappyPath('v1.0.0', 'test test2')
|
||||
})
|
||||
})
|
||||
|
||||
// Test that main successfully uploads and returns the manifest & package URL
|
||||
async function testHappyPath(version: string): Promise<void> {
|
||||
async function testHappyPath(version: string, path: string): Promise<void> {
|
||||
// Mock the environment
|
||||
process.env.GITHUB_REPOSITORY = 'test/test'
|
||||
github.context.eventName = 'release'
|
||||
@@ -188,7 +197,7 @@ async function testHappyPath(version: string): Promise<void> {
|
||||
}
|
||||
getInputMock.mockImplementation((name: string) => {
|
||||
if (name === 'path') {
|
||||
return 'test'
|
||||
return path
|
||||
} else if (name === 'registry') {
|
||||
return 'https://ghcr.io'
|
||||
}
|
||||
@@ -197,6 +206,10 @@ async function testHappyPath(version: string): Promise<void> {
|
||||
|
||||
isDirectoryMock.mockImplementation(() => true)
|
||||
|
||||
bundleFilesintoDirectoryMock.mockImplementation(() => {
|
||||
return '/tmp/test'
|
||||
})
|
||||
|
||||
createTempDirMock.mockImplementation(() => '/tmp/test')
|
||||
|
||||
createArchivesMock.mockImplementation(() => {
|
||||
@@ -246,6 +259,9 @@ async function testHappyPath(version: string): Promise<void> {
|
||||
'actions_oci_pkg'
|
||||
)
|
||||
|
||||
// Expect the files to be cleaned up
|
||||
// Expect all the temp files to be cleaned up
|
||||
expect(removeDirMock).toHaveBeenCalledWith('/tmp/test')
|
||||
expect(removeDirMock).toHaveBeenCalledTimes(
|
||||
createTempDirMock.mock.calls.length
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user