| 
									
										
										
										
											2023-08-24 11:01:45 -07:00
										 |  |  | import * as core from '../node_modules/@actions/core/' | 
					
						
							| 
									
										
										
										
											2023-12-07 14:53:07 -05:00
										 |  |  | import artifact, { | 
					
						
							|  |  |  |   UploadArtifactOptions | 
					
						
							| 
									
										
										
										
											2023-11-20 11:08:50 -05:00
										 |  |  | } from '../node_modules/@actions/artifact/lib/artifact' | 
					
						
							| 
									
										
										
										
											2020-04-28 17:18:53 +02:00
										 |  |  | import {findFilesToUpload} from './search' | 
					
						
							| 
									
										
										
										
											2020-07-31 17:27:37 +02:00
										 |  |  | import {getInputs} from './input-helper' | 
					
						
							|  |  |  | import {NoFileOptions} from './constants' | 
					
						
							| 
									
										
										
										
											2020-04-28 17:18:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | async function run(): Promise<void> { | 
					
						
							|  |  |  |   try { | 
					
						
							| 
									
										
										
										
											2020-07-31 17:27:37 +02:00
										 |  |  |     const inputs = getInputs() | 
					
						
							|  |  |  |     const searchResult = await findFilesToUpload(inputs.searchPath) | 
					
						
							| 
									
										
										
										
											2020-04-28 17:18:53 +02:00
										 |  |  |     if (searchResult.filesToUpload.length === 0) { | 
					
						
							| 
									
										
										
										
											2020-07-31 17:27:37 +02:00
										 |  |  |       // No files were found, different use cases warrant different types of behavior if nothing is found
 | 
					
						
							|  |  |  |       switch (inputs.ifNoFilesFound) { | 
					
						
							|  |  |  |         case NoFileOptions.warn: { | 
					
						
							|  |  |  |           core.warning( | 
					
						
							|  |  |  |             `No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.` | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |           break | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         case NoFileOptions.error: { | 
					
						
							|  |  |  |           core.setFailed( | 
					
						
							|  |  |  |             `No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.` | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |           break | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         case NoFileOptions.ignore: { | 
					
						
							|  |  |  |           core.info( | 
					
						
							|  |  |  |             `No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.` | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |           break | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-04-28 17:18:53 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2021-01-04 12:24:12 +02:00
										 |  |  |       const s = searchResult.filesToUpload.length === 1 ? '' : 's' | 
					
						
							| 
									
										
										
										
											2020-04-28 17:18:53 +02:00
										 |  |  |       core.info( | 
					
						
							| 
									
										
										
										
											2021-01-04 12:24:12 +02:00
										 |  |  |         `With the provided path, there will be ${searchResult.filesToUpload.length} file${s} uploaded` | 
					
						
							| 
									
										
										
										
											2020-04-28 17:18:53 +02:00
										 |  |  |       ) | 
					
						
							|  |  |  |       core.debug(`Root artifact directory is ${searchResult.rootDirectory}`) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-04 15:40:37 -05:00
										 |  |  |       const options: UploadArtifactOptions = {} | 
					
						
							| 
									
										
										
										
											2020-08-27 13:39:36 -04:00
										 |  |  |       if (inputs.retentionDays) { | 
					
						
							|  |  |  |         options.retentionDays = inputs.retentionDays | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-20 11:08:50 -05:00
										 |  |  |       if (typeof inputs.compressionLevel !== 'undefined') { | 
					
						
							|  |  |  |         options.compressionLevel = inputs.compressionLevel | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-07 14:53:07 -05:00
										 |  |  |       const uploadResponse = await artifact.uploadArtifact( | 
					
						
							| 
									
										
										
										
											2020-07-31 17:27:37 +02:00
										 |  |  |         inputs.artifactName, | 
					
						
							| 
									
										
										
										
											2020-04-28 17:18:53 +02:00
										 |  |  |         searchResult.filesToUpload, | 
					
						
							|  |  |  |         searchResult.rootDirectory, | 
					
						
							|  |  |  |         options | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-07 14:53:07 -05:00
										 |  |  |       core.info( | 
					
						
							|  |  |  |         `Artifact ${inputs.artifactName} has been successfully uploaded! Final size is ${uploadResponse.size} bytes. Artifact ID is ${uploadResponse.id}` | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |       core.setOutput('artifact-id', uploadResponse.id) | 
					
						
							| 
									
										
										
										
											2020-04-28 17:18:53 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-01-05 16:27:11 -05:00
										 |  |  |   } catch (error) { | 
					
						
							|  |  |  |     core.setFailed((error as Error).message) | 
					
						
							| 
									
										
										
										
											2020-04-28 17:18:53 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | run() |