Skip to content

fix: add --target-branch flag #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br><sub>[Read more here](#understanding-the-filtering-options)</sub> | `.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://[email protected]/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

Expand Down
2 changes: 2 additions & 0 deletions __mocks__/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const defaultConfig: Config = {
moduleAssetExcludePatterns: ['tests/**', 'examples/**'],
githubToken: 'ghp_test_token_2c6912E7710c838347Ae178B4',
useSSHSourceFormat: false,
targetBranch: 'master',
};

/**
Expand All @@ -46,6 +47,7 @@ const validConfigKeys = [
'moduleAssetExcludePatterns',
'githubToken',
'useSSHSourceFormat',
'targetBranch',
] as const;

type ValidConfigKey = (typeof validConfigKeys)[number];
Expand Down
2 changes: 2 additions & 0 deletions __tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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'],
]);
});
});
Expand Down
5 changes: 4 additions & 1 deletion __tests__/helpers/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const inputToConfigKeyMap: Record<string, keyof Config> = {
'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
Expand Down Expand Up @@ -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',
Expand All @@ -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'];
Expand All @@ -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'];

/**
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/types/config.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 4 additions & 4 deletions src/wiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down