#155 十二月累积更新 #127
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-app | |
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 | |
# 初始化一些流程需要的环境变量 | |
- 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 | |
# 设置 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 | |
# ======================= 构建 Docker 版本 ======================== | |
build-docker: | |
name: 构建 Docker 版本 | |
runs-on: ubuntu-latest | |
needs: | |
- init | |
- build-root-web | |
steps: | |
# 拉取代码(不需要子模块,只是获取 dockerfile) | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# 下载上一步构建的结果 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ needs.init.outputs.version }}-web | |
# 解压(不输出细节) | |
- name: Unzip | |
run: unzip -q Stapxs.QQ.Lite-${{ needs.init.outputs.version }}-web.zip | |
# 登录到 Docker Hub | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: stapxs | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
# 使用 buildx 构建 amd64 和 arm64 架构的镜像 | |
# 推送到 Docker Hub;不保留历史版本直接推送 latest | |
- name: Build Docker Image | |
run: | | |
docker buildx create --use | |
docker buildx build --platform linux/amd64,linux/arm64 -t stapxs/qq-web:latest --push . | |
# ==================== 构建 Github Pages 版本 ===================== | |
build-pages: | |
name: 构建 Github Pages 版本 | |
runs-on: ubuntu-latest | |
needs: init | |
steps: | |
# 拉取代码 | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
# 设置 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 | |
# 设置 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 }} | |
path: dist_electron | |
# ========================= 发布构建结果 ========================= | |
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 }} |