diff --git a/README.md b/README.md
index 191101eb..bc9046b3 100644
--- a/README.md
+++ b/README.md
@@ -199,6 +199,7 @@ configuring the following optional input parameters as needed.
| `module-change-exclude-patterns` | Comma-separated list of file patterns (relative to each module) to exclude from triggering version changes. Lets you release a module but control which files inside it do not force a version bump.
[Read more here](#understanding-the-filtering-options) | `.gitignore,*.md,*.tftest.hcl,tests/**` |
| `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/**` |
| `use-ssh-source-format` | If enabled, all links to source code in generated Wiki documentation will use SSH standard format (e.g., `git::ssh://git@github.com/owner/repo.git`) instead of HTTPS format (`git::https://github.com/owner/repo.git`) | `false` |
+| `target-branch` | The target branch to use for wiki operations. This allows supporting repositories that use 'main' instead of 'master' as their default branch. | `master` |
### Understanding the filtering options
diff --git a/__mocks__/config.ts b/__mocks__/config.ts
index 26a0a7e9..ae64a486 100644
--- a/__mocks__/config.ts
+++ b/__mocks__/config.ts
@@ -26,6 +26,7 @@ const defaultConfig: Config = {
moduleAssetExcludePatterns: ['tests/**', 'examples/**'],
githubToken: 'ghp_test_token_2c6912E7710c838347Ae178B4',
useSSHSourceFormat: false,
+ targetBranch: 'master',
};
/**
@@ -46,6 +47,7 @@ const validConfigKeys = [
'moduleAssetExcludePatterns',
'githubToken',
'useSSHSourceFormat',
+ 'targetBranch',
] as const;
type ValidConfigKey = (typeof validConfigKeys)[number];
diff --git a/__tests__/config.test.ts b/__tests__/config.test.ts
index be14bc22..606fc17d 100644
--- a/__tests__/config.test.ts
+++ b/__tests__/config.test.ts
@@ -155,6 +155,7 @@ describe('config', () => {
expect(config.moduleAssetExcludePatterns).toEqual(['tests/**', 'examples/**']);
expect(config.modulePathIgnore).toEqual(['tf-modules/kms/examples/complete']);
expect(config.useSSHSourceFormat).toBe(false);
+ expect(config.targetBranch).toBe('master');
expect(startGroup).toHaveBeenCalledWith('Initializing Config');
expect(startGroup).toHaveBeenCalledTimes(1);
expect(endGroup).toHaveBeenCalledTimes(1);
@@ -171,6 +172,7 @@ describe('config', () => {
['Module Change Exclude Patterns: .gitignore, *.md'],
['Module Asset Exclude Patterns: tests/**, examples/**'],
['Use SSH Source Format: false'],
+ ['Target Branch: master'],
]);
});
});
diff --git a/__tests__/helpers/inputs.ts b/__tests__/helpers/inputs.ts
index 5fa41ad0..e46c6b0e 100644
--- a/__tests__/helpers/inputs.ts
+++ b/__tests__/helpers/inputs.ts
@@ -22,6 +22,7 @@ export const inputToConfigKeyMap: Record = {
'module-change-exclude-patterns': 'moduleChangeExcludePatterns',
'module-asset-exclude-patterns': 'moduleAssetExcludePatterns',
'use-ssh-source-format': 'useSSHSourceFormat',
+ 'target-branch': 'targetBranch',
};
// Create reverse mapping from config keys to input names
@@ -49,6 +50,7 @@ export const defaultInputs = {
'module-asset-exclude-patterns': 'tests/**,examples/**',
github_token: 'ghp_test_token_2c6912E7710c838347Ae178B4',
'use-ssh-source-format': 'false',
+ 'target-branch': 'master',
};
export const requiredInputs = [
'major-keywords',
@@ -62,6 +64,7 @@ export const requiredInputs = [
'disable-branding',
'github_token',
'use-ssh-source-format',
+ 'target-branch',
];
export const optionalInputs = Object.keys(defaultInputs).filter((key) => !requiredInputs.includes(key));
export const booleanInputs = ['delete-legacy-tags', 'disable-wiki', 'disable-branding', 'use-ssh-source-format'];
@@ -73,7 +76,7 @@ export const arrayInputs = [
'module-change-exclude-patterns',
'module-asset-exclude-patterns',
];
-export const stringInputs = ['default-first-tag', 'terraform-docs-version', 'github_token'];
+export const stringInputs = ['default-first-tag', 'terraform-docs-version', 'github_token', 'target-branch'];
export const numberInputs = ['wiki-sidebar-changelog-max'];
/**
diff --git a/action.yml b/action.yml
index 124dd781..34142521 100644
--- a/action.yml
+++ b/action.yml
@@ -102,6 +102,12 @@ inputs:
If enabled, all links to source code in generated Wiki documentation will use SSH format instead of HTTPS format.
required: true
default: "false"
+ target-branch:
+ description: >
+ The target branch to use for wiki operations. This allows supporting repositories that use 'main'
+ instead of 'master' as their default branch.
+ required: true
+ default: "master"
github_token:
description: >
Required for retrieving pull request metadata, tags, releases, updating PR comments, wiki, and creating
diff --git a/package-lock.json b/package-lock.json
index 290b2ee1..243d6f93 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -27,7 +27,7 @@
"@vercel/ncc": "^0.38.3",
"@vitest/coverage-v8": "^3.1.3",
"make-coverage-badge": "^1.2.0",
- "openai": "*",
+ "openai": "latest",
"textlint": "^14.8.0",
"textlint-filter-rule-comments": "^1.2.2",
"textlint-rule-terminology": "^5.2.12",
diff --git a/src/config.ts b/src/config.ts
index 45390210..d8d40930 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -74,6 +74,7 @@ function initializeConfig(): Config {
moduleChangeExcludePatterns: getArrayInput('module-change-exclude-patterns', false),
moduleAssetExcludePatterns: getArrayInput('module-asset-exclude-patterns', false),
useSSHSourceFormat: getBooleanInput('use-ssh-source-format', { required: true }),
+ targetBranch: getInput('target-branch', { required: true }),
};
// Validate that *.tf is not in excludePatterns
@@ -103,6 +104,7 @@ function initializeConfig(): Config {
info(`Module Change Exclude Patterns: ${configInstance.moduleChangeExcludePatterns.join(', ')}`);
info(`Module Asset Exclude Patterns: ${configInstance.moduleAssetExcludePatterns.join(', ')}`);
info(`Use SSH Source Format: ${configInstance.useSSHSourceFormat}`);
+ info(`Target Branch: ${configInstance.targetBranch}`);
return configInstance;
} finally {
diff --git a/src/types/config.types.ts b/src/types/config.types.ts
index dea8abf6..8b60aaa6 100644
--- a/src/types/config.types.ts
+++ b/src/types/config.types.ts
@@ -102,4 +102,10 @@ export interface Config {
* Paths are relative to the workspace directory.
*/
modulePathIgnore: string[];
+
+ /**
+ * The target branch to use for wiki operations. This allows supporting repositories that use 'main'
+ * instead of 'master' as their default branch. Defaults to 'master' for backward compatibility.
+ */
+ targetBranch: string;
}
diff --git a/src/wiki.ts b/src/wiki.ts
index 89b95c9a..9dc43018 100644
--- a/src/wiki.ts
+++ b/src/wiki.ts
@@ -72,7 +72,7 @@ export function checkoutWiki(): void {
const isExistingRepo = existsSync(join(wikiDirectory, '.git'));
if (!isExistingRepo) {
info('Initializing new repository');
- execFileSync(gitPath, ['init', '--initial-branch=master', wikiDirectory], execWikiOpts);
+ execFileSync(gitPath, ['init', `--initial-branch=${config.targetBranch}`, wikiDirectory], execWikiOpts);
}
// Set or update the remote URL
@@ -115,13 +115,13 @@ export function checkoutWiki(): void {
'--no-recurse-submodules',
'--depth=1',
'origin',
- '+refs/heads/master*:refs/remotes/origin/master*',
- '+refs/tags/master*:refs/tags/master*',
+ `+refs/heads/${config.targetBranch}*:refs/remotes/origin/${config.targetBranch}*`,
+ `+refs/tags/${config.targetBranch}*:refs/tags/${config.targetBranch}*`,
],
execWikiOpts,
);
- execFileSync(gitPath, ['checkout', 'master'], execWikiOpts);
+ execFileSync(gitPath, ['checkout', config.targetBranch], execWikiOpts);
info('Successfully checked out wiki repository');
} finally {