1 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: CI
on: push: branches: - master
env: GIT_USER: fangqk1991 GIT_EMAIL: me@fangqk.com THEME_REPO: fangqk1991/maupassant-hexo THEME_BRANCH: master DEPLOY_REPO: fangqk1991/fangqk1991.github.io DEPLOY_BRANCH: master # Using for "Deploy to a server" SERVER_USER: some_user SERVER_HOST: example.com SERVER_PATH: /some/path
jobs: build: name: Build on node ${{ matrix.node_version }} and ${{ matrix.os }} runs-on: ubuntu-latest strategy: matrix: os: [ubuntu-latest] node_version: [12.x]
steps: - name: Checkout uses: actions/checkout@v3
# Download Hexo theme - name: Checkout theme repo uses: actions/checkout@v3 with: repository: ${{ env.THEME_REPO }} ref: ${{ env.THEME_BRANCH }} path: themes/maupassant-hexo
- name: Checkout deploy repo uses: actions/checkout@v3 with: repository: ${{ env.DEPLOY_REPO }} ref: ${{ env.DEPLOY_BRANCH }} path: .deploy_git ssh-key: ${{secrets.HEXO_DEPLOY_PRI}}
- name: Use Node.js ${{ matrix.node_version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node_version }}
# Prepare SSH Key and target hosts - name: Configuration environment env: HEXO_DEPLOY_PRI: ${{secrets.HEXO_DEPLOY_PRI}} run: | sudo timedatectl set-timezone "Asia/Shanghai" mkdir -p ~/.ssh/ echo "$HEXO_DEPLOY_PRI" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa ssh-keyscan github.com >> ~/.ssh/known_hosts git config --global user.name $GIT_USER git config --global user.email $GIT_EMAIL
- name: Build Hexo run: | yarn install npx hexo generate echo fangqk.com > build/CNAME
- name: Deploy to GitHub run: | npx hexo deploy
- name: Deploy to a server run: | ssh-keyscan ${SERVER_HOST} >> ~/.ssh/known_hosts rsync -avz --delete --progress ./build/ ${SERVER_USER}@${SERVER_HOST}:${SERVER_PATH}
|