Skip to content

Commit ee65bd0

Browse files
committed
tests(tags): update tags module with testing and improvements
- Added test suite for tags functionality - Updated documentation for tags - Added test helpers for inputs and Octokit - Fully mocked @actions/core for isolated testing - Improved path aliasing using `@/` for all local packages - Ensured consistent use of named imports throughout
1 parent aaf2352 commit ee65bd0

38 files changed

+1483
-695
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"[json]": {
3131
"editor.defaultFormatter": "biomejs.biome"
3232
},
33+
"[jsonc]": {
34+
"editor.defaultFormatter": "biomejs.biome"
35+
},
3336
"[markdown]": {
3437
"editor.defaultFormatter": "esbenp.prettier-vscode"
3538
},

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,19 @@ resources.
169169
While the out-of-the-box defaults are suitable for most use cases, you can further customize the action's behavior by
170170
configuring the following optional input parameters as needed.
171171

172-
| Input | Description | Default |
173-
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- |
174-
| `major-keywords` | Keywords in commit messages that indicate a major release | `major change,breaking change` |
175-
| `minor-keywords` | Keywords in commit messages that indicate a minor release | `feat,feature` |
176-
| `patch-keywords` | Keywords in commit messages that indicate a patch release | `fix,chore,docs` |
177-
| `default-first-tag` | Specifies the default tag version | `v1.0.0` |
178-
| `terraform-docs-version` | Specifies the terraform-docs version used to generate documentation for the wiki | `v0.19.0` |
179-
| `delete-legacy-tags` | Specifies a boolean that determines whether tags and releases from Terraform modules that have been deleted should be automatically removed | `true` |
180-
| `disable-wiki` | Whether to disable wiki generation for Terraform modules | `false` |
181-
| `wiki-sidebar-changelog-max` | An integer that specifies how many changelog entries are displayed in the sidebar per module | `5` |
182-
| `disable-branding` | Controls whether a small branding link to the action's repository is added to PR comments. Recommended to leave enabled to support OSS. | `false` |
183-
| `module-change-exclude-patterns` | A comma-separated list of file patterns to exclude from triggering version changes in Terraform modules. Patterns follow glob syntax (e.g., `.gitignore,_.md`) and are relative to each Terraform module directory. Files matching these patterns will not affect version changes. **WARNING**: Avoid excluding '`_.tf`' files, as they are essential for module detection and versioning processes. | `.gitignore, *.md, *.tftest.hcl, tests/**` |
184-
| `module-asset-exclude-patterns` | A comma-separated list of file patterns to exclude when bundling a Terraform module for tag/release. Patterns follow glob syntax (e.g., `tests/\*\*`) and are relative to each Terraform module directory. Files matching these patterns will be excluded from the bundled output. | `".gitignore, *.md, *.tftest.hcl, tests/**"` |
172+
| Input | Description | Default |
173+
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
174+
| `major-keywords` | Keywords in commit messages that indicate a major release | `major change,breaking change` |
175+
| `minor-keywords` | Keywords in commit messages that indicate a minor release | `feat,feature` |
176+
| `patch-keywords` | Keywords in commit messages that indicate a patch release | `fix,chore,docs` |
177+
| `default-first-tag` | Specifies the default tag version | `v1.0.0` |
178+
| `terraform-docs-version` | Specifies the terraform-docs version used to generate documentation for the wiki | `v0.19.0` |
179+
| `delete-legacy-tags` | Specifies a boolean that determines whether tags and releases from Terraform modules that have been deleted should be automatically removed | `true` |
180+
| `disable-wiki` | Whether to disable wiki generation for Terraform modules | `false` |
181+
| `wiki-sidebar-changelog-max` | An integer that specifies how many changelog entries are displayed in the sidebar per module | `5` |
182+
| `disable-branding` | Controls whether a small branding link to the action's repository is added to PR comments. Recommended to leave enabled to support OSS. | `false` |
183+
| `module-change-exclude-patterns` | A comma-separated list of file patterns to exclude from triggering version changes in Terraform modules. Patterns follow glob syntax (e.g., `.gitignore,_.md`) and are relative to each Terraform module directory. Files matching these patterns will not affect version changes. **WARNING**: Avoid excluding '`_.tf`' files, as they are essential for module detection and versioning processes. | `.gitignore, *.md, *.tftest.hcl, tests/**` |
184+
| `module-asset-exclude-patterns` | A comma-separated list of file patterns to exclude when bundling a Terraform module for tag/release. Patterns follow glob syntax (e.g., `tests/\*\*`) and are relative to each Terraform module directory. Files matching these patterns will be excluded from the bundled output. | `.gitignore, *.md, *.tftest.hcl, tests/**` |
185185

