Update build.yml

This commit is contained in:
hwxlikemi 2025-01-30 14:00:39 +08:00 committed by GitHub
parent 49c3793f8b
commit 911c7ffcf0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,3 +1,5 @@
# Dev 分支推送部署预览
## 仅部署 Win 端
name: Build Dev name: Build Dev
on: on:
@ -15,13 +17,11 @@ jobs:
# 检出 Git 仓库 # 检出 Git 仓库
- name: Check out git repository - name: Check out git repository
uses: actions/checkout@v4.1.1 uses: actions/checkout@v4.1.1
# 安装 Node.js # 安装 Node.js
- name: Install Node.js - name: Install Node.js
uses: actions/setup-node@v4.0.0 uses: actions/setup-node@v4.0.0
with: with:
node-version: "18.x" node-version: "18.x"
# 复制环境变量文件 # 复制环境变量文件
- name: Copy .env.example - name: Copy .env.example
run: | run: |
@ -30,66 +30,17 @@ jobs:
} else { } else {
Write-Host ".env file already exists. Skipping the copy step." Write-Host ".env file already exists. Skipping the copy step."
} }
# 安装项目依赖 # 安装项目依赖
- name: Install Dependencies - name: Install Dependencies
run: npm install run: npm install
# 构建程序 # 构建程序
- name: Build Website - name: Build Website
run: npm run build run: npm run build
env: env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
# 上传构建产物 # 上传构建产物
- name: Upload artifacts - name: Upload artifacts
uses: actions/upload-artifact@v3.1.3 uses: actions/upload-artifact@v3.1.3
with: with:
name: Home name: Home
path: dist path: dist
deploy:
name: Deploy to gh-pages
runs-on: windows-latest
needs: release # 依赖 release 任务完成
steps:
# 检出 Git 仓库
- name: Check out git repository
uses: actions/checkout@v4.1.1
# 下载构建产物
- name: Download artifacts
uses: actions/download-artifact@v3.0.0
with:
name: Home
path: dist
# 切换到 gh-pages 分支
- name: Checkout gh-pages branch
run: |
git fetch origin gh-pages:gh-pages
git checkout gh-pages
# 删除 gh-pages 分支下的所有文件(除了 .git 目录)
- name: Clean gh-pages branch
run: |
# 删除所有文件和文件夹,除了 .git
Get-ChildItem -Path . -Exclude .git | Remove-Item -Recurse -Force
# 将构建产物复制到 gh-pages 分支
- name: Copy files to gh-pages branch
run: |
Copy-Item -Path dist/* -Destination . -Recurse -Force
# 提交更改
- name: Commit changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Deploy website from dev branch (cleaned branch)"
# 推送到 gh-pages 分支
- name: Push to gh-pages branch
run: |
git push origin gh-pages --force