原文发表于个人博客, 特此作版权声明
CSDN: 优雅的将hexo到github和coding
Noosphere.site: 优雅的将hexo到github和coding
上次写了篇文章 使用github action同时部署hexo到github和coding最优雅的方式,从实现原理的角度作了介绍,因为实现的目标比较多,因此看起来比较复杂,此次咱们不讲原理,仅仅按实现目标来介绍如何配置。node
先说咱们要实现的目标,而后再按目标来介绍方法git
hexo d -g
一个命令一次性部署到github和codinggit push
推送到github的surce仓库后,由action触发部署到github和coding的静态仓库_config.yml
。而不须要在action里面写死目标静态仓库的地址,方便维护说明:github
git push
触发,好比 github 的 action 可能某些缘由失败了,暂时又没时间去维护,那么我能够直接在本地hexo d -g
部署就行为了达到上面这些目标,我找了一轮市面上各类各样的解决方案,没看到彻底符合要求的。主要问题包括npm
就这样,观摩了一轮,我决定fork一个github mark上的hexo action出来,按需求本身弄一个action,通过考察,[sma11black/hexo-action](https://github.com/sma11black/hexo-action)
这个action比较接近需求,只须要简单改造就能够使用,怎么改造这里就不说了,{% post_link hexo-action-deploy-to-coding-and-multi-account 见上一篇文章%}ubuntu
通过简单改造的action的仓库是 [noosphere-coder/hexo-action@master](https://github.com/noosphere-coder/hexo-action)
,下面咱们直接使用就好安全
排除掉目标6,只须要是实现上面说的1-5的目标,也便是咱们能够使用咱们平时已经在github和coding里面使用的ssh key就好。那么配置很简单hexo
找到hexo根目录的_config.yml,而后配置deploy字段的内容以下ssh
deploy: type: 'git' repo: github: 'git@noosphere-coder.github.com:noosphere-coder/noosphere-coder.github.io.git' coding: 'git@e.coding.net:noosphere/noosphere.git' branch: 'master'
name: CI on: push: branches: [ master ] pull_request: branches: [ master ] jobs: build-and-deploy: runs-on: ubuntu-latest container: image: node:13-alpine steps: - uses: actions/checkout@v1 with: submodules: true - name: Install Dependencies run: | npm install - name: Deploy id: deploy uses: noosphere-coder/hexo-action@master with: deploy_key: ${{ secrets.DEPLOY_KEY }} # user_name: your github username # (or delete this input setting to use bot account) # user_email: your github useremail # (or delete this input setting to use bot account) commit_msg: ${{ github.event.head_commit.message }} - name: Get the output run: | echo "${{ steps.deploy.outputs.notify }}"
ssh key 配置
3.1 私钥配置: 把/home/$USER/ssh/id_rsa
的内容复制出来,在入口: {私有库}->settings->Secrets->New secret,新建名为DEPLOY_KEY
的key,加入id_rsa的内容
3.2 公钥配置: 把/home/$USER/ssh/id_rsa.pub
分别配置在github和coding的目标仓库post
至此,实现1-5目标的配置已经完成,也就是,咱们能够分别用下面这两种方式均可以同时部署到github和codingui
hexo g -d # 或者 hexo d -g
和
git push origin master
目标6是采用另外的ssh key,而不是直接使用/home/$USER/ssh/id_rsa
,通常来讲,这样做无非是这几种目的
为了达到这个目的,咱们须要告诉ssh,在碰到这个hexo的仓库的时候,请使用独立的 key。下面咱们来实现这个目标
ssh-keygen noosphere-coder
/home/$USER/.ssh
目录cat << EOF > /home/$USER/.ssh/config Host github.com HostName github.com PreferredAuthentications publickey IdentityFile /home/$USER/.ssh/id_rsa Host noosphere-coder.github.com HostName github.com PreferredAuthentications publickey IdentityFile /home/$USER/.ssh/noosphere-coder Host e.coding.net HostName e.coding.net PreferredAuthentications publickey IdentityFile /home/$USER/.ssh/id_rsa Host noosphere-coder.coding.net HostName e.coding.net PreferredAuthentications publickey IdentityFile /home/$USER/.ssh/noosphere-coder EOF
ssh key 配置
配置步骤同样,只须要把id_rsa改为noosphere-coder的内容就好了。git remote set-url origin git@noosphere-coder.github.com:noosphere-coder/hexo-action.git
以上 noosphere-coder请替换成你本身的仓库名称
至此,目标6已经完成,这个时候,你再去执行git push
的时候,ssh会自动使用独立的key而不会使用默认的id_rsa.
同时部署到github和coding主要是为了国内访问和国外访问流量区分,一个为了速度,两者为了搜索引擎收录(github封了百度的爬虫)
这个配置,实在没什么好讲的,直接上图吧
原文发布于:
CSDN: 优雅的将hexo到github和coding
个人博客 优雅的将hexo到github和coding - Noosphere
公众号 优雅的将hexo到github和coding
关注公众号和我互动