-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ci): improve documentation CI workflows (#922)
* ci: Adding docs tasks * ci: Adding docs build to CI * ci: Adding CI workflow to execute veramo-website action * ci: Fixing docs generator * ci: removing Github token * ci: Changing the Github Token for docs trigger * ci: Changing the Github Token for docs trigger * ci: Adding docusaurus dependency * docs: fixing generated API docs * docs: replacing comments by empty string in docs * ci: workflow dispatch for veramo-website * ci: attempt to veramo-website workflow dispatch * ci: attempt to veramo-website workflow dispatch * ci: attempt to veramo-website workflow dispatch * ci: attempt to veramo-website workflow dispatch * ci: attempt to veramo-website workflow dispatch * ci: attempt to veramo-website workflow dispatch * ci: attempt to veramo-website workflow dispatch * ci: attempt to veramo-website workflow dispatch * ci: attempt to veramo-website workflow dispatch * ci: attempt to veramo-website workflow dispatch * ci: using repository_dispatch instead of workflow_dispatch * ci: running website deploy only for main branch pushes * fix: removing extract-api script * fix: removing unecessary changes * Update .github/workflows/veramo-website.yml
- Loading branch information
Showing
8 changed files
with
2,760 additions
and
2,205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Trigger veramo-website build | ||
on: | ||
push: | ||
branches: | ||
- "main" | ||
jobs: | ||
dispatch: | ||
permissions: | ||
contents: write | ||
actions: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: | | ||
curl -X POST \ | ||
-H 'Authorization: token ${{ secrets.GH_TOKEN }}' \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
https://api.github.com/repos/uport-project/veramo-website/dispatches \ | ||
-d '{"event_type":"deploy_website"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { readdir, createReadStream, writeFile } from 'fs-extra' | ||
import { createInterface } from 'readline' | ||
import { join, parse } from 'path' | ||
import { exec } from 'child_process' | ||
import * as fs from 'fs' | ||
|
||
const DOCS_DIR = './docs/api' | ||
|
||
async function main() { | ||
await fs.promises.mkdir(DOCS_DIR, { recursive: true }) | ||
|
||
await new Promise((resolve, reject) => | ||
exec(`api-documenter markdown -i ./temp -o ${DOCS_DIR}`, (err, stdout, stderr) => { | ||
console.log(stdout) | ||
console.error(stderr) | ||
if (err) { | ||
reject(err) | ||
} else { | ||
resolve('') | ||
} | ||
}), | ||
) | ||
|
||
const docFiles = await readdir(DOCS_DIR) | ||
for (const docFile of docFiles) { | ||
try { | ||
const { name: id, ext } = parse(docFile) | ||
if (ext !== '.md') { | ||
continue | ||
} | ||
|
||
const docPath = join(DOCS_DIR, docFile) | ||
const input = createReadStream(docPath) | ||
const output: string[] = [] | ||
const lines = createInterface({ | ||
input, | ||
crlfDelay: Infinity, | ||
}) | ||
|
||
let title = '' | ||
lines.on('line', (line) => { | ||
let skip = false | ||
if (!title) { | ||
const titleLine = line.match(/## (.*)/) | ||
if (titleLine) { | ||
title = titleLine[1] | ||
} | ||
} | ||
const indexHomeLink = line.match(/\[Home\]\(.\/index\.md\)/) | ||
const homeLink = line.match(/\[Home\]\(.\/index\.md\) > (.*)/) | ||
if (homeLink) { | ||
line = line.replace('Home', 'Packages') | ||
} | ||
|
||
if (indexHomeLink) { | ||
// Skip the breadcrumb for the toplevel index file. | ||
if (id === 'index') { | ||
skip = true | ||
} | ||
|
||
skip = true | ||
} | ||
|
||
// See issue #4. api-documenter expects \| to escape table | ||
// column delimiters, but docusaurus uses a markdown processor | ||
// that doesn't support this. Replace with an escape sequence | ||
// that renders |. | ||
if (line.startsWith('|')) { | ||
line = line.replace(/\\\|/g, '|') | ||
} | ||
|
||
// MDX cries when you put commects in there :( | ||
line = replaceAll(line, '<!-- -->', '') | ||
|
||
if (id === 'core') { | ||
line = line.replace('core package', 'Veramo Core') | ||
} | ||
|
||
if (!skip) { | ||
output.push(line) | ||
} | ||
}) | ||
|
||
await new Promise((resolve) => lines.once('close', resolve)) | ||
input.close() | ||
|
||
const header = ['---', `id: ${id}`, `title: ${title}`, `hide_title: true`, '---'] | ||
|
||
await writeFile(docPath, header.concat(output).join('\n')) | ||
} catch (err) { | ||
console.error(`Could not process ${docFile}: ${err}`) | ||
} | ||
} | ||
} | ||
|
||
function escapeRegExp(string: string) { | ||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // $& means the whole matched string | ||
} | ||
|
||
function replaceAll(str: string, find: string, replace: string) { | ||
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as path from 'path' | ||
import { resolve } from 'path' | ||
import { existsSync, readdirSync, copyFileSync, mkdirSync, unlinkSync } from 'fs' | ||
|
||
const outputFolder = './temp' | ||
const { documentPackages } = require('../docsconfig.json') | ||
|
||
if (!existsSync(resolve(outputFolder))) { | ||
console.log('Creating', outputFolder) | ||
mkdirSync(resolve(outputFolder)) | ||
} else { | ||
console.log('Removing files in', outputFolder) | ||
readdirSync(resolve(outputFolder)).forEach((file) => { | ||
unlinkSync(resolve(outputFolder, file)) | ||
}) | ||
} | ||
|
||
for (const packageName of documentPackages) { | ||
const apiDocsPath: string = path.join(__dirname, `../packages/${packageName}/api`) | ||
|
||
readdirSync(apiDocsPath).forEach((file) => { | ||
console.log('Copying', resolve(outputFolder, file)) | ||
copyFileSync(resolve(apiDocsPath, file), resolve(outputFolder, file)) | ||
}) | ||
} |
Oops, something went wrong.