From 9296008ecc2d3d4ed1ad8e01f89fc65d6259d66b Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 14 Nov 2024 18:10:01 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/publish.yml | 59 ++++++++++++++++++++--------------- README_PUBLISH.md | 8 ++--- electron/build.js | 40 ++++++++++++------------ 3 files changed, 58 insertions(+), 49 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f38c7e19e..a57ed43eb 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -125,16 +125,10 @@ jobs: include: - platform: "macos-12" build_type: "mac" - args: "--target aarch64-apple-darwin" - - platform: "macos-12" - build_type: "mac" - args: "--target x86_64-apple-darwin" - platform: "ubuntu-latest" build_type: "android" - args: "" - platform: "windows-latest" build_type: "windows" - args: "" runs-on: ${{ matrix.platform }} environment: build @@ -153,7 +147,7 @@ jobs: uses: nick-fields/retry@v2 with: timeout_minutes: 10 - max_attempts: 5 + max_attempts: 3 command: | git submodule init git submodule update --remote "resources/mobile" @@ -170,8 +164,8 @@ jobs: if: matrix.build_type == 'android' uses: nick-fields/retry@v2 with: - timeout_minutes: 60 - max_attempts: 10 + timeout_minutes: 20 + max_attempts: 5 command: | cd resources/mobile/platforms/android/eeuiApp chmod +x ./gradlew @@ -180,20 +174,35 @@ jobs: - name: (Android) Upload File if: matrix.build_type == 'android' env: - DP_KEY: ${{ secrets.DP_KEY }} + PUBLISH_KEY: ${{ secrets.PUBLISH_KEY }} run: | node ./electron/build.js android-upload - name: (Android) Upload Release if: matrix.build_type == 'android' + uses: actions/github-script@v7 env: - GH_TOKEN: ${{ secrets.GH_TOKEN }} - uses: softprops/action-gh-release@v2 + RELEASE_ID: ${{ needs.create-release.outputs.release_id }} with: - tag_name: v${{ needs.check-version.outputs.version }} - draft: true - files: | - resources/mobile/platforms/android/eeuiApp/app/build/outputs/apk/release/*.apk + script: | + const fs = require('fs'); + const path = require('path'); + const globby = require('globby'); + + // 查找 APK 文件 + const files = await globby('resources/mobile/platforms/android/eeuiApp/app/build/outputs/apk/release/*.apk'); + + for (const file of files) { + const data = await fs.promises.readFile(file); + + await github.rest.repos.uploadReleaseAsset({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: process.env.RELEASE_ID, + name: path.basename(file), + data: data + }); + } # Mac 构建步骤 - name: (Mac) Build Client @@ -203,9 +212,9 @@ jobs: APPLEIDPASS: ${{ secrets.APPLEIDPASS }} CSC_LINK: ${{ secrets.CSC_LINK }} CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} - DP_KEY: ${{ secrets.DP_KEY }} - GH_TOKEN: ${{ secrets.GH_TOKEN }} - GH_REPOSITORY: ${{ github.repository }} + PUBLISH_KEY: ${{ secrets.PUBLISH_KEY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPOSITORY: ${{ github.repository }} run: | ./cmd electron mac @@ -213,15 +222,15 @@ jobs: - name: (Windows) Build Client if: matrix.build_type == 'windows' env: - DP_KEY: ${{ secrets.DP_KEY }} - GH_TOKEN: ${{ secrets.GH_TOKEN }} - GH_REPOSITORY: ${{ github.repository }} + PUBLISH_KEY: ${{ secrets.PUBLISH_KEY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPOSITORY: ${{ github.repository }} shell: bash run: | ./cmd electron win # publish-release: - # needs: [check-version, create-release, builds] + # needs: [check-version, create-release, build-client] # if: needs.check-version.outputs.should_release == 'true' # permissions: # contents: write @@ -232,13 +241,13 @@ jobs: # id: publish-release # uses: actions/github-script@v7 # env: - # release_id: ${{ needs.create-release.outputs.release_id }} + # RELEASE_ID: ${{ needs.create-release.outputs.release_id }} # with: # script: | # github.rest.repos.updateRelease({ # owner: context.repo.owner, # repo: context.repo.repo, - # release_id: process.env.release_id, + # release_id: process.env.RELEASE_ID, # draft: false, # prerelease: false # }) diff --git a/README_PUBLISH.md b/README_PUBLISH.md index b12dedf40..8f34667e9 100644 --- a/README_PUBLISH.md +++ b/README_PUBLISH.md @@ -4,15 +4,15 @@ 1. 添加环境变量 `APPLEID`、`APPLEIDPASS` 用于公证 2. 添加环境变量 `CSC_LINK`、`CSC_KEY_PASSWORD` 用于签名 -3. 添加环境变量 `GH_TOKEN`、`GH_REPOSITORY` 用于发布到GitHub -4. 添加环境变量 `DP_KEY` 用于发布到私有服务器 +3. 添加环境变量 `GITHUB_TOKEN`、`GITHUB_REPOSITORY` 用于发布到GitHub(GitHub Actions 发布不需要) +4. 添加环境变量 `PUBLISH_KEY` 用于发布到私有服务器 ## 通过 GitHub Actions 发布 1. 执行 `npm run version` 生成版本 2. 执行 `npm run build` 编译前端 3. 执行 `git commit` 提交并推送 -4. 添加并推送标签 +4. 等待 GitHub Actions 自动发布 ## 本地发布 @@ -22,5 +22,5 @@ ## 编译App -1. 执行 `./cmd appbuild [setting]` 编译 +1. 执行 `./cmd appbuild publish` 编译 2. 进入 `resources/mobile` eeui框架内打包Android或iOS应用 diff --git a/electron/build.js b/electron/build.js index 31b8502f0..c8f2d92bc 100644 --- a/electron/build.js +++ b/electron/build.js @@ -11,7 +11,7 @@ const utils = require('./utils'); const config = require('../package.json') const env = require('dotenv').config({ path: './.env' }) const argv = process.argv; -const {APPLEID, APPLEIDPASS, GH_TOKEN, GH_REPOSITORY, DP_KEY} = process.env; +const {APPLEID, APPLEIDPASS, GITHUB_TOKEN, GITHUB_REPOSITORY, PUBLISH_KEY} = process.env; const electronDir = path.resolve(__dirname, "public"); const nativeCachePath = path.resolve(__dirname, ".native"); @@ -37,9 +37,9 @@ async function detectAndDownloadUpdater() { // 获取最新release const spinner = ora('检查更新器...').start(); const response = await axios.get('https://api.github.com/repos/kuaifan/dootask-updater/releases/latest', { - headers: GH_TOKEN ? { 'Authorization': `token ${GH_TOKEN}` } : {} + headers: GITHUB_TOKEN ? { 'Authorization': `token ${GITHUB_TOKEN}` } : {} }); - + if (!response.data || !response.data.assets) { spinner.fail('检查更新器失败'); return; @@ -67,7 +67,7 @@ async function detectAndDownloadUpdater() { } // 过滤出binary开头的zip文件 - const assets = response.data.assets.filter(asset => + const assets = response.data.assets.filter(asset => asset.name.startsWith('binary_') && asset.name.endsWith('.zip') ); @@ -81,7 +81,7 @@ async function detectAndDownloadUpdater() { if (!match) continue; let [, platform, arch] = match; - + // 平台名称映射 const platformMap = { 'macos': 'mac', @@ -114,7 +114,7 @@ async function detectAndDownloadUpdater() { url: asset.browser_download_url, method: 'GET', responseType: 'stream', - headers: GH_TOKEN ? { 'Authorization': `token ${GH_TOKEN}` } : {} + headers: GITHUB_TOKEN ? { 'Authorization': `token ${GITHUB_TOKEN}` } : {} }); response.data.pipe(writer); @@ -129,7 +129,7 @@ async function detectAndDownloadUpdater() { await new Promise((resolve, reject) => { yauzl.open(zipPath, { lazyEntries: true }, (err, zipfile) => { if (err) reject(err); - + zipfile.readEntry(); zipfile.on('entry', (entry) => { if (/\/$/.test(entry.fileName)) { @@ -137,7 +137,7 @@ async function detectAndDownloadUpdater() { } else { zipfile.openReadStream(entry, (err, readStream) => { if (err) reject(err); - + const outputPath = path.join(targetDir, path.basename(entry.fileName)); const writer = fs.createWriteStream(outputPath); readStream.pipe(writer); @@ -148,7 +148,7 @@ async function detectAndDownloadUpdater() { }); } }); - + zipfile.on('end', resolve); }); }); @@ -270,8 +270,8 @@ function axiosAutoTry(data) { * @param url */ function androidUpload(url) { - if (!DP_KEY) { - console.error("缺少 Deploy Key, 请检查环境变量!"); + if (!PUBLISH_KEY) { + console.error("缺少 PUBLISH_KEY 环境变量"); process.exit() } const releaseDir = path.resolve(__dirname, "../resources/mobile/platforms/android/eeuiApp/app/build/outputs/apk/release"); @@ -300,7 +300,7 @@ function androidUpload(url) { data: formData, headers: { 'Publish-Version': config.version, - 'Publish-Key': DP_KEY, + 'Publish-Key': PUBLISH_KEY, 'Content-Type': 'multipart/form-data;boundary=' + formData.getBoundary(), }, onUploadProgress: progress => { @@ -556,8 +556,8 @@ async function startBuild(data) { }) } // github (build && publish) - if (publish === true && GH_TOKEN && utils.strExists(GH_REPOSITORY, "/")) { - const repository = GH_REPOSITORY.split("/") + if (publish === true && GITHUB_TOKEN && utils.strExists(GITHUB_REPOSITORY, "/")) { + const repository = GITHUB_REPOSITORY.split("/") econfig.build.publish = { "releaseType": "release", "provider": "github", @@ -573,10 +573,10 @@ async function startBuild(data) { econfig.build.directories.output = `${output}-generic`; fs.writeFileSync(packageFile, JSON.stringify(econfig, null, 4), 'utf8'); child_process.execSync(`npm run ${platform}`, {stdio: "inherit", cwd: "electron"}); - if (publish === true && DP_KEY) { + if (publish === true && PUBLISH_KEY) { genericPublish({ url: econfig.build.publish.url, - key: DP_KEY, + key: PUBLISH_KEY, version: config.version, output: econfig.build.directories.output }) @@ -649,7 +649,7 @@ if (["dev"].includes(argv[2])) { name: "MacOS", value: platforms[0], checked: true - }, + }, { name: "Windows", value: platforms[1] @@ -671,7 +671,7 @@ if (["dev"].includes(argv[2])) { name: "arm64", value: architectures[0], checked: true - }, + }, { name: "x64", value: architectures[1] @@ -734,8 +734,8 @@ if (["dev"].includes(argv[2])) { const publishAnswers = await inquirer.prompt(publishQuestions); Object.assign(answers, publishAnswers); - if (!DP_KEY && (!GH_TOKEN || !utils.strExists(GH_REPOSITORY, "/"))) { - console.error("发布需要 Deploy Key 或 GitHub Token 和 Repository, 请检查环境变量!"); + if (!PUBLISH_KEY && (!GITHUB_TOKEN || !utils.strExists(GITHUB_REPOSITORY, "/"))) { + console.error("发布需要 PUBLISH_KEY 或 GitHub Token 和 Repository, 请检查环境变量!"); process.exit() }