186186
### Example Usage with Inputs
187187

__mocks__/@actions/core.ts

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
import type { AnnotationProperties, ExitCode, InputOptions } from 'node_modules/@actions/core';
2+
import { vi } from 'vitest';
3+
import type { Mock } from 'vitest';
4+
5+
// Import the actual module
6+
const actual = await vi.importActual<typeof import('node_modules/@actions/core')>('@actions/core');
7+
8+
// Strictly typed MockedFunction helper that only applies to function types
9+
type MockedFunction<TFunc> = TFunc extends (...args: infer TArgs) => infer TReturn
10+
? Mock<(...args: TArgs) => TReturn> & TFunc
11+
: never;
12+
13+
/**
14+
* Writes a debug message to the user log.
15+
* @param message - The debug message to log.
16+
*/
17+
export const debug: MockedFunction<(message: string) => void> = vi.fn((message: string): void => {});
18+
19+
/**
20+
* Writes an informational message to the log.
21+
* @param message - The info message to log.
22+
*/
23+
export const info: MockedFunction<(message: string) => void> = vi.fn((message: string): void => {});
24+
25+
/**
26+
* Adds a warning issue with optional annotation properties.
27+
* @param message - The warning message or error.
28+
* @param properties - Optional properties to add to the annotation.
29+
*/
30+
export const warning: MockedFunction<(message: string | Error, properties?: AnnotationProperties) => void> = vi.fn(
31+
(message: string | Error, properties?: AnnotationProperties): void => {},
32+
);
33+
34+
/**
35+
* Adds a notice issue with optional annotation properties.
36+
* @param message - The notice message or error.
37+
* @param properties - Optional properties to add to the annotation.
38+
*/
39+
export const notice: MockedFunction<(message: string | Error, properties?: AnnotationProperties) => void> = vi.fn(
40+
(message: string | Error, properties?: AnnotationProperties): void => {},
41+
);
42+
43+
/**
44+
* Adds an error issue with optional annotation properties.
45+
* @param message - The error message or error.
46+
* @param properties - Optional properties to add to the annotation.
47+
*/
48+
export const error: MockedFunction<(message: string | Error, properties?: AnnotationProperties) => void> = vi.fn(
49+
(message: string | Error, properties?: AnnotationProperties): void => {},
50+
);
51+
52+
/**
53+
* Sets the action status to failed.
54+
* When the action exits it will be with an exit code of 1.
55+
* @param message - The error message or object.
56+
* @throws An error with the specified message.
57+
*/
58+
export const setFailed: MockedFunction<(message: string | Error) => void> = vi.fn((message: string | Error) => {
59+
actual.setFailed(message);
60+
});
61+
62+
/**
63+
* Begins a new output group. Output until the next `endGroup` will be foldable in this group.
64+
* @param name - The name of the output group.
65+
*/
66+
export const startGroup: MockedFunction<(name: string) => void> = vi.fn((name: string): void => {});
67+
68+
/**
69+
* Ends the current output group.
70+
*/
71+
export const endGroup: MockedFunction<() => void> = vi.fn((): void => {});
72+
73+
/**
74+
* Gets the value of an input. Will return an empty string if the input is not defined.
75+
* @param name - Name of the input to get
76+
* @param options - Optional. See InputOptions.
77+
* @returns string
78+
*/
79+
export const getInput: MockedFunction<(name: string, options?: InputOptions) => string> = vi.fn(
80+
(name: string, options?: InputOptions): string => {
81+
return actual.getInput(name, options);
82+
},
83+
);
84+
85+
/**
86+
* Gets the input value of the boolean type in the YAML 1.2 "core schema" specification.
87+
* Supported boolean input list: `true | True | TRUE | false | False | FALSE`
88+
* @param name - Name of the input to get
89+
* @param options - Optional. See InputOptions.
90+
* @returns boolean
91+
*/
92+
export const getBooleanInput: MockedFunction<(name: string, options?: InputOptions) => boolean> = vi.fn(
93+
(name: string, options?: InputOptions): boolean => {
94+
return actual.getBooleanInput(name, options);
95+
},
96+
);
97+
98+
/**
99+
* Gets the values of an multiline input. Each value will be trimmed.
100+
* @param name - Name of the input to get
101+
* @param options - Optional. See InputOptions.
102+
* @returns string[]
103+
*/
104+
export const getMultilineInput: MockedFunction<(name: string, options?: InputOptions) => string[]> = vi.fn(
105+
(name: string, options?: InputOptions): string[] => {
106+
return actual.getMultilineInput(name, options);
107+
},
108+
);
109+
110+
/**
111+
* Masks a value in the log. When the masked value appears in the log, it is replaced with asterisks.
112+
* @param secret - Value to mask
113+
*/
114+
export const setSecret: MockedFunction<(secret: string) => void> = vi.fn((secret: string): void => {});
115+
116+
/**
117+
* Prepends the given path to the PATH environment variable.
118+
* @param inputPath - Path to prepend
119+
*/
120+
export const addPath: MockedFunction<(inputPath: string) => void> = vi.fn((inputPath: string): void => {});
121+
122+
/**
123+
* Sets env variable for this action and future actions in the job.
124+
* @param name - Name of the variable to set
125+
* @param val - Value of the variable
126+
*/
127+
export const exportVariable: MockedFunction<(name: string, val: string) => void> = vi.fn(
128+
(name: string, val: string): void => {},
129+
);
130+
131+
/**
132+
* Enables or disables the echoing of commands into stdout for the rest of the step.
133+
* @param enabled - True to enable echoing, false to disable
134+
*/
135+
export const setCommandEcho: MockedFunction<(enabled: boolean) => void> = vi.fn((enabled: boolean): void => {});
136+
137+
/**
138+
* Begin an output group.
139+
* @param name - Name of the output group
140+
* @param fn - Function to execute within the output group
141+
*/
142+
export const group: MockedFunction<(name: string, fn: () => Promise<void>) => Promise<void>> = vi.fn(
143+
async (name: string, fn: () => Promise<void>): Promise<void> => {
144+
await fn();
145+
},
146+
);
147+
148+
/**
149+
* Saves state for current action.
150+
* The state can only be retrieved by this action's post job execution.
151+
* @param name - Name of the state to store
152+
* @param value - Value to store. Non-string values will be converted to a string via JSON.stringify
153+
*/
154+
export const saveState: MockedFunction<(name: string, value: string) => void> = vi.fn(
155+
(name: string, value: string): void => {},
156+
);
157+
158+
/**
159+
* Gets the value of an state set by this action's main execution.
160+
* @param name - Name of the state to get
161+
* @returns string
162+
*/
163+
export const getState: MockedFunction<(name: string) => string> = vi.fn((name: string): string => '');
164+
165+
/**
166+
* Gets whether Actions Step Debug is on or not
167+
* @returns boolean
168+
*/
169+
export const isDebug: MockedFunction<() => boolean> = vi.fn((): boolean => false);
170+
171+
/**
172+
* Gets the value of an OIDC token from the GitHub Actions runtime
173+
* @param audience - Optional audience for the token
174+
* @returns string
175+
*/
176+
export const getIDToken: MockedFunction<(audience?: string) => Promise<string>> = vi.fn(
177+
async (audience?: string): Promise<string> => '',
178+
);
179+
180+
/**
181+
* Sets the value of an output.
182+
* @param name - Name of the output to set
183+
* @param value - Value to store. Non-string values will be converted to a string via JSON.stringify
184+
*/
185+
export const setOutput: MockedFunction<(name: string, value: string) => void> = vi.fn(
186+
(name: string, value: string): void => {},
187+
);
188+
189+
// Re-export types
190+
export type { InputOptions, AnnotationProperties };
191+
export type { ExitCode };

0 commit comments

Comments
 (0)