GithubAction-Deploy
使用 github action 自动化部署
创建GitHub repository 存放源文件
在repo设置界面里添加Secrets(本地生成一对公私钥ssh-keygen,这里填上私钥,命名为 ACTION_DEPLOY_KEY(可以任意命名,但要和Actions里的设定$对应)
在存放GitHub pages的repo设定Deploy keys为刚生成的公钥
在根目录下创建GitHub Actions workflow文件
name: Build and Update Note.junyangz.com for github pages
on: push
jobs:
build:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- name: Use Node.js 10.x
uses: actions/setup-node@v1
with:
node-version: "10.x"
- name: Setup Hexo env
env:
ACTION_DEPLOY_KEY: ${{ secrets.ACTION_DEPLOY_KEY }}
run: |
# set up private key for deploy
mkdir -p ~/.ssh/
echo "$ACTION_DEPLOY_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
# set git infomation
git config --global user.name 'Junyangz'
git config --global user.email 'junyangz.iie@gmail.com'
# install dependencies
npm i -g hexo-cli
npm i
- name: Deploy
run: |
# generate and depoly
hexo g -d