diff --git a/action.yml b/action.yml index a0d4644..1bee327 100644 --- a/action.yml +++ b/action.yml @@ -69,6 +69,11 @@ inputs: description: >- Published Template IDs will be prefixed with the namespace. If omitted, this value will default to the source repo name + default-branch: + required: false + description: >- + The default branch for the repo (used when creating documentation updates) + If omitted, this value will default to `main` runs: using: node16 main: dist/index.js diff --git a/src/generateDocs.ts b/src/generateDocs.ts index c5baaa2..622fe9b 100644 --- a/src/generateDocs.ts +++ b/src/generateDocs.ts @@ -39,15 +39,15 @@ const TEMPLATE_README_TEMPLATE = ` _Note: This file was auto-generated from the [devcontainer-template.json](#{RepoUrl}). Add additional notes to a \`NOTES.md\`._ `; -export async function generateFeaturesDocumentation(basePath: string, ociRegistry: string, namespace: string) { - await _generateDocumentation(basePath, FEATURES_README_TEMPLATE, 'devcontainer-feature.json', ociRegistry, namespace); +export async function generateFeaturesDocumentation(basePath: string, ociRegistry: string, namespace: string, defaultBranch: string) { + await _generateDocumentation(basePath, FEATURES_README_TEMPLATE, 'devcontainer-feature.json', defaultBranch, ociRegistry, namespace); } -export async function generateTemplateDocumentation(basePath: string) { - await _generateDocumentation(basePath, TEMPLATE_README_TEMPLATE, 'devcontainer-template.json'); +export async function generateTemplateDocumentation(basePath: string, defaultBranch: string) { + await _generateDocumentation(basePath, TEMPLATE_README_TEMPLATE, 'devcontainer-template.json', defaultBranch); } -async function _generateDocumentation(basePath: string, readmeTemplate: string, metadataFile: string, ociRegistry: string = '', namespace: string = '') { +async function _generateDocumentation(basePath: string, readmeTemplate: string, metadataFile: string, defaultBranch: string, ociRegistry: string = '', namespace: string = '') { const directories = fs.readdirSync(basePath); await Promise.all( @@ -117,7 +117,7 @@ async function _generateDocumentation(basePath: string, readmeTemplate: string, let urlToConfig = `${metadataFile}`; const basePathTrimmed = basePath.startsWith('./') ? basePath.substring(2) : basePath; if (srcInfo.owner && srcInfo.repo) { - urlToConfig = `https://github.com/${srcInfo.owner}/${srcInfo.repo}/blob/main/${basePathTrimmed}/${f}/${metadataFile}`; + urlToConfig = `https://github.com/${srcInfo.owner}/${srcInfo.repo}/blob/${defaultBranch}/${basePathTrimmed}/${f}/${metadataFile}`; } let header; diff --git a/src/main.ts b/src/main.ts index 1735fae..b5d1d8f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -17,6 +17,7 @@ async function run(): Promise { // Read inputs const shouldGenerateDocumentation = core.getInput('generate-docs').toLowerCase() === 'true'; const sourceMetadata = getGitHubMetadata(); + const defaultBranch = core.getInput('default-branch') ?? 'main'; // Read inputs - Features const shouldPublishFeatures = core.getInput('publish-features').toLowerCase() === 'true'; @@ -127,12 +128,12 @@ async function run(): Promise { if (shouldGenerateDocumentation && featuresBasePath) { core.info('Generating documentation for Features...'); - await generateFeaturesDocumentation(featuresBasePath, featuresOciRegistry, featuresNamespace); + await generateFeaturesDocumentation(featuresBasePath, featuresOciRegistry, featuresNamespace, defaultBranch); } if (shouldGenerateDocumentation && templatesBasePath) { core.info('Generating documentation for Templates...'); - await generateTemplateDocumentation(templatesBasePath); + await generateTemplateDocumentation(templatesBasePath, defaultBranch); } }