原文發表於個人博客, 特此作版權聲明
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
關注公衆號和我互動