Skip to content

Commit

Permalink
docs: reuse action workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 3, 2022
1 parent cdfba22 commit a13f0aa
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 83 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Docs

on:
workflow_dispatch:
schedule:
- cron: 30 1/6 * * *

jobs:
docs:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 16
- id: cache
name: Yarn Cache Dir
run: echo "::set-output name=value::$(yarn cache dir)"
- name: Restore Lockfile
uses: actions/cache@v2
with:
path: yarn.lock
key: yarn-lock-${{ runner.os }}-${{ github.sha }}
- name: Restore Cache
uses: actions/cache@v2
with:
path: ${{ steps.cache.outputs.value }}
key: yarn-cache-${{ runner.os }}-${{ github.sha }}-node-16
- name: Install
run: yarn
- name: Download
uses: actions/download-artifact@v3
with:
name: packages
- name: Checkout koishi-plugin-dialogue
uses: actions/checkout@v3
with:
repository: koishijs/koishi-plugin-dialogue
path: external/dialogue
- name: Checkout koishi-plugin-eval
uses: actions/checkout@v3
with:
repository: koishijs/koishi-plugin-eval
path: external/eval
- name: Checkout koishi-plugin-github
uses: actions/checkout@v3
with:
repository: koishijs/koishi-plugin-github
path: external/github
- name: Create Symlinks
run: |
ln -s ../../external/dialogue/docs ./docs/community/dialogue
ln -s ../../external/eval/docs ./docs/community/eval
ln -s ../../external/github/docs ./docs/community/github
- name: Build
run: yarn docs build
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: docs/.vuepress/dist
publish_branch: master
external_repository: koishijs/koishijs.github.io
force_orphan: true
101 changes: 23 additions & 78 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ name: Test
on:
- push
- pull_request
- workflow_dispatch

env:
CI: true

jobs:
prepare:
Expand All @@ -18,10 +14,7 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 14
- id: random
name: Generate UUID
run: echo "::set-output name=value::$(openssl rand -hex 10)"
node-version: 16
- id: cache
name: Yarn Cache Dir
run: echo "::set-output name=value::$(yarn cache dir)"
Expand All @@ -31,15 +24,14 @@ jobs:
uses: actions/cache@v2
with:
path: yarn.lock
key: yarn-lock-${{ runner.os }}-${{ steps.random.outputs.value }}
key: yarn-lock-${{ runner.os }}-${{ github.sha }}
- name: Prepare Cache
uses: actions/cache@v2
with:
path: ${{ steps.cache.outputs.value }}
key: yarn-cache-${{ runner.os }}-${{ steps.random.outputs.value }}-node-14
key: yarn-cache-${{ runner.os }}-${{ github.sha }}-node-16

outputs:
random-uuid: ${{ steps.random.outputs.value }}
cache-dir: ${{ steps.cache.outputs.value }}

