Skip to content
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

Allow overriding main branch name #162

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
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 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