Skip to content

Commit fb751d4

Browse files
authored
feat: add useSSHSourceFormat option to configure source URL format in Wiki documentation (#146)
1 parent 46b354c commit fb751d4

File tree

14 files changed

+112
-18
lines changed

14 files changed

+112
-18
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ jobs:
5151
delete-legacy-tags: false # Note: We don't want to delete tags in this repository
5252
module-change-exclude-patterns: .gitignore,*.md,*.tftest.hcl,tests/**
5353
module-asset-exclude-patterns: .gitignore,*.md,*.tftest.hcl,tests/**
54+
use-ssh-source-format: true

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
env:
3636
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO_CI_TESTING }}
3737

38-
- name: SonarCloud Scan
39-
uses: sonarsource/sonarcloud-github-action@v4
38+
- name: SonarQube Scan
39+
uses: SonarSource/sonarqube-scan-action@v4
4040
env:
4141
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ configuring the following optional input parameters as needed.
182182
| `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` |
183183
| `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/**` |
184184
| `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/**` |
185+
| `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` |
185186

186187
### Example Usage with Inputs
187188

@@ -217,6 +218,7 @@ jobs:
217218
wiki-sidebar-changelog-max: 10
218219
module-change-exclude-patterns: .gitignore,*.md,*.tftest.hcl,tests/**
219220
module-asset-exclude-patterns: .gitignore,*.md,*.tftest.hcl,tests/**
221+
use-ssh-source-format: false
220222
```
221223

222224
## Inspiration

__mocks__/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const defaultConfig: Config = {
2424
moduleChangeExcludePatterns: ['.gitignore', '*.md'],
2525
moduleAssetExcludePatterns: ['tests/**', 'examples/**'],
2626
githubToken: 'ghp_test_token_2c6912E7710c838347Ae178B4',
27+
useSSHSourceFormat: false,
2728
};
2829

2930
/**
@@ -42,6 +43,7 @@ const validConfigKeys = [
4243
'moduleChangeExcludePatterns',
4344
'moduleAssetExcludePatterns',
4445
'githubToken',
46+
'useSSHSourceFormat',
4547
] as const;
4648

4749
type ValidConfigKey = (typeof validConfigKeys)[number];

__tests__/config.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ describe('config', () => {
117117
expect(config.githubToken).toBe('ghp_test_token_2c6912E7710c838347Ae178B4');
118118
expect(config.moduleChangeExcludePatterns).toEqual(['.gitignore', '*.md']);
119119
expect(config.moduleAssetExcludePatterns).toEqual(['tests/**', 'examples/**']);
120+
expect(config.useSSHSourceFormat).toBe(false);
120121
expect(startGroup).toHaveBeenCalledWith('Initializing Config');
121122
expect(startGroup).toHaveBeenCalledTimes(1);
122123
expect(endGroup).toHaveBeenCalledTimes(1);
123-
expect(info).toHaveBeenCalledTimes(10);
124+
expect(info).toHaveBeenCalledTimes(11);
124125
expect(vi.mocked(info).mock.calls).toEqual([
125126
['Major Keywords: MAJOR CHANGE, BREAKING CHANGE, !'],
126127
['Minor Keywords: feat, feature'],
@@ -132,8 +133,8 @@ describe('config', () => {
132133
['Wiki Sidebar Changelog Max: 10'],
133134
['Module Change Exclude Patterns: .gitignore, *.md'],
134135
['Module Asset Exclude Patterns: tests/**, examples/**'],
136+
['Use SSH Source Format: false'],
135137
]);
136-
expect(info).toHaveBeenCalledTimes(10);
137138
});
138139
});
139140

__tests__/helpers/inputs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ export const defaultInputs = {
2121
'module-change-exclude-patterns': '.gitignore,*.md',
2222
'module-asset-exclude-patterns': 'tests/**,examples/**',
2323
github_token: 'ghp_test_token_2c6912E7710c838347Ae178B4',
24+
'use-ssh-source-format': 'false',
2425
};
2526
export const requiredInputs = Object.keys(defaultInputs);
26-
export const booleanInputs = ['delete-legacy-tags', 'disable-wiki', 'disable-branding'];
27+
export const booleanInputs = ['delete-legacy-tags', 'disable-wiki', 'disable-branding', 'use-ssh-source-format'];
2728
export const booleanConfigKeys: BooleanConfigKeys[] = ['deleteLegacyTags', 'disableWiki', 'disableBranding'];
2829

2930
/**

__tests__/terraform-docs.test.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { context } from '@/mocks/context';
77
import { ensureTerraformDocsConfigDoesNotExist, generateTerraformDocs, installTerraformDocs } from '@/terraform-docs';
88
import type { TerraformModule } from '@/types';
99
import { info } from '@actions/core';
10-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
10+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
1111
import which from 'which';
1212

1313
const execFilePromisified = promisify(execFile);
@@ -50,7 +50,6 @@ describe('terraform-docs', async () => {
5050
afterEach(() => {
5151
Object.defineProperty(process, 'platform', { value: realPlatform });
5252
Object.defineProperty(process, 'arch', { value: realArch });
53-
vi.resetAllMocks();
5453
});
5554

5655
describe('install terraform-docs (linux, darwin, freebsd)', () => {
@@ -184,6 +183,10 @@ describe('terraform-docs', async () => {
184183

185184
expect(() => installTerraformDocs(terraformDocsVersion)).toThrow('not found: invalid-non-existent-binary');
186185
});
186+
187+
afterAll(() => {
188+
mockWhichSync.mockRestore();
189+
});
187190
});
188191

189192
describe('terraform-docs version validation', () => {
@@ -219,7 +222,7 @@ describe('terraform-docs', async () => {
219222
join('C:\\Windows\\System32', 'terraform-docs.exe'),
220223
];
221224

222-
beforeEach(async () => {
225+
beforeAll(async () => {
223226
// Get real implementations
224227
const realChildProcess = (await vi.importActual('node:child_process')) as typeof import('node:child_process');
225228
const realFs = (await vi.importActual('node:fs')) as typeof import('node:fs');
@@ -232,6 +235,14 @@ describe('terraform-docs', async () => {
232235
mockWhichSync.mockImplementation(realWhich.sync);
233236
});
234237

238+
afterAll(() => {
239+
// Restore original mock implementations
240+
mockExecFileSync.mockRestore();
241+
fsExistsSyncMock.mockRestore();
242+
mockFsUnlinkSync.mockRestore();
243+
mockWhichSync.mockRestore();
244+
});
245+
235246
afterEach(() => {
236247
// Cleanup downloaded/installed files
237248
for (const file of cleanupFiles) {
@@ -241,8 +252,6 @@ describe('terraform-docs', async () => {
241252
// Ignore cleanup errors
242253
}
243254
}
244-
245-
// Restore original mock implementations (handled via global resetAllMocks())
246255
});
247256

248257
it(`should install terraform-docs on the real system ${process.arch}/${process.platform}`, () => {

__tests__/wiki.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,51 @@ describe('wiki', async () => {
316316
expect(commitCall?.[1]).toEqual(['commit', '-m', 'PR #456 - Complex PR title\n\nLine 1\nLine 2\nLine 3']);
317317
});
318318
});
319+
320+
describe('formatModuleSource()', () => {
321+
beforeEach(() => {
322+
context.set({
323+
repo: { owner: 'techpivot', repo: 'terraform-module-releaser' },
324+
repoUrl: 'https://github.com/techpivot/terraform-module-releaser',
325+
});
326+
});
327+
328+
it('should format source URL as HTTPS when useSSHSourceFormat is false', async () => {
329+
config.set({ useSSHSourceFormat: false });
330+
const files = await generateWikiFiles(terraformModules);
331+
332+
// Read each generated .md file and verify it contains HTTPS format
333+
for (const file of files) {
334+
if (file.endsWith('.md')) {
335+
const content = readFileSync(file, 'utf8');
336+
if (content.includes('source =')) {
337+
expect(content).toContain('source = "git::https://github.com/techpivot/terraform-module-releaser.git?ref=');
338+
expect(content).not.toContain(
339+
'source = "git::ssh://git@github.com/techpivot/terraform-module-releaser.git?ref=',
340+
);
341+
}
342+
}
343+
}
344+
});
345+
346+
it('should format source URL as SSH when useSSHSourceFormat is true', async () => {
347+
config.set({ useSSHSourceFormat: true });
348+
const files = await generateWikiFiles(terraformModules);
349+
350+
// Read each generated .md file and verify it contains SSH format
351+
for (const file of files) {
352+
if (file.endsWith('.md')) {
353+
const content = readFileSync(file, 'utf8');
354+
if (content.includes('source =')) {
355+
expect(content).toContain(
356+
'source = "git::ssh://git@github.com/techpivot/terraform-module-releaser.git?ref=',
357+
);
358+
expect(content).not.toContain(
359+
'source = "git::https://github.com/techpivot/terraform-module-releaser.git?ref=',
360+
);
361+
}
362+
}
363+
}
364+
});
365+
});
319366
});

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ inputs:
8383
The minimatch syntax is used for pattern matching. Files matching these patterns will be excluded from the bundled output.
8484
required: true
8585
default: ".gitignore,*.md,*.tftest.hcl,tests/**"
86+
use-ssh-source-format:
87+
description: If enabled, all links to source code in generated Wiki documentation will use SSH format instead of HTTPS format
88+
required: true
89+
default: "false"
8690
github_token:
8791
description: |
8892
Required for retrieving pull request metadata, tags, releases, updating PR comments, wiki, and creating tags/releases.

package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@
1313
"bugs": {
1414
"url": "https://github.com/techpivot/terraform-module-releaser/issues"
1515
},
16-
"keywords": [
17-
"terraform",
18-
"module",
19-
"releaser",
20-
"github-action",
21-
"monorepo"
22-
],
16+
"keywords": ["terraform", "module", "releaser", "github-action", "monorepo"],
2317
"license": "MIT",
2418
"exports": {
2519
".": "./dist/index.js"

0 commit comments

Comments
 (0)