Some checks failed
Hexo Build and Deploy / Build Hexo and Deploy to GitHub (push) Has been cancelled
62 lines
1.7 KiB
YAML
62 lines
1.7 KiB
YAML
name: Hexo Build and Deploy
|
|
|
|
on: [push]
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
name: Build Hexo and Deploy to GitHub
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout Source Code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '22'
|
|
# cache: 'npm' # 启用npm缓存
|
|
- name: Cache node_modules
|
|
uses: actions/cache@v4
|
|
id: npm-cache
|
|
with:
|
|
path: |
|
|
node_modules
|
|
# ~/.npm
|
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-node-
|
|
|
|
- name: Install Dependencies
|
|
run: |
|
|
# 只有当缓存未命中时才执行完整安装
|
|
if [ ! -d "node_modules" ] || [ ! -f "node_modules/.installed" ]; then
|
|
npm ci
|
|
touch node_modules/.installed
|
|
else
|
|
echo "Using cached dependencies"
|
|
fi
|
|
if ! command -v hexo &> /dev/null; then
|
|
npm install -g hexo-cli
|
|
else
|
|
echo "Hexo CLI is already installed"
|
|
fi
|
|
|
|
- name: Setup SSH Key and Git Config
|
|
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
|
|
git config --global user.name "gitea"
|
|
git config --global user.email "979541498@qq.com"
|
|
|
|
- name: Clean and Generate
|
|
run: |
|
|
hexo clean
|
|
hexo generate
|
|
|
|
- name: Deploy to GitHub
|
|
run: |
|
|
hexo deploy |