Ver Fonte

【新增】添加客户端编译和测试的 GitHub Actions 工作流

- 新增编译客户端的 GitHub Actions 工作流文件
- 添加自动配置 Node.js 环境和安装依赖的步骤
- 实现客户端代码的编译和生成安装包
- 新增上传编译产物到 GitHub Actions 艺术品功能
- 添加 fix-cors.js 文件以解决跨域请求问题
PJ568 há 1 ano atrás
pai
commit
bf61596bf8
2 ficheiros alterados com 89 adições e 0 exclusões
  1. 69 0
      .github/workflows/build-app.yaml
  2. 20 0
      assets/fix-cors.js

+ 69 - 0
.github/workflows/build-app.yaml

@@ -0,0 +1,69 @@
+name: 编译客户端
+
+on:
+  workflow_dispatch:
+  push:
+    paths:
+      - '.github/workflows/build-app.yaml'
+      - 'client/**'
+
+concurrency:
+  group: "client"
+  cancel-in-progress: true
+
+permissions:
+  contents: read
+  id-token: write
+
+jobs:
+  build-app:
+    runs-on: ubuntu-latest
+    env:
+      TZ: Asia/Shanghai
+    steps:
+
+    - name: 检出仓库
+      uses: actions/checkout@v4
+
+    - name: 安装依赖
+      run: |
+        sudo apt install -y libdbus-1-dev \
+          libsoup3.0-dev \
+          libjavascriptcoregtk-4.1-dev \
+          libwebkit2gtk-4.1-dev \
+          build-essential \
+          curl \
+          wget \
+          libssl-dev \
+          libgtk-3-dev \
+          libayatana-appindicator3-dev \
+          librsvg2-dev \
+          gnome-video-effects \
+          gnome-video-effects-extra
+
+    - name: 配置 Node.js
+      uses: actions/setup-node@v4
+      with:
+        node-version: '16.x'
+    
+    - name: 安装 Pake
+      run: |
+        npm install -g pake-cli && pake --version
+    
+    - name: 编译客户端
+      run: |
+        YAA_VERSION=$(grep '^version' ./Cargo.toml | awk -F= '{print $2}' | tr -d '" ')
+        mkdir -p target && mkdir -p target/client
+        cd target/client
+        pake ../../client/index.html \
+          -name yaa \
+          --icon ../../assets/yaa_512.png \
+          --installer-language zh-CN \
+          --app-version $YAA_VERSION \
+          --use-local-file
+        cd ../..
+
+    - name: 上传包
+      uses: actions/upload-artifact@v4
+      with:
+        path: 'target/client/*/*.*'

+ 20 - 0
assets/fix-cors.js

@@ -0,0 +1,20 @@
+// 强制所有 fetch 请求添加 CORS 头
+const originalFetch = window.fetch;
+window.fetch = async (url, options) => {
+  if (typeof url === 'string' && url.startsWith('http')) {
+    options = options || {};
+    options.headers = options.headers || {};
+    options.headers['Origin'] = window.location.origin;
+    options.mode = 'cors';
+  }
+  return originalFetch(url, options);
+};
+
+// 强制所有 XHR 请求添加 CORS 头
+const originalOpen = XMLHttpRequest.prototype.open;
+XMLHttpRequest.prototype.open = function (method, url) {
+  originalOpen.apply(this, arguments);
+  if (typeof url === 'string' && url.startsWith('http')) {
+    this.setRequestHeader('Origin', window.location.origin);
+  }
+};