Skip to content

Commit

Permalink
fix(ci): improve documentation CI workflows (#922)
Browse files Browse the repository at this point in the history
* 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
italobb committed Jun 10, 2022
1 parent 67bd742 commit 0579764
Show file tree
Hide file tree
Showing 8 changed files with 2,760 additions and 2,205 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-and-test-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-2-${{ hashFiles('**/package.json') }}

- run: yarn install --frozen-lockfile
- run: yarn bootstrap
- run: yarn build
Expand All @@ -42,5 +42,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
18 changes: 18 additions & 0 deletions .github/workflows/veramo-website.yml
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"}'
23 changes: 14 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,24 @@
"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:copy && yarn docs:build",
"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 +49,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))
})
}
Loading

0 comments on commit 0579764

Please sign in to comment.