From 6a67b1cf3fd7cc130a1932cf6ced54f775fc10e5 Mon Sep 17 00:00:00 2001 From: xugaoyi <894072666@qq.com> Date: Thu, 19 Dec 2019 15:37:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 8 +- README.MD | 126 ++++++++++++++++++++++++++++++-- deploy.sh | 35 ++++----- deployToCoding.sh | 12 --- docs/.vuepress/config.js | 9 +-- docs/about/readme.md | 2 +- docs/other/LearningAndMemory.md | 2 +- package.json | 3 +- 8 files changed, 146 insertions(+), 51 deletions(-) delete mode 100644 deployToCoding.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38ab804..727f608 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,19 +22,17 @@ jobs: # 工作流 uses: actions/setup-node@v1 # 作用:安装nodejs with: node-version: ${{ matrix.node-version }} # 版本 - - name: run deploy.sh + - name: run deploy.sh # 步骤3 (同时部署到github和coding) env: # 设置环境变量 GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} # toKen私密变量 CODING_TOKEN: ${{ secrets.CODING_TOKEN }} # 腾讯云开发者平台(coding)私密token run: npm install && npm run deploy - # - name: Build and Deploy # 步骤3 + # - name: Build and Deploy # 步骤3 (只提交到github可以使用这个步骤) # uses: JamesIves/github-pages-deploy-action@master # 作用:将项目构建和部署到github。 https://github.com/JamesIves/github-pages-deploy-action # env: # 设置环境变量 # ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} # toKen私密变量 - # CODING_TOKEN: ${{ secrets.CODING_TOKEN }} # 腾讯云开发者平台(coding)私密token # BASE_BRANCH: master # 要部署的文件夹所在的分支. # BRANCH: gh-pages # 部署到的分支 # FOLDER: docs/.vuepress/dist # 要部署的文件夹. - # BUILD_SCRIPT: npm install && npm run build && npm run deployToCoding && cd docs/.vuepress/dist && echo 'b.evanblogweb.com' > CNAME && cd - # 部署前要执行的命令,记得进入某个目录后要后面要退回开始的目录 - # # npm run deployToCoding 此命令是部署到腾讯云开发者平台(coding) \ No newline at end of file + # BUILD_SCRIPT: npm install && npm run build && cd docs/.vuepress/dist && echo 'b.evanblogweb.com' > CNAME && cd - # 部署前要执行的命令(记得cd进入某个目录后,后面要cd -退回开始的目录) \ No newline at end of file diff --git a/README.MD b/README.MD index 45c987b..770c7b8 100644 --- a/README.MD +++ b/README.MD @@ -60,23 +60,137 @@ npm run deploy # 运行部署脚本deploy.sh,并发布到仓库的gh-pages分支 ##### 2)、使用GitHub Action自动持续集成 -第一步,按照[官方文档](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line),生成一个GitHub 密钥。 +第一步,按照[官方文档](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line),生成一个github token (令牌)。 第二步,将这个密钥储存到当前仓库的`Settings/Secrets`里面。 > `Settings/Secrets`是储存秘密的环境变量的地方。环境变量的名字可以随便起,这里用的是`ACCESS_TOKEN`。如果你不用这个名字,`.github/workflows/ci.yml`脚本里的变量名也要跟着改。 -第三步,提交代码到GitHub仓库master分支。 +第三步,push提交代码到GitHub仓库master分支。 第四步,设置GitHub Pages为gh-pages分支。 -参考 [教程](http://www.ruanyifeng.com/blog/2019/09/getting-started-with-github-actions.html) - > 注意:如果您有自定义域名,需要在`.github/workflows/ci.yml`中修改`evanblogweb.com`为你的域名。 > > 如没有自定义域名,需要在`.github/workflows/ci.yml`中去掉`cd docs/.vuepress/dist && echo 'evanblogweb.com' > CNAME && cd -`命令 +> +> 参考 [GitHub Action教程](http://www.ruanyifeng.com/blog/2019/09/getting-started-with-github-actions.html) + + + +#### 5、部署升级:同时部署到github和[coding](https://dev.tencent.com/) + +为了让博客站能够让百度收录,因此我把博客部署到了coding(腾讯云开发者平台),相关[文章](https://evanblogweb.com/other/baidushoulu.html)。 + +在原有部署方式上做了升级,同时部署到github和coding。 + +`deploy.sh`文件: + +> 看不懂代码shell代码? 参考: + +```sh +#!/usr/bin/env sh +set -e # 确保脚本抛出遇到的错误 +npm run build # 生成静态文件 +cd docs/.vuepress/dist # 进入生成的文件夹 + +# deploy to coding +echo 'www.evanblogweb.com\nevanblogweb.com' > CNAME # 自定义域名 +if [ -z "$CODING_TOKEN" ]; then # -z <字符串> 长度为0则为true;$CODING_TOKEN来自于github仓库`Settings/Secrets`设置的私密环境变量 + msg='deploy' + codingUrl=git@git.dev.tencent.com:xugaoyi/xugaoyi.git +else + msg='来自github action的自动部署' + codingUrl=https://xugaoyi:${CODING_TOKEN}@git.dev.tencent.com/xugaoyi/xugaoyi.git + git config --global user.name "xugaoyi" + git config --global user.email "894072666@qq.com" +fi +git init +git add -A +git commit -m ${msg} +git push -f $codingUrl master # 推送到coding + +# deploy to github +echo 'b.evanblogweb.com' > CNAME +if [ -z "$GITHUB_TOKEN" ]; then + githubUrl=git@github.com:xugaoyi/evanblog.git +else + githubUrl=https://xugaoyi:${GITHUB_TOKEN}@github.com/xugaoyi/evanblog.git +fi +git add -A +git commit -m ${msg} +git push -f $githubUrl master:gh-pages # 推送到github + +cd - # 退回开始所在目录 +rm -rf docs/.vuepress/dist +``` + + + +`ci.yml`文件: + +> 看不懂yaml代码? 参考: + +```yaml +name: CI + +# 在master分支发生push事件时触发。 +on: + push: + branches: + - master +jobs: # 工作流 + build: + runs-on: ubuntu-latest #运行在虚拟机环境ubuntu-latest + + strategy: + matrix: + node-version: [10.x] + + steps: # 步骤 + - name: Checkout # 步骤1 + uses: actions/checkout@v1 # 使用的动作。格式:userName/repoName。作用:检出仓库,获取源码。 官方actions库:https://github.com/actions + - name: Use Node.js ${{ matrix.node-version }} # 步骤2 + uses: actions/setup-node@v1 # 作用:安装nodejs + with: + node-version: ${{ matrix.node-version }} # 版本 + - name: run deploy.sh # 步骤3 (同时部署到github和coding) + env: # 设置环境变量 + GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} # toKen私密变量 + CODING_TOKEN: ${{ secrets.CODING_TOKEN }} # 腾讯云开发者平台(coding)私密token + run: npm install && npm run deploy + + # - name: Build and Deploy # 步骤3 (只部署到github可以使用这个步骤) + # uses: JamesIves/github-pages-deploy-action@master # 作用:将项目构建和部署到github。 https://github.com/JamesIves/github-pages-deploy-action + # env: # 设置环境变量 + # ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} # toKen私密变量 + # BASE_BRANCH: master # 要部署的文件夹所在的分支. + # BRANCH: gh-pages # 部署到的分支 + # FOLDER: docs/.vuepress/dist # 要部署的文件夹. + # BUILD_SCRIPT: npm install && npm run build && cd docs/.vuepress/dist && echo 'b.evanblogweb.com' > CNAME && cd - # 部署前要执行的命令(记得cd进入某个目录后,后面要cd -退回开始的目录) +``` + +使用前先将[github token (令牌) ](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line)和[coding token (令牌)](https://dev.tencent.com/help/doc/account/access-token) 同时设置到github仓库的`Settings/Secrets`位置。 + +![token设置](https://raw.githubusercontent.com/xugaoyi/image_store/master/blog/token.jpg) + +##### 部署方式有两种: + +##### 1) 、使用如下命令一键部署到github和coding + +```sh +npm run deploy +``` + +##### 2)、使用GitHub Action自动部署到github和coding + +只需要push提交代码到github仓库master分支即可。 + +> 参考 [GitHub Action教程](http://www.ruanyifeng.com/blog/2019/09/getting-started-with-github-actions.html) + + @@ -98,11 +212,11 @@ npm run deploy # 运行部署脚本deploy.sh,并发布到仓库的gh-pages分支 * 域名列表中点击`解析` -![dns1](https://raw.githubusercontent.com/xugaoyi/image_store/master/blogdns1.png) +![dns1](https://raw.githubusercontent.com/xugaoyi/image_store/master/blog/dns1.png) * 进入解析页面后,点击`添加记录`。填入,记录类型:`CNAME`,主机记录:`www`,解析线路:默认,记录值:你的github pages地址`.github.io`,TTL:默认的10分钟,确定。 -![dns2](https://raw.githubusercontent.com/xugaoyi/image_store/master/blogdns2.png) +![dns2](https://raw.githubusercontent.com/xugaoyi/image_store/master/blog/dns2.png) #### 3、使github pages与域名关联 diff --git a/deploy.sh b/deploy.sh index 9423efd..d5bd1fe 100644 --- a/deploy.sh +++ b/deploy.sh @@ -9,35 +9,32 @@ npm run build # 进入生成的文件夹 cd docs/.vuepress/dist -# github -echo 'b.evanblogweb.com' > CNAME # 自定义域名 -if [ -z "$GITHUB_TOKEN" ]; then # -z 字符串 长度为0则为true - echo "没有token" - msg='' - githubUrl=git@github.com:xugaoyi/evanblog.git +# deploy to coding +echo 'www.evanblogweb.com\nevanblogweb.com' > CNAME # 自定义域名 +if [ -z "$CODING_TOKEN" ]; then # -z 字符串 长度为0则为true;$CODING_TOKEN来自于github仓库`Settings/Secrets`设置的私密环境变量 + msg='deploy' + codingUrl=git@git.dev.tencent.com:xugaoyi/xugaoyi.git else - echo "有token" - msg='来自github action的自动' - githubUrl=https://xugaoyi:${GITHUB_TOKEN}@github.com/xugaoyi/evanblog.git - echo $githubUrl + msg='来自github action的自动部署' + codingUrl=https://xugaoyi:${CODING_TOKEN}@git.dev.tencent.com/xugaoyi/xugaoyi.git git config --global user.name "xugaoyi" git config --global user.email "894072666@qq.com" fi git init git add -A -git commit -m "${msg}deploy" -git push -f $githubUrl master:gh-pages # 发布到github +git commit -m ${msg} +git push -f $codingUrl master # 推送到coding -# coding -echo 'evanblogweb.com\nwww.evanblogweb.com' > CNAME -if [ -z "$CODING_TOKEN" ]; then - codingUrl=git@git.dev.tencent.com:xugaoyi/xugaoyi.git +# deploy to github +echo 'b.evanblogweb.com' > CNAME +if [ -z "$GITHUB_TOKEN" ]; then + githubUrl=git@github.com:xugaoyi/evanblog.git else - codingUrl=https://xugaoyi:${CODING_TOKEN}@git.dev.tencent.com/xugaoyi/xugaoyi.git + githubUrl=https://xugaoyi:${GITHUB_TOKEN}@github.com/xugaoyi/evanblog.git fi git add -A -git commit -m "${msg}deploy" -git push -f $codingUrl master # 发布到coding +git commit -m ${msg} +git push -f $githubUrl master:gh-pages # 推送到github cd - # 退回开始所在目录 diff --git a/deployToCoding.sh b/deployToCoding.sh deleted file mode 100644 index 99d7a49..0000000 --- a/deployToCoding.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env sh -set -e - -cd docs/.vuepress/dist - -echo 'evanblogweb.com\nwww.evanblogweb.com' > CNAME -git init -git add -A -git commit -m '来着GitHub Action的部署deploy' -#git push -f git@git.dev.tencent.com:xugaoyi/xugaoyi.git master -git push -f https://xugaoyi:${CODING_TOKEN}@git.dev.tencent.com/xugaoyi/xugaoyi.git master -cd - \ No newline at end of file diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index ca2e58c..b6af4a2 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -15,15 +15,14 @@ module.exports = { lineNumbers: true // 代码行号 }, themeConfig: { // 主题配置 - logo: '/img/logo2.png', // 导航栏logo nav, + sidebar, // 侧边栏 'auto' | 自定义 + logo: '/img/logo2.png', // 导航栏logo repo: 'xugaoyi/evanblog', // 导航栏右侧生成Github链接 + lastUpdated: '更新于', // 更新的时间,及前缀文字 string | boolean // editLinks: true, // 编辑链接 // editLinkText: '在 Github 上编辑此页', - lastUpdated: '更新于', // 更新的时间,及前缀文字 string | boolean - // displayAllHeaders: true // 默认值:false - //sidebar: 'auto', //自动侧边栏 - sidebar + // displayAllHeaders: true, // 默认值:false }, // locales: { // // 键名是该语言所属的子路径 diff --git a/docs/about/readme.md b/docs/about/readme.md index ed1fffb..ce72e14 100644 --- a/docs/about/readme.md +++ b/docs/about/readme.md @@ -2,7 +2,7 @@ web前端工程师,喜欢唱、跳、rap、篮球,写程序。 本人↓↓↓ -本人照片 +本人照片 ## :email: 联系 diff --git a/docs/other/LearningAndMemory.md b/docs/other/LearningAndMemory.md index 9728b3f..93da8ba 100644 --- a/docs/other/LearningAndMemory.md +++ b/docs/other/LearningAndMemory.md @@ -61,7 +61,7 @@ ——以上内容摘自《认知天性》,结合本人的个人理解,更多内容请查看该书籍。 -![认知天性](https://raw.githubusercontent.com/xugaoyi/image_store/master/blogrztx.png) +![认知天性](https://raw.githubusercontent.com/xugaoyi/image_store/master/blog/rztx.png) diff --git a/package.json b/package.json index 23e1741..c629a8f 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,7 @@ "dev": "vuepress dev docs", "list": "node utils/getFilenames.js", "build": "vuepress build docs", - "deploy": "bash deploy.sh", - "deployToCoding": "bash deployToCoding.sh" + "deploy": "bash deploy.sh" }, "license": "MIT", "devDependencies": {