Skip to content

Commit

Permalink
DOC-250: local check links extension (#425)
Browse files Browse the repository at this point in the history
# Description of change

https://hazelcast.atlassian.net/browse/DOC-250

---------

Co-authored-by: Jack Green <[email protected]>
  • Loading branch information
fantkolja and JackPGreen authored Nov 29, 2024
1 parent e43999f commit 273db7b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
5 changes: 3 additions & 2 deletions .github/actions/validate/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ runs:
sparse-checkout: |
antora-playbook.yml
lib/load-check-links-playbook.js
lib/antora-link-checker-extension.js
sparse-checkout-cone-mode: false
path: hazelcast-docs
ref: main
Expand All @@ -25,6 +26,6 @@ runs:
run: |
cp "./hazelcast-docs/lib/load-check-links-playbook.js" "./load-check-links-playbook.js"
npm i
npm i -D [email protected] @jcahills/[email protected] [email protected]
npm i -D [email protected] [email protected]
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
./node_modules/.bin/antora --fetch --to-dir test --log-level=error --log-failure-level=error --extension=hazelcast-docs/lib/antora-link-checker-extension.js check-links-playbook.yml
8 changes: 8 additions & 0 deletions lib/antora-link-checker-extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This extension stops the Antora site generator from building the site after checking internal links (xrefs).
// As a result, the output is a list of broken links rather than a documentation site.

module.exports.register = (context) => {
context.on('documentsConverted', () => {
context.stop()
})
}
24 changes: 18 additions & 6 deletions lib/load-check-links-playbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,31 @@ function rewriteCurrentVersion() {
}
}

function excludeBaseBranch(sources, repoName, branchName) {
const matchedRepos = sources.filter(source => source.url.endsWith(repoName));
if (matchedRepos.length === 0) {
throw new Error(`There is no repository ${repoName} among the playbook sources!`);
}
let currentSource = matchedRepos.find(source => isMatch(branchName, source.branches));
function getCurrentSource(matchedRepos, branchName) {
let currentSource = matchedRepos.find(source => {
if (Array.isArray(source.branches)) {
return source.branches.find(branch => isMatch(branchName, branch));
} else {
return isMatch(branchName, source.branches);
}
});
if (!currentSource) {
console.debug(`No matching base branch found. Rewriting version to omit version collision!`);
rewriteCurrentVersion();
currentSource = matchedRepos[0];
}

return currentSource;
}

function excludeBaseBranch(sources, repoName, branchName) {
const excludedBranch = `!${branchName}`;
const matchedRepos = sources.filter(source => source.url.endsWith(repoName));
if (matchedRepos.length === 0) {
throw new Error(`There is no repository ${repoName} among the playbook sources!`);
}

const currentSource = getCurrentSource(matchedRepos, branchName);
if (Array.isArray(currentSource.branches)) {
currentSource.branches.push(excludedBranch);
} else {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "antora --to-dir docs --fetch antora-playbook.yml && cp _redirects docs",
"build-local": "antora --to-dir docs --fetch antora-playbook-local.yml",
"check-links-local": "antora --fetch --to-dir test --log-level=error --log-failure-level=error --extension=@jcahills/antora-link-checker antora-playbook-local.yml",
"check-links-local": "antora --fetch --to-dir test --log-level=error --log-failure-level=error --extension=./lib/antora-link-checker-extension.js antora-playbook-local.yml",
"generate-pdfs-platform-5-5": "antora assembler-playbook-platform-5-5.yml",
"generate-pdfs-platform-5-4": "antora assembler-playbook-platform-5-4.yml",
"generate-pdfs-platform-5-3": "antora assembler-playbook-platform-5-3.yml",
Expand All @@ -26,7 +26,6 @@
"devDependencies": {
"@antora/cli": "^3.1.1",
"@antora/site-generator": "^3.1.1",
"@jcahills/antora-link-checker": "^1.0.1",
"@djencks/antora-aggregate-collector": "^0.1.0-beta.1",
"asciidoctor-kroki": "^0.15.0",
"ngrok": "^4.2.2",
Expand Down

0 comments on commit 273db7b

Please sign in to comment.