利用 Github Action 自动部署 Hexo
利用 Github Action 自动部署 Hexo。
Secrets
仓库下 Setting -> Secrets -> New repository secret 新建 Secrets
Actions
Hexo 目录下新建 .github\workflows\deploy.yml
deploy.yml1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| name: Hexo Deploy
on: push: branches: - source
env: TZ: Asia/Shanghai GIT_USER: Vitan GIT_EMAIL: vitan.me@gmail.com DEPLOY_REPO: ivitan/ivitan.github.io DEPLOY_BRANCH: master THEME_REPO: ivitan/indigo THEME_BRANCH: master
jobs: build: name: Setup OS runs-on: ubuntu-latest strategy: matrix: os: [ubuntu-latest] node_version: [12.x]
steps: - name: Checkout Repository source branch uses: actions/checkout@v2 with: ref: source
- name: Checkout Deploy Repo uses: actions/checkout@v2 with: repository: ${{ env.DEPLOY_REPO }} ref: ${{ env.DEPLOY_BRANCH }} path: .deploy_git - name: Checkout Theme Repo uses: actions/checkout@v2 with: repository: ${{ env.THEME_REPO }} ref: ${{ env.THEME_BRANCH }} path: themes/indigo
- name: Setup Node.js ${{ matrix.node_version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node_version }} - name: Setup Deploy Private Key env: HEXO_DEPLOY_PRI: ${{secrets.HEXO_DEPLOY_PRI}} run: | mkdir -p ~/.ssh/ echo "$HEXO_DEPLOY_PRI" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Setup Git Infomation run: | git config --global user.name $GIT_USER git config --global user.email $GIT_EMAIL
- name: Setup Hexo Dependencies run: | sudo timedatectl set-timezone $TZ npm install hexo-cli -g npm install wget https://github.com/ivitan/ivitan.github.io/releases/download/Pin/generator.js -O ./node_modules/hexo-generator-index/lib/generator.js
- name: Deploy Hexo blog run: | hexo clean hexo generate hexo deploy
|