Skip to content

Commit 20c7844

Browse files
committed
feat: support optional v prefix with directory separator config
- Removed deprecated action-metadata types and utility functions. - Introduced new metadata structure for action inputs in `metadata.ts`. - Updated configuration handling to support dynamic input mapping. - Enhanced tag processing to accommodate various directory separators. - Added tests for metadata input handling and error scenarios. - Improved regex patterns for module tag validation. - Updated action.yml to include new input parameters for tag directory separator and version prefix usage. - Refactored TerraformModule class to utilize new configuration settings for versioning.
1 parent 1a9de54 commit 20c7844

15 files changed

+417
-82
lines changed

__mocks__/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { ACTION_INPUTS, createConfigFromInputs } from '@/utils/action-metadata';
1+
import { setupTestInputs } from '@/tests/helpers/inputs';
22
import type { Config } from '@/types';
33
import type { ActionInputMetadata } from '@/types';
4-
import { setupTestInputs } from '@/tests/helpers/inputs';
4+
import { ACTION_INPUTS, createConfigFromInputs } from '@/utils/metadata';
55

66
/**
77
* Configuration interface with added utility methods

__tests__/config.test.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
setupTestInputs,
1010
stringInputs,
1111
} from '@/tests/helpers/inputs';
12+
import { VALID_TAG_DIRECTORY_SEPARATORS } from '@/utils/constants';
1213
import { endGroup, getBooleanInput, getInput, info, startGroup } from '@actions/core';
1314
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
1415

@@ -191,22 +192,32 @@ describe('config', () => {
191192

192193
it('should throw error for invalid tag directory separator length', () => {
193194
setupTestInputs({ 'tag-directory-separator': 'ab' });
194-
expect(() => getConfig()).toThrow(
195-
new TypeError('Tag directory separator must be exactly one character'),
196-
);
195+
expect(() => getConfig()).toThrow(new TypeError('Tag directory separator must be exactly one character'));
197196
});
198197

199198
it('should throw error for invalid tag directory separator character', () => {
200199
setupTestInputs({ 'tag-directory-separator': '@' });
201200
expect(() => getConfig()).toThrow(
202-
new TypeError("Tag directory separator must be one of: -, _, /, .. Got: '@'"),
201+
new TypeError(`Tag directory separator must be one of: ${VALID_TAG_DIRECTORY_SEPARATORS.join(', ')}. Got: '@'`),
203202
);
204203
});
205204

205+
it('should allow valid tag directory separators', () => {
206+
for (const separator of VALID_TAG_DIRECTORY_SEPARATORS) {
207+
clearConfigForTesting();
208+
vi.unstubAllEnvs();
209+
setupTestInputs({ 'tag-directory-separator': separator });
210+
const config = getConfig();
211+
expect(config.tagDirectorySeparator).toBe(separator);
212+
}
213+
});
214+
206215
it('should throw error for invalid default first tag format', () => {
207216
setupTestInputs({ 'default-first-tag': 'invalid-tag' });
208217
expect(() => getConfig()).toThrow(
209-
new TypeError("Default first tag must be in format v#.#.# or #.#.# (e.g., v1.0.0 or 1.0.0). Got: 'invalid-tag'"),
218+
new TypeError(
219+
"Default first tag must be in format v#.#.# or #.#.# (e.g., v1.0.0 or 1.0.0). Got: 'invalid-tag'",
220+
),
210221
);
211222

212223
clearConfigForTesting();
@@ -229,7 +240,7 @@ describe('config', () => {
229240
it('should initialize with valid default inputs', () => {
230241
const config = getConfig();
231242

232-
expect(config.majorKeywords).toEqual(['major change', 'breaking change', '!']);
243+
expect(config.majorKeywords).toEqual(['major change', 'breaking change']);
233244
expect(config.minorKeywords).toEqual(['feat', 'feature']);
234245
expect(config.patchKeywords).toEqual(['fix', 'chore', 'docs']);
235246
expect(config.defaultFirstTag).toBe('v1.0.0');
@@ -250,7 +261,7 @@ describe('config', () => {
250261
expect(startGroup).toHaveBeenCalledTimes(1);
251262
expect(endGroup).toHaveBeenCalledTimes(1);
252263
expect(vi.mocked(info).mock.calls).toEqual([
253-
['Major Keywords: major change, breaking change, !'],
264+
['Major Keywords: major change, breaking change'],
254265
['Minor Keywords: feat, feature'],
255266
['Patch Keywords: fix, chore, docs'],
256267
['Default First Tag: v1.0.0'],

__tests__/context.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('context', () => {
4848
it(`should throw an error if ${envVar} is not set`, () => {
4949
// Set the specific environment variable to undefined, but keep others set
5050
vi.stubEnv(envVar, undefined);
51-
51+
5252
expect(() => getContext()).toThrow(
5353
new Error(
5454
`The ${envVar} environment variable is missing or invalid. This variable should be automatically set by GitHub for each workflow run. If this variable is missing or not correctly set, it indicates a serious issue with the GitHub Actions environment, potentially affecting the execution of subsequent steps in the workflow. Please review the workflow setup or consult the documentation for proper configuration.`,
@@ -60,7 +60,6 @@ describe('context', () => {
6060

6161
describe('event validation', () => {
6262
it('should throw error when event is not pull_request', () => {
63-
6463
vi.stubEnv('GITHUB_EVENT_NAME', 'push');
6564
expect(() => getContext()).toThrow('This workflow is not running in the context of a pull request');
6665
});
@@ -196,7 +195,6 @@ describe('context', () => {
196195
// Ensure GITHUB_API_URL is not set to test the default fallback
197196
vi.stubEnv('GITHUB_API_URL', undefined);
198197

199-
200198
const context = getContext();
201199

202200
// Check that the context was created with default API URL

__tests__/helpers/action-defaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from 'node:fs';
22
import * as path from 'node:path';
3-
import { ACTION_INPUTS } from '@/utils/action-metadata';
3+
import { ACTION_INPUTS } from '@/utils/metadata';
44
import * as yaml from 'js-yaml';
55

66
/**

__tests__/helpers/inputs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getActionDefaults } from '@/tests/helpers/action-defaults';
22
import type { Config } from '@/types';
3-
import { ACTION_INPUTS } from '@/utils/action-metadata';
3+
import { ACTION_INPUTS } from '@/utils/metadata';
44
import { vi } from 'vitest';
55

66
// Load action defaults once globally

0 commit comments

Comments
 (0)