|
| 1 | +/** |
| 2 | + * @fileoverview Main entry point for the terraform-module-gcs-publisher GitHub Action. |
| 3 | + * This module handles publishing Terraform modules to Google Cloud Storage with proper |
| 4 | + * versioning, metadata, and cleanup of old versions. It implements the core functionality |
| 5 | + * required by the action including input validation, file handling, GCS uploads, and |
| 6 | + * version management. |
| 7 | + * |
| 8 | + * @author Infraspec |
| 9 | + * @license MIT |
| 10 | + */ |
1 | 11 | import { GCSService } from './services/gcs-service';
|
2 | 12 | import { ModuleOptions } from './interfaces';
|
3 | 13 | /**
|
4 |
| - * Creates a zip archive of the module |
| 14 | + * Creates a zip archive of the module for uploading to Google Cloud Storage. |
| 15 | + * This function uses the system's zip command to create an archive while excluding |
| 16 | + * git-related files and other unnecessary metadata files. |
5 | 17 | *
|
6 |
| - * @param sourcePath - Path to the module to be archived |
7 |
| - * @param outputPath - Path where the archive will be created |
8 |
| - * @returns The path to the created archive |
| 18 | + * @param sourcePath - Path to the module directory to be archived |
| 19 | + * @param outputPath - Path where the zip archive will be created |
| 20 | + * @returns The path to the created zip archive |
| 21 | + * @throws {Error} When the source path doesn't exist or isn't accessible |
| 22 | + * @throws {Error} When the zip command fails to execute properly |
| 23 | + * @throws {Error} When the output zip file cannot be created or verified |
9 | 24 | */
|
10 | 25 | declare function createZipArchive(sourcePath: string, outputPath: string): Promise<string>;
|
11 | 26 | /**
|
12 |
| - * Parses and validates all input parameters |
| 27 | + * Parses and validates all input parameters from the GitHub Actions environment. |
| 28 | + * This function extracts inputs using the @actions/core library and constructs |
| 29 | + * a validated ModuleOptions object ready for use in the module publishing process. |
13 | 30 | *
|
14 |
| - * @returns Validated module options |
| 31 | + * @returns Validated module options object with all required properties set |
| 32 | + * @throws {Error} When required inputs are missing from the GitHub Actions context |
| 33 | + * @throws {Error} When inputs fail validation via the validateInputs function |
15 | 34 | */
|
16 | 35 | declare function getValidatedInputs(): ModuleOptions;
|
17 | 36 | /**
|
18 |
| - * Validates the input parameters |
| 37 | + * Validates the input parameters to the GitHub Action. |
| 38 | + * This function performs comprehensive validation on all input parameters including |
| 39 | + * format validation, existence checks, and semantic version validation. |
19 | 40 | *
|
20 |
| - * @param options - Module options to validate |
| 41 | + * @param options - Module options object containing all parameters to validate |
| 42 | + * @throws {Error} When the bucket name doesn't conform to GCS naming rules |
| 43 | + * @throws {Error} When the module name contains invalid characters |
| 44 | + * @throws {Error} When the module path doesn't exist on the filesystem |
| 45 | + * @throws {Error} When the module version isn't a valid semantic version format |
| 46 | + * @throws {Error} When the keepVersions parameter is not a positive integer |
21 | 47 | */
|
22 | 48 | declare function validateInputs(options: ModuleOptions): void;
|
23 | 49 | /**
|
24 |
| - * Creates a temporary file for Google credentials |
| 50 | + * Creates a temporary file for Google credentials. |
| 51 | + * This function validates the JSON format of the credentials and writes them to a |
| 52 | + * temporary file that can be used by the Google Cloud Storage client library. |
25 | 53 | *
|
26 |
| - * @param credentialsJson - Google credentials JSON string |
27 |
| - * @returns Path to the created credentials file |
| 54 | + * @param credentialsJson - Google credentials JSON string containing service account information |
| 55 | + * @returns Path to the created temporary credentials file |
| 56 | + * @throws {Error} When the credentials JSON is invalid or cannot be parsed |
| 57 | + * @throws {Error} When the temporary file cannot be created due to file system errors |
28 | 58 | */
|
29 | 59 | declare function createTempCredentialsFile(credentialsJson: string): string;
|
30 | 60 | /**
|
31 |
| - * Processes the module upload and related operations |
| 61 | + * Processes the module upload and related operations. |
| 62 | + * This function calculates the file hash, performs the upload operation, |
| 63 | + * and handles cleanup of old versions if requested in the options. |
32 | 64 | *
|
33 |
| - * @param options - Module options |
34 |
| - * @param gcsService - GCS service instance |
35 |
| - * @param zipFilePath - Path to the zip file to upload |
36 |
| - * @returns URL to the uploaded module |
| 65 | + * @param options - Module options containing bucket name, module name, and version information |
| 66 | + * @param gcsService - GCS service instance for interacting with Google Cloud Storage |
| 67 | + * @param zipFilePath - Path to the local zip file to be uploaded |
| 68 | + * @returns URL to the uploaded module in Google Cloud Storage (gs:// format) |
| 69 | + * @throws {Error} When file hash calculation fails due to file system errors |
| 70 | + * @throws {Error} When the upload to GCS fails due to authentication or network issues |
| 71 | + * @throws {Error} When cleanup of old versions fails (if deleteOldVersions is true) |
37 | 72 | */
|
38 | 73 | declare function processModuleUpload(options: ModuleOptions, gcsService: GCSService, zipFilePath: string): Promise<string>;
|
39 | 74 | /**
|
40 |
| - * Main function that runs the action |
| 75 | + * Main function that runs the GitHub Action for publishing Terraform modules to GCS. |
| 76 | + * This is the entry point for the action that handles the entire process from reading |
| 77 | + * inputs, validating parameters, creating the zip archive, and uploading to GCS. |
| 78 | + * |
| 79 | + * @throws {Error} When required inputs are missing or invalid |
| 80 | + * @throws {Error} When zip creation fails due to file system issues |
| 81 | + * @throws {Error} When GCS authentication or upload operations fail |
41 | 82 | */
|
42 | 83 | declare function run(): Promise<void>;
|
43 | 84 | export { run, createZipArchive, getValidatedInputs, validateInputs, createTempCredentialsFile, processModuleUpload };
|
0 commit comments