Skip to content

Commit

Permalink
FIx links checker warnings (#429)
Browse files Browse the repository at this point in the history
1. Copy asciidoc.attributes for links-checker
2. Use the same links-check workflow as for other repos
  • Loading branch information
fantkolja authored Dec 5, 2024
1 parent 6d68bdb commit db885c4
Show file tree
Hide file tree
Showing 5 changed files with 3,744 additions and 17 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Check for broken internal links
env:
GIT_CREDENTIALS: ${{ secrets.GIT_CREDENTIALS }}
run: |
npm i
npm run-script check-links-local
- name: Checkout Current Repo
uses: actions/checkout@v4
- name: Check dead links
uses: hazelcast/hazelcast-docs/.github/actions/validate@main


3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/docs/
/build/
.DS_Store
package-lock.json
/pdf-docs/
Gemfile.lock
.idea
.idea
26 changes: 22 additions & 4 deletions lib/load-check-links-playbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ 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
const globalSources = loadGlobalContentSources();
let { globalSources, globalAsciidocAttributes } = loadGlobalAntoraData();

// 3. Modify global content.sources
// - add hazelcast-docs GitHub URL
Expand All @@ -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);
}
Expand Down Expand Up @@ -52,20 +56,25 @@ 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'];
return sources;
}

function rewriteCurrentVersion() {
Expand Down Expand Up @@ -138,6 +147,15 @@ 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;
const checkLinksPlaybook = YAML.stringify(localPlaybook);
Expand Down
Loading

0 comments on commit db885c4

Please sign in to comment.