Skip to content

Commit e07b1e9

Browse files
committed
Add tests and update dependencies
1 parent cb3db63 commit e07b1e9

20 files changed

+420
-137
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up Node.js
1616
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
1717
with:
18-
node-version: 20
18+
node-version: 23
1919
cache: npm
2020

2121
- name: Install dependencies
@@ -36,7 +36,7 @@ jobs:
3636
- name: Set up Node.js
3737
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
3838
with:
39-
node-version: 20
39+
node-version: 23
4040
cache: npm
4141

4242
- name: Install dependencies

dist/index.js

Lines changed: 43 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/interfaces/index.d.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,56 @@
11
/**
2-
* Interface for Google Cloud Storage bucket upload options
2+
* @fileoverview Type definitions and interfaces for the terraform-module-gcs-publisher.
3+
* This module contains TypeScript interfaces that define the structure for module options,
4+
* GCS bucket options, and other data structures used throughout the application.
5+
*
6+
* @author Infraspec
7+
* @license MIT
8+
*/
9+
/**
10+
* Interface for Google Cloud Storage bucket upload options.
11+
* These options are used when uploading files to a GCS bucket.
312
*/
413
export interface GCSBucketOptions {
14+
/** Destination path within the bucket where the file will be stored */
515
destination: string;
16+
/** Metadata to associate with the uploaded file */
617
metadata: {
18+
/** MIME type of the file, typically 'application/zip' for module archives */
719
contentType: string;
20+
/** Cache control header, affects how the file is cached by browsers and CDNs */
821
cacheControl: string;
22+
/** Custom metadata fields that provide additional information about the file */
923
metadata: {
24+
/** SHA-256 hash of the file for integrity verification */
1025
sha256Hash: string;
26+
/** Identifier for the uploader, typically the action name */
1127
uploadedBy: string;
28+
/** ISO timestamp when the upload occurred */
1229
uploadTimestamp: string;
1330
};
1431
};
32+
/** Validation method to use during upload (e.g., 'crc32c') */
1533
validation: string;
34+
/** Whether to use resumable uploads, typically set to false for smaller files */
1635
resumable: boolean;
1736
}
1837
/**
19-
* Interface for module publishing options
38+
* Interface for module publishing options.
39+
* These options control how a Terraform module is published to GCS.
2040
*/
2141
export interface ModuleOptions {
42+
/** Name of the GCS bucket to upload to (must follow GCS naming rules) */
2243
bucketName: string;
44+
/** Name of the Terraform module (used in path construction and file naming) */
2345
moduleName: string;
46+
/** Semantic version of the module (e.g., '1.0.0') */
2447
moduleVersion: string;
48+
/** Local filesystem path to the module directory */
2549
modulePath: string;
50+
/** Google Cloud credentials JSON content for authentication */
2651
googleCredentialsJson: string;
52+
/** Whether to delete older versions of the same module */
2753
deleteOldVersions: boolean;
54+
/** Number of recent versions to retain when cleaning up old versions */
2855
keepVersions: number;
2956
}

dist/interfaces/index.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/interfaces/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main.d.ts

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,84 @@
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+
*/
111
import { GCSService } from './services/gcs-service';
212
import { ModuleOptions } from './interfaces';
313
/**
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.
517
*
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
924
*/
1025
declare function createZipArchive(sourcePath: string, outputPath: string): Promise<string>;
1126
/**
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.
1330
*
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
1534
*/
1635
declare function getValidatedInputs(): ModuleOptions;
1736
/**
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.
1940
*
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
2147
*/
2248
declare function validateInputs(options: ModuleOptions): void;
2349
/**
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.
2553
*
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
2858
*/
2959
declare function createTempCredentialsFile(credentialsJson: string): string;
3060
/**
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.
3264
*
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)
3772
*/
3873
declare function processModuleUpload(options: ModuleOptions, gcsService: GCSService, zipFilePath: string): Promise<string>;
3974
/**
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
4182
*/
4283
declare function run(): Promise<void>;
4384
export { run, createZipArchive, getValidatedInputs, validateInputs, createTempCredentialsFile, processModuleUpload };

dist/main.js

Lines changed: 60 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)