name: Build Dev on: push: branches: - dev - master jobs: release: name: Build Website runs-on: windows-latest steps: # 检出 Git 仓库 - name: Check out git repository uses: actions/checkout@v4.1.1 # 安装 Node.js - name: Install Node.js uses: actions/setup-node@v4.0.0 with: node-version: "18.x" # 复制环境变量文件 - name: Copy .env.example run: | if (-not (Test-Path .env)) { Copy-Item .env.example .env } else { Write-Host ".env file already exists. Skipping the copy step." } # 安装项目依赖 - name: Install Dependencies run: npm install # 构建程序 - name: Build Website run: npm run build env: GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} # 上传构建产物 - name: Upload artifacts uses: actions/upload-artifact@v3.1.3 with: name: Home 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