Merge pull request #2 from GIgako19929/update-main-function

Update main function to process images and handle errors
This commit is contained in:
Giorgi Meskhidze 2025-02-03 11:48:42 -05:00 committed by GitHub
commit 5eedf3cf42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 0 deletions

View File

@ -1 +1,2 @@
20.6.0

View File

@ -183,4 +183,27 @@ describe('main', () => {
expect(outputs['predicate-type']).toBe('https://slsa.dev/provenance/v1')
})
})
describe('when an error occurs during processing', () => {
beforeEach(() => {
process.env = {
...originalEnv,
GITHUB_SERVER_URL: 'https://github.com',
GITHUB_REPOSITORY: 'owner/repo'
}
})
it('fails the workflow run', async () => {
jest.spyOn(core, 'getInput').mockImplementation((name) => {
if (name === 'subject-images') {
throw new Error('Test error')
}
return ''
})
await main.run()
expect(setFailedMock).toHaveBeenCalledWith('Test error')
})
})
})

View File

@ -14,6 +14,8 @@ export async function run(): Promise<void> {
for (const image of images) {
core.info(`Processing image: ${image}`)
// Add logic to process each image for attestation
// Assuming processImageForAttestation is a function that processes the image
await processImageForAttestation(image)
}
}
@ -28,3 +30,13 @@ export async function run(): Promise<void> {
core.setFailed(error.message)
}
}
/**
* Processes an image for attestation.
* @param {string} image - The image to process.
* @returns {Promise<void>} Resolves when the image is processed.
*/
async function processImageForAttestation(image: string): Promise<void> {
// Add the actual logic to process the image for attestation
core.info(`Image ${image} processed for attestation`)
}