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

Improving documentation CI workflows #922

Merged
merged 27 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0b28542
ci: Adding docs tasks
italobb Jun 1, 2022
6fd9e6e
ci: Adding docs build to CI
italobb Jun 1, 2022
4efedff
ci: Adding CI workflow to execute veramo-website action
italobb Jun 1, 2022
4a3a611
ci: Fixing docs generator
italobb Jun 3, 2022
f5b4833
ci: removing Github token
italobb Jun 3, 2022
e1f2362
ci: Changing the Github Token for docs trigger
italobb Jun 3, 2022
af8b52f
ci: Changing the Github Token for docs trigger
italobb Jun 3, 2022
b640c05
ci: Adding docusaurus dependency
italobb Jun 6, 2022
76cb63c
docs: fixing generated API docs
italobb Jun 7, 2022
7cd4eac
docs: replacing comments by empty string in docs
italobb Jun 8, 2022
5928242
ci: workflow dispatch for veramo-website
italobb Jun 8, 2022
5611d15
ci: attempt to veramo-website workflow dispatch
italobb Jun 8, 2022
32dce39
ci: attempt to veramo-website workflow dispatch
italobb Jun 8, 2022
7bd4a68
ci: attempt to veramo-website workflow dispatch
italobb Jun 8, 2022
2d0139a
ci: attempt to veramo-website workflow dispatch
italobb Jun 8, 2022
1995ba2
ci: attempt to veramo-website workflow dispatch
italobb Jun 8, 2022
52efe1d
ci: attempt to veramo-website workflow dispatch
italobb Jun 8, 2022
7e34084
ci: attempt to veramo-website workflow dispatch
italobb Jun 8, 2022
1f60dbd
ci: attempt to veramo-website workflow dispatch
italobb Jun 8, 2022
9bd73b4
ci: attempt to veramo-website workflow dispatch
italobb Jun 8, 2022
1a9f322
ci: attempt to veramo-website workflow dispatch
italobb Jun 8, 2022
93289e6
Merge branch 'main' into italo/fix-docs
italobb Jun 8, 2022
99778bd
ci: using repository_dispatch instead of workflow_dispatch
italobb Jun 10, 2022
96f14c9
ci: running website deploy only for main branch pushes
italobb Jun 10, 2022
e89cbc0
fix: removing extract-api script
italobb Jun 10, 2022
13b8245
fix: removing unecessary changes
italobb Jun 10, 2022
ad0a917
Update .github/workflows/veramo-website.yml
italobb Jun 10, 2022
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
11 changes: 5 additions & 6 deletions .github/workflows/build-and-test-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
italobb marked this conversation as resolved.
Show resolved Hide resolved
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v2
- uses: actions/setup-node@v2
with:
node-version: '14.x'

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand All @@ -30,7 +26,9 @@ jobs:
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-2-${{ hashFiles('**/package.json') }}

- name: Get yarn cache directory path
italobb marked this conversation as resolved.
Show resolved Hide resolved
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- run: yarn install --frozen-lockfile
- run: yarn bootstrap
- run: yarn build
Expand All @@ -42,5 +40,6 @@ jobs:
POSTGRES_PASSWORD: test123
POSTGRES_PORT: 5432
run: yarn test:integration
- run: yarn docs
- run: yarn lint
- run: npx codecov
3 changes: 2 additions & 1 deletion .github/workflows/build-test-publish-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ jobs:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: test123
POSTGRES_PORT: 5432
run: yarn test:integration
run: yarn test:integration
- run: yarn docs

