From 58ebe5e63c7390f7be3c0d1bc9dabab9027c26a6 Mon Sep 17 00:00:00 2001 From: Mykola Fant Date: Thu, 14 Nov 2024 19:59:09 +0200 Subject: [PATCH] Global check links playbook (#412) # Description of change 1. Adds two files which will be reused across other docs repos for global links check 2. As a BONUS remove an unexisting reference from `templates/antora.yml` --- .github/actions/validate/action.yml | 30 ++++++++++++++++ lib/load-check-links-playbook.js | 54 +++++++++++++++++++++++++++++ templates/antora.yml | 2 -- 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 .github/actions/validate/action.yml create mode 100644 lib/load-check-links-playbook.js diff --git a/.github/actions/validate/action.yml b/.github/actions/validate/action.yml new file mode 100644 index 00000000..8eef321e --- /dev/null +++ b/.github/actions/validate/action.yml @@ -0,0 +1,30 @@ +name: Validate +description: Check for dead links + +runs: + using: 'composite' + steps: + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + + - name: Checkout global antora-playbook + uses: actions/checkout@v4 + with: + repository: hazelcast/hazelcast-docs + sparse-checkout: | + antora-playbook.yml + lib/load-check-links-playbook.js + sparse-checkout-cone-mode: false + path: hazelcast-docs + ref: main + + - name: Check for broken internal links + shell: bash + run: | + cp "./hazelcast-docs/lib/load-check-links-playbook.js" "./load-check-links-playbook.js" + npm i + npm i -D yaml@2.6.0 + node load-check-links-playbook.js $GITHUB_REPOSITORY $GITHUB_BASE_REF + ./node_modules/.bin/antora --fetch --to-dir test --log-level=error --log-failure-level=error --extension=@jcahills/antora-link-checker check-links-playbook.yml diff --git a/lib/load-check-links-playbook.js b/lib/load-check-links-playbook.js new file mode 100644 index 00000000..86fb1938 --- /dev/null +++ b/lib/load-check-links-playbook.js @@ -0,0 +1,54 @@ +const YAML = require('yaml'); +const fs = require('fs'); + +const [currentRepoName, baseBranchName] = process.argv.slice(-2); + +console.log('Checking links...'); + +if (currentRepoName.endsWith('.js') || baseBranchName.endsWith('.js')) { + throw new Error('GitHub repository name and base branch should be passed as arguments'); +} + +console.log('Repository name: ', currentRepoName); +console.log('Base branch: ', baseBranchName); + +// 1. Load and parse local antora-playbook.yml +const localAntoraPlaybookContent = fs.readFileSync('./antora-playbook.yml', 'utf8'); +const localAntoraPlaybook = YAML.parse(localAntoraPlaybookContent); + +// 2. Load and parse global antora-playbook.yml's content.sources +const globalAntoraPlaybookContent = fs.readFileSync('./hazelcast-docs/antora-playbook.yml', 'utf8'); +const globalAntoraPlaybook = YAML.parse(globalAntoraPlaybookContent); +let globalSources = globalAntoraPlaybook.content.sources; +// 3. Modify global content.sources +// - add hazelcast-docs GitHub URL +const hazelcastDocsSource = globalSources.find(source => source.url === '.'); +hazelcastDocsSource.url = 'https://github.com/hazelcast/hazelcast-docs'; + +// - remove hazelcast-mono & management-center, +// because they have only Swagger docs thus will never have links to the current +// and also they require authentication +globalSources = globalSources.filter(source => + !(source.url === 'https://github.com/hazelcast/hazelcast-mono') + && !(source.url === 'https://github.com/hazelcast/management-center')); + +// - add current branch +globalSources.unshift({ + url: '.', + branches: 'HEAD', + start_path: 'docs', +}); + +// - remove current target branch from the global content list +const currentRepoSource = globalSources.find(source => source.url.endsWith(currentRepoName)); +currentRepoSource.branches.push(`!${baseBranchName}`); + +// 4. Replace local content.sources with the modified content.sources +localAntoraPlaybook.content.sources = globalSources; +const checkLinksPlaybook = YAML.stringify(localAntoraPlaybook); + +fs.writeFileSync( + './check-links-playbook.yml', + checkLinksPlaybook, + { encoding: 'utf8' }, +); diff --git a/templates/antora.yml b/templates/antora.yml index 57e08435..b246b0c2 100644 --- a/templates/antora.yml +++ b/templates/antora.yml @@ -1,7 +1,5 @@ name: templates title: Templates version: v0.1 -nav: - - modules/ROOT/nav.adoc