Skip to content

Commit 6b856bc

Browse files
committed
Allow overriding main branch name
1 parent 9b0f84a commit 6b856bc

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ inputs:
6969
description: >-
7070
Published Template IDs will be prefixed with the namespace.
7171
If omitted, this value will default to the source repo name
72+
default-branch:
73+
required: false
74+
description: >-
75+
The default branch for the repo (used when creating pull requests for documentation updates)
76+
If omitted, this value will default to `main`
7277
runs:
7378
using: node16
7479
main: dist/index.js

src/generateDocs.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ const TEMPLATE_README_TEMPLATE = `
3939
_Note: This file was auto-generated from the [devcontainer-template.json](#{RepoUrl}). Add additional notes to a \`NOTES.md\`._
4040
`;
4141

42-
export async function generateFeaturesDocumentation(basePath: string, ociRegistry: string, namespace: string) {
43-
await _generateDocumentation(basePath, FEATURES_README_TEMPLATE, 'devcontainer-feature.json', ociRegistry, namespace);
42+
export async function generateFeaturesDocumentation(basePath: string, ociRegistry: string, namespace: string, defaultBranch: string) {
43+
await _generateDocumentation(basePath, FEATURES_README_TEMPLATE, 'devcontainer-feature.json', defaultBranch, ociRegistry, namespace);
4444
}
4545

46-
export async function generateTemplateDocumentation(basePath: string) {
47-
await _generateDocumentation(basePath, TEMPLATE_README_TEMPLATE, 'devcontainer-template.json');
46+
export async function generateTemplateDocumentation(basePath: string, defaultBranch: string) {
47+
await _generateDocumentation(basePath, TEMPLATE_README_TEMPLATE, 'devcontainer-template.json', defaultBranch);
4848
}
4949

50-
async function _generateDocumentation(basePath: string, readmeTemplate: string, metadataFile: string, ociRegistry: string = '', namespace: string = '') {
50+
async function _generateDocumentation(basePath: string, readmeTemplate: string, metadataFile: string, defaultBranch: string, ociRegistry: string = '', namespace: string = '') {
5151
const directories = fs.readdirSync(basePath);
5252

5353
await Promise.all(
@@ -117,7 +117,7 @@ async function _generateDocumentation(basePath: string, readmeTemplate: string,
117117
let urlToConfig = `${metadataFile}`;
118118
const basePathTrimmed = basePath.startsWith('./') ? basePath.substring(2) : basePath;
119119
if (srcInfo.owner && srcInfo.repo) {
120-
urlToConfig = `https://github.com/${srcInfo.owner}/${srcInfo.repo}/blob/main/${basePathTrimmed}/${f}/${metadataFile}`;
120+
urlToConfig = `https://github.com/${srcInfo.owner}/${srcInfo.repo}/blob/${defaultBranch}/${basePathTrimmed}/${f}/${metadataFile}`;
121121
}
122122

123123
let header;

src/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ async function run(): Promise<void> {
1717
// Read inputs
1818
const shouldGenerateDocumentation = core.getInput('generate-docs').toLowerCase() === 'true';
1919
const sourceMetadata = getGitHubMetadata();
20+
const defaultBranch = core.getInput('default-branch') ?? 'main';
2021

2122
// Read inputs - Features
2223
const shouldPublishFeatures = core.getInput('publish-features').toLowerCase() === 'true';
@@ -127,12 +128,12 @@ async function run(): Promise<void> {
127128

128129
if (shouldGenerateDocumentation && featuresBasePath) {
129130
core.info('Generating documentation for Features...');
130-
await generateFeaturesDocumentation(featuresBasePath, featuresOciRegistry, featuresNamespace);
131+
await generateFeaturesDocumentation(featuresBasePath, featuresOciRegistry, featuresNamespace, defaultBranch);
131132
}
132133

133134
if (shouldGenerateDocumentation && templatesBasePath) {
134135
core.info('Generating documentation for Templates...');
135-
await generateTemplateDocumentation(templatesBasePath);
136+
await generateTemplateDocumentation(templatesBasePath, defaultBranch);
136137
}
137138
}
138139

0 commit comments

Comments
 (0)