调整 CI #115
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 在主分支上构建 | |
name: build | |
on: | |
push: # push 触发 | |
branches: | |
- next | |
jobs: | |
# ========================= 准备项目 ========================= | |
init: | |
name: 初始化构建 | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.step_init.outputs.VERSION }} | |
steps: | |
# 拉取代码 | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
persist-credentials: false | |
# 初始化一些流程需要的环境变量 | |
- name: Init Env | |
id: step_init | |
run: echo VERSION=$(node -p "require('./package.json').version") >> $GITHUB_OUTPUT | |
# ========================= 构建 Web 版本 ========================= | |
build-root-web: | |
name: 构建 Web 版本(根目录) | |
runs-on: ubuntu-latest | |
needs: init | |
steps: | |
# 拉取代码 | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
persist-credentials: false | |
# 设置 Node.js 版本 | |
- name: Load Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
# 更新依赖 | |
- name: Install | |
run: yarn | |
# 构建 | |
- name: Build | |
run: yarn build | |
# 将 dist 目录压缩为 zip | |
- name: Zip | |
run: zip -r Stapxs.QQ.Lite-${{ needs.init.outputs.version }}-web.zip dist | |
# 上传构建结果 | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ needs.init.outputs.version }}-web | |
path: Stapxs.QQ.Lite-${{ needs.init.outputs.version }}-web.zip | |
# ==================== 构建 Github Pages 版本 ===================== | |
build-pages: | |
name: 构建 Github Pages 版本 | |
runs-on: ubuntu-latest | |
needs: init | |
steps: | |
# 拉取代码 | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
persist-credentials: false | |
# 设置 Node.js 版本 | |
- name: Load Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
# 更新依赖 | |
- name: Install | |
run: yarn | |
# 构建 | |
- name: Build | |
run: yarn build | |
env: | |
BUILD_ENV: github-actions | |
# 部署 Web 版本 | |
- name: Deploy | |
uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
token: ${{ secrets.ACCESS_TOKEN }} | |
branch: gh-pages | |
folder: dist | |
# ========================= 构建 Electron 版本 ========================= | |
build-electron: | |
name: 构建 Electron 版本 | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [windows-2019, ubuntu-latest] | |
outputs: | |
version: ${{ needs.init.outputs.version }} | |
needs: init | |
steps: | |
# 拉取代码 | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
persist-credentials: false | |
# 设置 Node.js 版本 | |
- name: Load Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
# 更新依赖 | |
- name: Install | |
run: yarn | |
# 构建 electron 版本(Windows) | |
- name: Build Electron (Windows) | |
if: matrix.os == 'windows-2019' | |
run: yarn build:win | |
env: | |
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
# 构建 electron 版本(Linux) | |
- name: Build Electron (Linux) | |
if: matrix.os == 'ubuntu-latest' | |
run: yarn build:linux | |
env: | |
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
# 上传构建结果 | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ needs.init.outputs.version }}-${{ matrix.os }} | |
# Stapxs QQ Lite 开头的文件和 stapxs-qq-lite 开头的文件;不用管后缀 | |
path: | | |
Stapxs.QQ.Lite* | |
stapxs-qq-lite* | |
# ========================= 发布构建结果 ========================= | |
release: | |
name: 发布构建结果 | |
runs-on: ubuntu-latest | |
needs: | |
- build-root-web | |
- build-electron | |
steps: | |
# 下载构建结果 | |
- name: Download Artifacts | |
id: download-artifact | |
uses: actions/download-artifact@v4 | |
with: | |
path: ${{ needs.build-electron.outputs.version }} | |
pattern: ${{ needs.build-electron.outputs.version }}-* | |
merge-multiple: true | |
- name: Artifacts List | |
run: ls -R | |
# 发布构建结果 | |
- name: Publish Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: ./${{ needs.build-electron.outputs.version }}/* | |
tag_name: v${{ needs.build-electron.outputs.version }} | |
body: | | |
# Release 自动构建 | |
`这是一个自动构建版本,由 GitHub Actions 自动构建并发布。` | |
## 更新内容 | |
${{ github.event.head_commit.message }} | |
## 自动构建信息 | |
- 构建时间:${{ github.event.head_commit.timestamp }} | |
- 构建提交:${{ github.event.head_commit.id }} | |
- 构建分支:${{ github.event.head_commit.tree_id }} | |
draft: false | |
prerelease: false | |
token: ${{ secrets.ACCESS_TOKEN }} |