Skip to content

Commit

Permalink
docs: enhance ci build
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 3, 2022
1 parent cdfba22 commit 8cb4069
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 73 deletions.
94 changes: 26 additions & 68 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name: Test

on:
- push
- pull_request
- workflow_dispatch

env:
CI: true
push:
pull_request:
workflow_dispatch:
schedule:
- cron: 30 1/6 * * *

jobs:
prepare:
Expand All @@ -18,10 +17,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 +27,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 +48,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 All @@ -81,6 +76,7 @@ jobs:
plugins
lint:
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
needs:
- prepare
Expand All @@ -91,23 +87,24 @@ 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
run: yarn lint

unit-test:
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
needs:
- prepare
Expand All @@ -128,20 +125,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 All @@ -150,45 +147,6 @@ jobs:
file: ./coverage/coverage-final.json
name: codecov

publish:
if: ${{ github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
needs:
- prepare
- build
- unit-test

env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

steps:
- name: Check out
uses: actions/checkout@v3
- name: Create .npmrc
run: 'echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc'
- name: Set up Node
uses: actions/setup-node@v2
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: Publish
run: yarn pub

docs:
if: ${{ github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
Expand All @@ -202,17 +160,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 Expand Up @@ -263,17 +221,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 8cb4069

Please sign in to comment.