build:
Expand All @@ -53,17 +45,17 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 14
node-version: 16
- name: Restore Lockfile
uses: actions/cache@v2
with:
path: yarn.lock
key: yarn-lock-${{ runner.os }}-${{ needs.prepare.outputs.random-uuid }}
key: yarn-lock-${{ runner.os }}-${{ github.sha }}
- name: Restore Cache
uses: actions/cache@v2
with:
path: ${{ needs.prepare.outputs.cache-dir }}
key: yarn-cache-${{ runner.os }}-${{ needs.prepare.outputs.random-uuid }}-node-14
key: yarn-cache-${{ runner.os }}-${{ github.sha }}-node-16
- name: Install
run: yarn
- name: Build JS
Expand Down Expand Up @@ -91,17 +83,17 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 14
node-version: 16
- name: Restore Lockfile
uses: actions/cache@v2
with:
path: yarn.lock
key: yarn-lock-${{ runner.os }}-${{ needs.prepare.outputs.random-uuid }}
key: yarn-lock-${{ runner.os }}-${{ github.sha }}
- name: Restore Cache
uses: actions/cache@v2
with:
path: ${{ needs.prepare.outputs.cache-dir }}
key: yarn-cache-${{ runner.os }}-${{ needs.prepare.outputs.random-uuid }}-node-14
key: yarn-cache-${{ runner.os }}-${{ github.sha }}-node-16
- name: Install
run: yarn
- name: Lint
Expand All @@ -128,20 +120,20 @@ jobs:
uses: actions/cache@v2
with:
path: yarn.lock
key: yarn-lock-${{ runner.os }}-${{ needs.prepare.outputs.random-uuid }}
key: yarn-lock-${{ runner.os }}-${{ github.sha }}
- name: Restore Cache
uses: actions/cache@v2
with:
path: ${{ needs.prepare.outputs.cache-dir }}
key: yarn-cache-${{ runner.os }}-${{ needs.prepare.outputs.random-uuid }}-node-${{ matrix.node-version }}
key: yarn-cache-${{ runner.os }}-${{ github.sha }}-node-${{ matrix.node-version }}
restore-keys: |
yarn-lock-${{ runner.os }}-${{ needs.prepare.outputs.random-uuid }}-node
yarn-lock-${{ runner.os }}-${{ github.sha }}-node
- name: Install
run: yarn
- name: Build JS
run: yarn compile
- name: Unit Test
run: yarn test:json --mongo-ports=27017 --mysql-ports=3306,3307,3308
run: yarn test:json
- name: Report Coverage
if: ${{ matrix.node-version == 14 }}
uses: codecov/codecov-action@v1
Expand Down Expand Up @@ -169,17 +161,17 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 14
node-version: 16
- name: Restore Lockfile
uses: actions/cache@v2
with:
path: yarn.lock
key: yarn-lock-${{ runner.os }}-${{ needs.prepare.outputs.random-uuid }}
key: yarn-lock-${{ runner.os }}-${{ github.sha }}
- name: Restore Cache
uses: actions/cache@v2
with:
path: ${{ needs.prepare.outputs.cache-dir }}
key: yarn-cache-${{ runner.os }}-${{ needs.prepare.outputs.random-uuid }}-node-14
key: yarn-cache-${{ runner.os }}-${{ github.sha }}-node-16
- name: Install
run: yarn
- name: Download
Expand All @@ -197,58 +189,11 @@ jobs:
- build

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v2
- name: Trigger Docs
uses: benc-uk/workflow-dispatch@v1
with:
node-version: 14
- name: Restore Lockfile
uses: actions/cache@v2
with:
path: yarn.lock
key: yarn-lock-${{ runner.os }}-${{ needs.prepare.outputs.random-uuid }}
- name: Restore Cache
uses: actions/cache@v2
with:
path: ${{ needs.prepare.outputs.cache-dir }}
key: yarn-cache-${{ runner.os }}-${{ needs.prepare.outputs.random-uuid }}-node-14
- name: Install
run: yarn
- name: Download
uses: actions/download-artifact@v3
with:
name: packages
- name: Checkout koishi-plugin-dialogue
uses: actions/checkout@v3
with:
repository: koishijs/koishi-plugin-dialogue
path: external/dialogue
- name: Checkout koishi-plugin-eval
uses: actions/checkout@v3
with:
repository: koishijs/koishi-plugin-eval
path: external/eval
- name: Checkout koishi-plugin-github
uses: actions/checkout@v3
with:
repository: koishijs/koishi-plugin-github
path: external/github
- name: Create Symlinks
run: |
ln -s ../../external/dialogue/docs ./docs/community/dialogue
ln -s ../../external/eval/docs ./docs/community/eval
ln -s ../../external/github/docs ./docs/community/github
- name: Build
run: yarn docs build
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: docs/.vuepress/dist
publish_branch: master
external_repository: koishijs/koishijs.github.io
force_orphan: true
workflow: Docs
token: ${{ secrets.WORKFLOW_TOKEN }}

docs-next:
if: ${{ github.ref == 'refs/heads/next' }}
Expand All @@ -263,17 +208,17 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 14
node-version: 16
- name: Restore Lockfile
uses: actions/cache@v2
with:
path: yarn.lock
key: yarn-lock-${{ runner.os }}-${{ needs.prepare.outputs.random-uuid }}
key: yarn-lock-${{ runner.os }}-${{ github.sha }}
- name: Restore Cache
uses: actions/cache@v2
with:
path: ${{ needs.prepare.outputs.cache-dir }}
key: yarn-cache-${{ runner.os }}-${{ needs.prepare.outputs.random-uuid }}-node-14
key: yarn-cache-${{ runner.os }}-${{ github.sha }}-node-16
- name: Install
run: yarn
- name: Download
Expand Down
7 changes: 5 additions & 2 deletions docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { execSync } from 'child_process'
import { resolve } from 'path'
import { remove as removeDiacritics } from 'diacritics'
import { readdirSync } from 'fs'
Expand All @@ -18,6 +17,10 @@ for (const dirent of dirents) {
communitySidebar.push(require(communityFolder + '/' + dirent.name))
}

const hash = process.env.GITHUB_SHA
? ` (${process.env.GITHUB_SHA.slice(0, 7)})`
: ''

module.exports = {
base: '/',
title: 'Koishi',
Expand Down Expand Up @@ -47,7 +50,7 @@ module.exports = {
theme: theme({
logo: '/koishi.png',
navbar: [{
text: `v4.x (${execSync('git log -1 --format=%h').toString().trim()})`,
text: 'v4.x' + hash,
children: [{
text: 'v3.x',
link: 'https://koishi.js.org/v3/',
Expand Down
2 changes: 1 addition & 1 deletion docs/.vuepress/layouts/home/screen-6.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const { width, height } = useWindowSize()
const config = useThemeLocaleData().value
function getSidebarItems(route: string) {
return resolveArraySidebarItems(config.sidebar[route].filter(item => item.isGroup), 1)
return resolveArraySidebarItems(config.sidebar[route].filter(item => item.children), 1)
}
</script>
Expand Down
3 changes: 1 addition & 2 deletions docs/.vuepress/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import popup from '@vuepress/plugin-pwa-popup'
import container from '@vuepress/plugin-container'
import docsearch from '@vuepress/plugin-docsearch'
import zoom from '@vuepress/plugin-medium-zoom'
import { redirect } from 'vuepress-plugin-redirect2'

export default (options: DefaultThemeOptions): Theme => ({
name: 'vuepress-theme-local',
extends: defaultTheme(),
extends: defaultTheme(options),

layouts: {
Layout: require.resolve('./layouts/Layout.vue'),
Expand Down

0 comments on commit a13f0aa

Please sign in to comment.