Skip to content

Commit

Permalink
copy asciidoc attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
fantkolja committed Dec 5, 2024
1 parent ed6e129 commit bbbcac5
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions lib/load-check-links-playbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ function main() {
const { currentRepoName, baseBranchName } = parseInputArgs();

// 1. Load and parse local antora-playbook.yml
const localAntoraPlaybook = loadLocalAntoraPlaybook();
let localAntoraPlaybook = loadLocalAntoraPlaybook();

// 2. Load and parse global antora-playbook.yml's content.sources
let globalSources = loadGlobalContentSources();
let { globalSources, globalAsciidocAttributes } = loadGlobalAntoraData();

// 3. Modify global content.sources
// - add hazelcast-docs GitHub URL
globalSources = addHazelcastDocsUrl(globalSources);
addHazelcastDocsUrl(globalSources);

// - exclude current target branch from the global content list by adding the branch name with the "!" prefix
const currentRepoSource = excludeBaseBranch(globalSources, currentRepoName, baseBranchName);

// - add current branch
addCurrentBranch(currentRepoSource, globalSources);

// - hazelcast-mono antora-playbook, contains global attributes, used across other repos
// need to add them to the local antora-playbook
localAntoraPlaybook = copyGlobalAsciidocAttributes(globalAsciidocAttributes, localAntoraPlaybook);

// 4. Replace local content.sources with the modified content.sources
writeCheckLinksPlaybookFile(localAntoraPlaybook, globalSources);
}
Expand Down Expand Up @@ -52,21 +56,24 @@ function removeProtectedSources(sources) {
&& !(source.url === 'https://github.com/hazelcast/management-center'));
}

function loadGlobalContentSources() {
function loadGlobalAntoraData() {
const globalAntoraPlaybookContent = fs.readFileSync('./hazelcast-docs/antora-playbook.yml', 'utf8');
const globalAntoraPlaybook = YAML.parse(globalAntoraPlaybookContent);

// - remove hazelcast-mono & management-center,
// because they have only Swagger docs thus will never have links to the current
// and also they require authentication
return removeProtectedSources(globalAntoraPlaybook.content.sources);
const globalSources = removeProtectedSources(globalAntoraPlaybook.content.sources);
const globalAsciidocAttributes = globalAntoraPlaybook.asciidoc.attributes;

return { globalSources, globalAsciidocAttributes };
}

function addHazelcastDocsUrl(sources) {
// in the global playbook it's declared with a dot `.`
const hazelcastDocsSource = sources.find(source => source.url === '.');
hazelcastDocsSource.url = 'https://github.com/hazelcast/hazelcast-docs';
hazelcastDocsSource.branches = [main];
hazelcastDocsSource.branches = ['main'];
return sources;
}

Expand Down Expand Up @@ -140,8 +147,18 @@ function addCurrentBranch(repoSource, sources) {
sources.unshift(currentBranchSource);
}

function copyGlobalAsciidocAttributes(globalAsciidocAttributes, localAntoraPlaybook) {
localAntoraPlaybook.asciidoc.attributes = {
...globalAsciidocAttributes,
...localAntoraPlaybook.asciidoc.attributes,
};

return localAntoraPlaybook;
}

function writeCheckLinksPlaybookFile(localPlaybook, sources) {
localPlaybook.content.sources = sources;
console.log(localPlaybook);
const checkLinksPlaybook = YAML.stringify(localPlaybook);

console.debug(checkLinksPlaybook);
Expand Down

0 comments on commit bbbcac5

Please sign in to comment.