Update main.yml
This commit is contained in:
102
.github/workflows/main.yml
vendored
102
.github/workflows/main.yml
vendored
@@ -4,77 +4,63 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
TZ: Asia/Shanghai
|
||||
|
||||
jobs:
|
||||
# Job 1: 检查代码并缓存依赖
|
||||
check_and_cache:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# 检查分支
|
||||
- name: 检查分支
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
ref: master
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: 检查分支
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
ref: master
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# 缓存 npm 包
|
||||
- name: 缓存项目 npm 包
|
||||
id: cache-node-modules
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: node_modules
|
||||
key: ${{ runner.os }}-nodeModules-${{ hashFiles('package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-nodeModules-
|
||||
- name: 缓存项目 npm 包
|
||||
id: cache-node-modules
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: node_modules
|
||||
key: ${{ runner.os }}-nodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-nodeModules-
|
||||
|
||||
# Job 2: 安装依赖和清理构建
|
||||
install_and_clean:
|
||||
runs-on: ubuntu-latest
|
||||
needs: check_and_cache
|
||||
steps:
|
||||
# 安装 Node 及 Hexo
|
||||
- name: 安装 Node 和 Hexo
|
||||
run: |
|
||||
echo "安装 Node.js 版本 22.x"
|
||||
cd ..
|
||||
npm install hexo-cli --global
|
||||
npm install || echo "依赖安装失败"
|
||||
- name: 安装 Node
|
||||
uses: actions/setup-node@v5
|
||||
with:
|
||||
node-version: "22.x"
|
||||
|
||||
# 清理文件树
|
||||
- name: 清理文件树
|
||||
run: |
|
||||
npm run clean
|
||||
- name: 安装 Hexo
|
||||
run: |
|
||||
npm install hexo-cli --global
|
||||
|
||||
# Job 3: 生成静态文件
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
needs: install_and_clean
|
||||
steps:
|
||||
# 生成静态文件并压缩
|
||||
- name: 生成静态文件并压缩
|
||||
run: |
|
||||
npm run build
|
||||
- name: 安装依赖
|
||||
if: steps.cache-node-modules.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
npm install
|
||||
|
||||
# Job 4: 部署到 GitHub Pages
|
||||
deploy_to_github:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
steps:
|
||||
- name: 部署静态文件到 GitHub Pages
|
||||
run: |
|
||||
echo "开始部署到 GitHub page"
|
||||
cd ./public
|
||||
git init
|
||||
git config user.name "${{ github.actor }}"
|
||||
git config user.email "${{ github.actor }}@users.noreply.github.com"
|
||||
git add .
|
||||
git commit -m "${{ github.event.head_commit.message }} · [${{ github.sha }}] · $(date +"%Y-%m-%d %H:%M:%S")"
|
||||
# 将静态文件推送到指定的 Pages 仓库和 gh-pages 分支
|
||||
git push --force --quiet "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/bishshi/pages.git" master
|
||||
- name: 清理文件树
|
||||
run: |
|
||||
npm run clean
|
||||
|
||||
- name: 生成静态文件并压缩
|
||||
run: |
|
||||
npm run build
|
||||
|
||||
- name: 部署
|
||||
run: |
|
||||
cd ./public
|
||||
git init
|
||||
git config user.name "${{ github.actor }}"
|
||||
git config user.email "${{ github.actor }}@users.noreply.github.com"
|
||||
git add .
|
||||
git commit -m "${{ github.event.head_commit.message }}··[$(date +"%Z %Y-%m-%d %A %H:%M:%S")]"
|
||||
git push --force --quiet "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/bishshi/pages.git" master:master
|
||||
|
||||
Reference in New Issue
Block a user