|
9 | 9 | VALID_TAG_DIRECTORY_SEPARATORS, |
10 | 10 | VERSION_TAG_REGEX, |
11 | 11 | } from '@/utils/constants'; |
12 | | -import { removeTrailingCharacters } from '@/utils/string'; |
13 | 12 | import { endGroup, info, startGroup } from '@actions/core'; |
14 | 13 |
|
15 | 14 | /** |
@@ -224,7 +223,7 @@ export class TerraformModule { |
224 | 223 | return null; |
225 | 224 | } |
226 | 225 |
|
227 | | - const match = latestTag.match(MODULE_TAG_REGEX); |
| 226 | + const match = MODULE_TAG_REGEX.exec(latestTag); |
228 | 227 |
|
229 | 228 | return match ? match[3] : null; |
230 | 229 | } |
@@ -471,7 +470,7 @@ export class TerraformModule { |
471 | 470 | return null; |
472 | 471 | } |
473 | 472 |
|
474 | | - return `${this.name}/${releaseTagVersion}`; |
| 473 | + return `${this.name}${config.tagDirectorySeparator}${releaseTagVersion}`; |
475 | 474 | } |
476 | 475 |
|
477 | 476 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
@@ -617,29 +616,23 @@ export class TerraformModule { |
617 | 616 | * |
618 | 617 | * The function transforms the directory path by: |
619 | 618 | * - Trimming whitespace |
620 | | - * - Replacing invalid characters with hyphens |
621 | | - * - Normalizing slashes |
622 | | - * - Removing leading/trailing slashes |
623 | | - * - Handling consecutive dots and hyphens |
624 | | - * - Removing any remaining whitespace |
625 | 619 | * - Converting to lowercase (for consistency) |
626 | | - * - Removing trailing dots, hyphens, and underscores |
| 620 | + * - Normalizing path separators (both backslashes and forward slashes) to the configured tag directory separator |
| 621 | + * - Replacing invalid characters with hyphens (preserving only alphanumeric, "/", ".", "-", "_") |
| 622 | + * - Normalizing consecutive special characters ("/", ".", "-", "_") to single instances |
| 623 | + * - Removing leading/trailing special characters ("/", ".", "-", "_") |
627 | 624 | * |
628 | 625 | * @param {string} terraformDirectory - The relative directory path from which to generate the module name. |
629 | 626 | * @returns {string} A valid Terraform module name based on the provided directory path. |
630 | 627 | */ |
631 | 628 | public static getTerraformModuleNameFromRelativePath(terraformDirectory: string): string { |
632 | | - const cleanedDirectory = terraformDirectory |
| 629 | + return terraformDirectory |
633 | 630 | .trim() |
634 | | - .replace(/[^a-zA-Z0-9/_-]+/g, '-') |
635 | | - .replace(/\/{2,}/g, '/') |
636 | | - .replace(/\/\.+/g, '/') |
637 | | - .replace(/(^\/|\/$)/g, '') |
638 | | - .replace(/\.\.+/g, '.') |
639 | | - .replace(/--+/g, '-') |
640 | | - .replace(/\s+/g, '') |
641 | | - .toLowerCase(); |
642 | | - return removeTrailingCharacters(cleanedDirectory, ['.', '-', '_']); |
| 631 | + .toLowerCase() |
| 632 | + .replace(/[/\\]/g, config.tagDirectorySeparator) // Normalize backslashes and forward slashes to configured separator |
| 633 | + .replace(/[^a-zA-Z0-9/._-]+/g, '-') // Replace invalid characters with hyphens (preserve alphanumeric, /, ., _, -) |
| 634 | + .replace(/[/._-]{2,}/g, (match) => match[0]) // Normalize consecutive special characters to single instances |
| 635 | + .replace(/(^[/._-]+|[/._-]+$)/g, ''); // Remove leading/trailing special characters |
643 | 636 | } |
644 | 637 |
|
645 | 638 | /** |
|
0 commit comments