Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global check links playbook #412

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/actions/validate/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Validate
description: Check for dead links

runs:
using: 'composite'
steps:
- uses: actions/setup-node@v4
with:
node-version: 20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
node-version: 20
node-version: 20
cache: npm

Might be worth trying?

https://github.com/actions/setup-node?tab=readme-ov-file#caching-global-packages-data

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 [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
54 changes: 54 additions & 0 deletions lib/load-check-links-playbook.js
Original file line number Diff line number Diff line change
@@ -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' },
);
2 changes: 0 additions & 2 deletions templates/antora.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: templates
title: Templates
version: v0.1
nav:
- modules/ROOT/nav.adoc


Loading