Skip to content

feat: Introduce zuul job for building docs #312

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"write-heading-ids": "docusaurus write-heading-ids",
"typecheck": "tsc",
"postinstall": "node getDocs.js && node populateStds.js && node populateCerts.js && node populateClouds.js",
"postprocess": "node postprocess",
"test": "echo \"Error: no test specified\" && exit 1",
"lint:md": "markdownlint-cli2 \"**/*.md\"",
"fix:md": "markdownlint-cli2-fix \"**/*.md\"",
Expand Down
6 changes: 6 additions & 0 deletions playbooks/post.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- hosts: all
tasks:
- name: 'Postprocess docusaurus to generate artifacts usable for offline use'
ansible.builtin.command: 'npm run postprocess'
args:
chdir: '{{ zuul.project.src_dir }}'
49 changes: 49 additions & 0 deletions postprocess.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict'

const fs = require('fs-extra')
const path = require('path')
const recursiveReaddir = require('recursive-readdir')

const buildDirectory = path.join(__dirname, 'build')
const absoluteUrlRegExp = /(href|src)="(?!http[s]|ftp?:\/\/)([^"|#]+)"/g

const isDirectory = (dirPath) => path.extname(dirPath) === ''

const convertAbsolutePathsToRelative = (content, filePath) =>
content.replace(absoluteUrlRegExp, (_absoluteUrl, $1, $2) => {
const currentDirPath = path.dirname(filePath)
const relativeDirPath =
currentDirPath === '.' ? '.' : path.relative(currentDirPath, '')

let relativePath = path.join(relativeDirPath, $2)
if (isDirectory(relativePath)) {
relativePath = path.join(relativePath, 'index.html')
}

return `${$1}="${relativePath}"`
})

const websiteTextualFileExtensions = ['.css', '.js', '.html', '.xml']
const isNotWebsiteTextualFile = (filePath, stats) =>
!(
stats.isDirectory() ||
websiteTextualFileExtensions.includes(path.extname(filePath))
)

const postProcess = async () => {
const filePaths = await recursiveReaddir(buildDirectory, [
isNotWebsiteTextualFile
])
await Promise.all(
filePaths.map(async (filePath) => {
const content = await fs.readFile(filePath)
const relativePath = path.relative(buildDirectory, filePath)
await fs.writeFile(
filePath,
convertAbsolutePathsToRelative(String(content), relativePath)
)
})
)
}

postProcess()
18 changes: 18 additions & 0 deletions zuul.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- job:
name: docs-build
parent: js-build
nodeset: ubuntu-noble
vars:
node_version: 18
javascript_content_dir: build
# pre-run: playbooks/pre.yaml
# run: playbooks/run.yaml
post-run: playbooks/post.yaml

- project:
merge-mode: squash-merge
default-branch: main
check:
jobs:
- docs-build