- name: setup git coordinates
run: |
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/veramo-website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Trigger veramo-website build
on:
push:
italobb marked this conversation as resolved.
Show resolved Hide resolved
branches:
- "main"
- "italo/fix-docs"
permissions: write-all
italobb marked this conversation as resolved.
Show resolved Hide resolved
jobs:
dispatch:
permissions:
contents: write
actions: write
runs-on: ubuntu-latest
steps:
- run: |
curl -X POST \
-H 'Authorization: Bearer ${{ secrets.GH_TOKEN }}' \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/uport-project/veramo-website/actions/workflows/main.yml/dispatches \
italobb marked this conversation as resolved.
Show resolved Hide resolved
-d '{"ref":"main"}'
24 changes: 15 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@
"test": "jest --config=jest.json --coverage=false",
"test:watch": "yarn test --watch --verbose",
"veramo": "./packages/cli/bin/veramo.js",
"prettier": "prettier --write '{packages,__tests__, !build}/**/*.{ts,js,json,md,yml}'",
"prettier": "prettier --write '{packages,docs,__tests__, !build}/**/*.{ts,js,json,md,yml}'",
"build-clean": "rimraf ./packages/*/build ./packages/*/api ./packages/*/node_modules ./packages/*/tsconfig.tsbuildinfo && jest --clearCache",
"publish:latest": "lerna publish --conventional-commits --include-merged-tags --create-release github --yes --dist-tag latest --registry https://registry.npmjs.org/:_authToken=${NPM_TOKEN}",
"publish:next": "lerna publish --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid next --pre-dist-tag next --yes --registry https://registry.npmjs.org/:_authToken=${NPM_TOKEN}",
"publish:unstable": "lerna publish --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid unstable --pre-dist-tag unstable --yes --registry https://registry.npmjs.org/:_authToken=${NPM_TOKEN}"
"publish:unstable": "lerna publish --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid unstable --pre-dist-tag unstable --yes --registry https://registry.npmjs.org/:_authToken=${NPM_TOKEN}",
"docs": "yarn docs:extract && yarn docs:copy && yarn docs:build",
"docs:extract": "ts-node ./scripts/docs-extract.ts",
"docs:copy": "ts-node ./scripts/docs-copy.ts",
"docs:build": "ts-node ./scripts/docs-build.ts && yarn docs:pretty",
"docs:pretty": "pretty-quick"
},
"workspaces": [
"packages/*"
],
"devDependencies": {
"@microsoft/api-documenter": "7.13.68",
"@microsoft/api-extractor": "7.18.19",
"@microsoft/api-extractor-model": "7.13.16",
"devDependencies": {
"@microsoft/api-documenter": "^7.17.17",
"@microsoft/api-extractor": "^7.25.0",
"@microsoft/api-extractor-model": "^7.18.0",
"@types/fs-extra": "^9.0.13",
"@types/jest": "27.0.2",
"codecov": "3.8.3",
"cross-fetch": "3.1.4",
Expand All @@ -44,9 +50,9 @@
"rimraf": "3.0.2",
"semantic-release": "18.0.0",
"ts-jest": "27.0.7",
"ts-json-schema-generator": "0.97.0",
"ts-node": "10.4.0",
"typescript": "4.4.4"
"ts-json-schema-generator": "1.0.0",
"ts-node": "10.8.0",
"typescript": "4.6.3"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ dev
const packageConfig = require(resolve(options.packageConfig))
const interfaces: any = {}

for (const pluginInterfaceName in packageConfig.veramo.pluginInterfaces) {
for (const pluginInterfaceName in packageConfig?.veramo?.pluginInterfaces) {
const entryFile = packageConfig.veramo.pluginInterfaces[pluginInterfaceName]
const api = {
components: {
Expand Down
104 changes: 104 additions & 0 deletions scripts/docs-build.ts
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()
25 changes: 25 additions & 0 deletions scripts/docs-copy.ts
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))
})
}
30 changes: 30 additions & 0 deletions scripts/docs-extract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as path from 'path'
italobb marked this conversation as resolved.
Show resolved Hide resolved
import { Extractor, ExtractorConfig, ExtractorResult } from '@microsoft/api-extractor'

const { documentPackages } = require('../docsconfig.json')

documentPackages.map((packageName: string) => {
const apiExtractorJsonPath: string = path.join(__dirname, `../packages/${packageName}/api-extractor.json`)
// Load and parse the api-extractor.json file
const extractorConfig: ExtractorConfig = ExtractorConfig.loadFileAndPrepare(apiExtractorJsonPath)

// Invoke API Extractor
const extractorResult: ExtractorResult = Extractor.invoke(extractorConfig, {
// Equivalent to the "--local" command-line parameter
localBuild: true,

// Equivalent to the "--verbose" command-line parameter
showVerboseMessages: true,
})

if (extractorResult.succeeded) {
console.log(`API Extractor completed successfully`)
process.exitCode = 0
} else {
console.error(
`API Extractor completed with ${extractorResult.errorCount} errors` +
` and ${extractorResult.warningCount} warnings`,
)
process.exitCode = 1
}
})
Loading