From bbbcac537adc50fc8e68768f49d2ac9f8b54f698 Mon Sep 17 00:00:00 2001 From: Mykola Fant Date: Thu, 5 Dec 2024 17:30:17 +0200 Subject: [PATCH] copy asciidoc attributes --- lib/load-check-links-playbook.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/load-check-links-playbook.js b/lib/load-check-links-playbook.js index f7a06440..eafc4e78 100644 --- a/lib/load-check-links-playbook.js +++ b/lib/load-check-links-playbook.js @@ -6,14 +6,14 @@ 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); @@ -21,6 +21,10 @@ function main() { // - 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); } @@ -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; } @@ -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);