build(CI): 弃用 travis-ci,改用 github actions 进行 CI

pull/19/head
dunwu 2022-04-11 16:51:22 +08:00
parent b48d14643b
commit 106f0031cf
7 changed files with 103 additions and 76 deletions

36
.github/workflows/deploy.yml vendored 100644
View File

@ -0,0 +1,36 @@
name: CI
# 在master分支发生push事件时触发。
on:
push:
branches:
- master
env: # 设置环境变量
TZ: Asia/Shanghai # 时区(设置时区可使页面中的`最近更新时间`使用时区时间)
jobs:
build: # 自定义名称
runs-on: ubuntu-latest # 运行在虚拟机环境ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
# 使用的动作。格式userName/repoName。作用检出仓库获取源码。 官方actions库https://github.com/actions
- name: Checkout
uses: actions/checkout@master
# 指定 nodejs 版本
- name: Use Nodejs ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
# 部署
- name: Deploy
env: # 设置环境变量
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }}
run: npm install && npm run deploy

View File

@ -1,24 +0,0 @@
# 持续集成 CI
# @see https://docs.travis-ci.com/user/tutorial/
language: node_js
sudo: required
node_js: '16.13.0'
branches:
only:
- master
before_install:
- export TZ=Asia/Shanghai
script: bash ./scripts/deploy.sh
notifications:
email:
recipients:
- forbreak@163.com
on_success: change
on_failure: always

View File

@ -13,5 +13,6 @@
"MD036": false,
"fenced-code-language": false,
"no-hard-tabs": false,
"whitespace": false
"whitespace": false,
"emphasis-style": { "style": "consistent" }
}

View File

@ -1,30 +0,0 @@
{
"name": "db-tutorial",
"version": "1.0.0",
"private": true,
"scripts": {
"clean": "rimraf dist && rimraf .temp",
"build": "npm run clean && vuepress build ./ --temp .temp",
"start": "vuepress dev ./ --temp .temp",
"lint": "markdownlint -r markdownlint-rule-emphasis-style -c ./.markdownlint.json **/*.md -i node_modules",
"lint:fix": "markdownlint -f -r markdownlint-rule-emphasis-style -c ./.markdownlint.json **/*.md -i node_modules",
"show-help": "vuepress --help",
"view-info": "vuepress view-info ./ --temp .temp"
},
"devDependencies": {
"@vuepress/plugin-active-header-links": "^1.8.2",
"@vuepress/plugin-back-to-top": "^1.8.2",
"@vuepress/plugin-medium-zoom": "^1.8.2",
"@vuepress/plugin-pwa": "^1.8.2",
"@vuepress/theme-vue": "^1.8.2",
"markdownlint-cli": "^0.30.0",
"markdownlint-rule-emphasis-style": "^1.0.1",
"rimraf": "^3.0.1",
"vue-toasted": "^1.1.25",
"vuepress": "^1.8.2",
"vuepress-plugin-flowchart": "^1.5.0"
},
"dependencies": {
"moment": "^2.29.1"
}
}

37
package.json 100644
View File

@ -0,0 +1,37 @@
{
"name": "java-tutorial",
"version": "1.0.0",
"scripts": {
"clean": "rimraf docs/.temp",
"start": "vuepress dev docs",
"build": "vuepress build docs",
"deploy": "bash scripts/deploy.sh",
"updateTheme": "yarn remove vuepress-theme-vdoing && rm -rf node_modules && yarn && yarn add vuepress-theme-vdoing -D",
"editFm": "node utils/editFrontmatter.js",
"lint": "markdownlint -r markdownlint-rule-emphasis-style -c ./.markdownlint.json **/*.md -i node_modules",
"lint:fix": "markdownlint -f -r markdownlint-rule-emphasis-style -c ./.markdownlint.json **/*.md -i node_modules",
"show-help": "vuepress --help",
"view-info": "vuepress view-info ./ --temp docs/.temp"
},
"license": "MIT",
"devDependencies": {
"dayjs": "^1.9.7",
"inquirer": "^7.1.0",
"json2yaml": "^1.1.0",
"vuepress": "1.9.2",
"vuepress-plugin-baidu-tongji": "^1.0.1",
"vuepress-plugin-demo-block": "^0.7.2",
"vuepress-plugin-fulltext-search": "^2.2.1",
"vuepress-plugin-one-click-copy": "^1.0.2",
"vuepress-plugin-thirdparty-search": "^1.0.2",
"vuepress-plugin-zooming": "^1.1.7",
"vuepress-plugin-flowchart": "^1.4.2",
"vuepress-theme-vdoing": "^1.10.3",
"yamljs": "^0.3.0",
"markdownlint-cli": "^0.25.0",
"markdownlint-rule-emphasis-style": "^1.0.1",
"rimraf": "^3.0.1",
"vue-toasted": "^1.1.25"
},
"dependencies": {}
}

View File

@ -0,0 +1,7 @@
/**
* @see https://prettier.io/docs/en/options.html
* @see https://prettier.io/docs/en/configuration.html
*/
module.exports = {
tabWidth: 2, semi: false, singleQuote: true
}

View File

@ -7,40 +7,40 @@
# ------------------------------------------------------------------------------
# 装载其它库
ROOT_DIR=$(cd `dirname $0`/..; pwd)
ROOT_DIR=$(
cd $(dirname $0)/..
pwd
)
# 确保脚本抛出遇到的错误
set -e
cd ${ROOT_DIR}/docs
# 生成静态文件
npm install
npm run build
# 进入生成的文件夹
cd dist
cd ${ROOT_DIR}/docs/.temp
# 如果是发布到自定义域名
# echo 'www.example.com' > CNAME
git init
git checkout -b gh-pages && git add .
git commit -m 'deploy'
# 如果发布到 https://<USERNAME>.github.io/<REPO>
GITHUB_REPO=github.com/dunwu/db-tutorial.git
GITEE_REPO=gitee.com/turnon/db-tutorial.git
if [[ ${GITHUB_TOKEN} && ${GITEE_TOKEN} ]]; then
echo "使用 token 公钥部署 gh-pages"
# ${GITHUB_TOKEN} 是 Github 私人令牌;${GITEE_TOKEN} 是 Gitee 私人令牌
# ${GITHUB_TOKEN} 和 ${GITEE_TOKEN} 都是环境变量travis-ci 构建时会传入变量
git push --force --quiet "https://dunwu:${GITHUB_TOKEN}@${GITHUB_REPO}" gh-pages
git push --force --quiet "https://turnon:${GITEE_TOKEN}@${GITEE_REPO}" gh-pages
msg='自动部署'
GITHUB_URL=https://dunwu:${GITHUB_TOKEN}@github.com/dunwu/db-tutorial.git
GITEE_URL=https://turnon:${GITEE_TOKEN}@gitee.com/turnon/db-tutorial.git
git config --global user.name "dunwu"
git config --global user.email "forbreak@163.com"
else
echo "使用 ssh 公钥部署 gh-pages"
git push -f git@github.com:dunwu/db-tutorial.git gh-pages
git push -f git@gitee.com:turnon/db-tutorial.git gh-pages
msg='手动部署'
GITHUB_URL=git@github.com:dunwu/db-tutorial.git
GITEE_URL=git@gitee.com:turnon/db-tutorial.git
fi
git init
git add -A
git commit -m "${msg}"
# 推送到github gh-pages分支
git push -f "${GITHUB_URL}" master:gh-pages
git push -f "${GITEE_URL}" master:gh-pages
cd ${ROOT_DIR}
cd -
rm -rf ${ROOT_DIR}/docs/.temp