Skip to content

Commit

Permalink
Allow overriding main branch name
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartleeks committed Mar 22, 2023
1 parent 9b0f84a commit 6b856bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 pull requests for documentation updates)
If omitted, this value will default to `main`
runs:
using: node16
main: dist/index.js
12 changes: 6 additions & 6 deletions src/generateDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async function run(): Promise<void> {
// 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';
Expand Down Expand Up @@ -127,12 +128,12 @@ async function run(): Promise<void> {

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);
}
}

Expand Down

0 comments on commit 6b856bc

Please sign in to comment.