name: Blog CI/CD
on: [push, repository_dispatch]
jobs:
blog-cicd:
name: Hexo blog build & deploy
runs-on: ubuntu-latest
env:
TZ: Asia/Shanghai
steps:
- name: Checkout codes
uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Cache node modules
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
run: |
npm install hexo-cli -g
npm install yuque-hexo -g
npm install
yuque-hexo sync
- name: Generate files
run: hexo generate
- name: Deploy blog
evn:
Github_Pages: github.com/sbwit/sbwit.github.io
Github_Token: ${{ secrets.TOKEN_GITHUBAPI }}
run: |
git clone "https://${Github_Pages}" deploy_git
mv ./deploy_git/.git ./public/
cd ./public
git config user.name "sbwit"
git config user.email "17740857130@qq.com"
git add .
git commit -m "GitHub Actions Auto Builder at $(date +'%Y-%m-%d %H:%M:%S')"
git push --force --quiet "https://${Github_Token}@${Github_Pages}" master:master
# -*- coding: utf8 -*-
import requests
def main_handler(event, context):
r = requests.post("https://api.github.com/repos/sbwit/sbwit.hexo/dispatches",
json = {"event_type": "start"},
headers = {"User-Agent":'curl/7.52.1',
'Content-Type': 'application/json',
'Accept': 'application/vnd.github.everest-preview+json',
'Authorization': 'token GITHUB_TOKEN(自己的)'})
if r.status_code == 204:
return "This's OK!"
else:
return r.status_code
官方的配置
# workflow name
name: CI Hexo
# master branch on push, auto run
on:
push:
branches:
- master
jobs:
Deploy-Pages:
name: Deploy Hexo Public To Pages
runs-on: ubuntu-latest
steps:
# check it to your workflow can access it
# from: https://github.com/actions/checkout
- name: Checkout Repository master branch
uses: actions/checkout@master
# from: https://github.com/actions/setup-node
- name: Setup Node.js 10.x
uses: actions/setup-node@master
with:
node-version: "12.14"
- name: Setup Git Infomation
run: |
git config --global user.name 'sbwit'
git config --global user.email '17740857130@163.com'
- name: Get Latest Commit Message
run: |
git log --pretty=format:"%s from Github Actions at `date +"%Y-%m-%d %H:%M:%S"`" --date=short -n 1 > commit-message.log
- name: Setup Hexo Dependencies
run: |
npm install hexo-cli -g
npm install
- name: Generate public files
run: |
hexo clean hexo generate
- name: Deploy To Github Pages
env:
Github_Pages: github.com/sbwit/sbwit.github.io
Github_Token: ${{ secrets.TOKEN_GITHUBAPI }}
run: |
git clone https://${Github_Pages} .github_pages
cd .github_pages
git checkout master
cd ../
mv .github_pages/.git/ ./public/
cd ./public/
git add .
git commit -F ../commit-message.log
git push --force --quiet "https://${Github_Token}@${Github_Pages}" master:master