From f2f9e433b5b068f12abb0ba14083e6a09b705dc4 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sun, 19 Mar 2023 22:11:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/electron-generic.yml | 85 --------------------- .github/workflows/electron-github.yml | 97 ------------------------ .github/workflows/publish-desktop.yml | 31 ++++++++ README_PUBLISH.md | 19 ++--- app/Http/Controllers/IndexController.php | 22 +++--- electron/build.js | 97 +++++++++--------------- package.json | 20 +---- 7 files changed, 90 insertions(+), 281 deletions(-) delete mode 100644 .github/workflows/electron-generic.yml delete mode 100644 .github/workflows/electron-github.yml create mode 100644 .github/workflows/publish-desktop.yml diff --git a/.github/workflows/electron-generic.yml b/.github/workflows/electron-generic.yml deleted file mode 100644 index 9595018e7..000000000 --- a/.github/workflows/electron-generic.yml +++ /dev/null @@ -1,85 +0,0 @@ -name: Build Generic - -on: - push: - tags: - - 'v*' - -jobs: - build-mac: - strategy: - fail-fast: false - matrix: - id: [ "com.dootask.task", "com.hitosea.task" ] - runs-on: macos-latest - environment: build - - if: startsWith(github.event.ref, 'refs/tags/v') - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Create changelog text - id: changelog - uses: loopwerk/tag-changelog@v1 - with: - token: ${{ secrets.GH_PAT }} - exclude_types: other,chore,build - - - name: Use Node.js 16.x - uses: actions/setup-node@v1 - with: - node-version: 16.x - - - name: Build for MacOS - env: - APPID: ${{ matrix.id }} - PROVIDER: "generic" - APPLEID: ${{ secrets.APPLEID }} - APPLEIDPASS: ${{ secrets.APPLEIDPASS }} - CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} - CSC_LINK: ${{ secrets.CSC_LINK }} - RELEASE_BODY: ${{ steps.changelog.outputs.changes }} - run: ./cmd electron build-mac - - build-win: - strategy: - fail-fast: false - matrix: - id: [ "com.dootask.task", "com.hitosea.task" ] - runs-on: windows-latest - environment: build - - if: startsWith(github.event.ref, 'refs/tags/v') - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Create changelog text - id: changelog - uses: loopwerk/tag-changelog@v1 - with: - token: ${{ secrets.GH_PAT }} - exclude_types: other,chore,build - - - name: Use Node.js 16.x - uses: actions/setup-node@v1 - with: - node-version: 16.x - - - name: Build for Windows - shell: powershell - env: - APPID: ${{ matrix.id }} - PROVIDER: "generic" - RELEASE_BODY: ${{ steps.changelog.outputs.changes }} - run: | - npm install - cd electron - npm install - cd ../ - mkdir -p ./electron/public - cp ./electron/index.html ./electron/public/index.html - npx mix --production -- --env --electron - node ./electron/build.js build-win - diff --git a/.github/workflows/electron-github.yml b/.github/workflows/electron-github.yml deleted file mode 100644 index f4fb53b13..000000000 --- a/.github/workflows/electron-github.yml +++ /dev/null @@ -1,97 +0,0 @@ -name: Build Github - -on: - push: - tags: - - 'v*' - -jobs: - release: - runs-on: ubuntu-latest - - if: ${{ (startsWith(github.event.ref, 'refs/tags/v')) && (github.repository == 'kuaifan/dootask') }} - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Create changelog text - id: changelog - uses: loopwerk/tag-changelog@v1 - with: - token: ${{ secrets.GH_PAT }} - exclude_types: other,chore,build - - - name: Create release - uses: actions/create-release@latest - env: - GITHUB_TOKEN: ${{ secrets.GH_PAT }} - with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} - body: ${{ steps.changelog.outputs.changes }} - - build-mac: - strategy: - fail-fast: false - matrix: - id: [ "com.dootask.task", "com.hitosea.task" ] - runs-on: macos-latest - environment: build - - if: ${{ (startsWith(github.event.ref, 'refs/tags/v')) && (github.repository == 'kuaifan/dootask') }} - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Use Node.js 16.x - uses: actions/setup-node@v1 - with: - node-version: 16.x - - - name: Build for MacOS - env: - APPID: ${{ matrix.id }} - PROVIDER: "github" - APPLEID: ${{ secrets.APPLEID }} - APPLEIDPASS: ${{ secrets.APPLEIDPASS }} - CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} - CSC_LINK: ${{ secrets.CSC_LINK }} - GH_TOKEN: ${{ secrets.GH_PAT }} - EP_PRE_RELEASE: true - run: ./cmd electron build-mac - - build-win: - strategy: - fail-fast: false - matrix: - id: [ "com.dootask.task", "com.hitosea.task" ] - runs-on: windows-latest - environment: build - - if: ${{ (startsWith(github.event.ref, 'refs/tags/v')) && (github.repository == 'kuaifan/dootask') }} - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Use Node.js 16.x - uses: actions/setup-node@v1 - with: - node-version: 16.x - - - name: Build for Windows - shell: powershell - env: - APPID: ${{ matrix.id }} - PROVIDER: "github" - GH_TOKEN: ${{ secrets.GH_PAT }} - EP_PRE_RELEASE: true - run: | - npm install - cd electron - npm install - cd ../ - mkdir -p ./electron/public - cp ./electron/index.html ./electron/public/index.html - npx mix --production -- --env --electron - node ./electron/build.js build-win - diff --git a/.github/workflows/publish-desktop.yml b/.github/workflows/publish-desktop.yml new file mode 100644 index 000000000..2bb4fb8e5 --- /dev/null +++ b/.github/workflows/publish-desktop.yml @@ -0,0 +1,31 @@ +name: Publish Desktop + +on: + push: + tags: + - 'v*' + +jobs: + build-mac: + runs-on: macos-latest + environment: build + + if: startsWith(github.event.ref, 'refs/tags/v') + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Use Node.js 16.x + uses: actions/setup-node@v1 + with: + node-version: 16.x + + - name: Build for MacOS + env: + APPLEID: ${{ secrets.APPLEID }} + APPLEIDPASS: ${{ secrets.APPLEIDPASS }} + CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} + CSC_LINK: ${{ secrets.CSC_LINK }} + DP_KEY: ${{ secrets.DP_KEY }} + run: ./cmd electron workflows + diff --git a/README_PUBLISH.md b/README_PUBLISH.md index bd3616c7e..78cb7e793 100644 --- a/README_PUBLISH.md +++ b/README_PUBLISH.md @@ -4,23 +4,20 @@ 1. 添加环境变量 `APPLEID`、`APPLEIDPASS`、`CSC_LINK` 2. 发布GitHub还需要添加 `GH_PAT` +3. 发布私有服务器还需要添加 `DP_KEY` ## 通过 GitHub Actions 发布 -1. 执行 `./cmd prod` 编译 -2. 执行 `node ./version.js` 制作版本 -3. 执行 `git commit` 相关操作 -4. 制作标签 -5. 推送标签 +1. 执行 `npm run version` 生成版本 +2. 执行 `npm run build` 编译前端 +3. 执行 `git commit` 提交并推送 +4. 添加并推送标签 ## 本地发布 -1. 执行 `./cmd prod` 编译 -2. 执行 `node ./version.js` 制作版本 -3. 执行 `git commit` 相关操作 -4. 制作标签 -5. 执行 `./cmd electron` 相关操作 - +1. 执行 `npm run version` 生成版本 +2. 执行 `npm run build` 编译前端 +3. 执行 `./cmd electron` 相关操作 ## 编译App diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index 9800ac620..6fbf0d23e 100755 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -211,24 +211,28 @@ class IndexController extends InvokeController */ public function desktop__publish($name = '') { - $genericVersion = Request::header('generic-version'); + $publishVersion = Request::header('publish-version'); $latestFile = public_path("uploads/desktop/latest"); $latestVersion = file_exists($latestFile) ? trim(file_get_contents($latestFile)) : "0.0.1"; if (strtolower($name) === 'latest') { $name = $latestVersion; } // 上传 - if (preg_match("/^\d+\.\d+\.\d+$/", $genericVersion)) { - if (version_compare($genericVersion, $latestVersion) > -1) { // 限制上传版本必须 ≥ 当前版本 - $genericPath = "uploads/desktop/{$genericVersion}/"; + if (preg_match("/^\d+\.\d+\.\d+$/", $publishVersion)) { + $publishKey = Request::header('publish-key'); + if ($publishKey !== env('APP_KEY')) { + return Base::retError("key error"); + } + if (version_compare($publishVersion, $latestVersion) > -1) { // 限制上传版本必须 ≥ 当前版本 + $publishPath = "uploads/desktop/{$publishVersion}/"; $res = Base::upload([ "file" => Request::file('file'), "type" => 'desktop', - "path" => $genericPath, + "path" => $publishPath, "fileName" => true ]); if (Base::isSuccess($res)) { - file_put_contents($latestFile, $genericVersion); + file_put_contents($latestFile, $publishVersion); } return $res; } @@ -278,9 +282,9 @@ class IndexController extends InvokeController } // 下载 if ($name && file_exists($latestFile)) { - $genericVersion = file_get_contents($latestFile); - if (preg_match("/^\d+\.\d+\.\d+$/", $genericVersion)) { - $filePath = public_path("uploads/desktop/{$genericVersion}/{$name}"); + $publishVersion = file_get_contents($latestFile); + if (preg_match("/^\d+\.\d+\.\d+$/", $publishVersion)) { + $filePath = public_path("uploads/desktop/{$publishVersion}/{$name}"); if (file_exists($filePath)) { return Response::download($filePath); } diff --git a/electron/build.js b/electron/build.js index 07b3cbbfa..9d7b67f3b 100644 --- a/electron/build.js +++ b/electron/build.js @@ -17,7 +17,7 @@ const nativeCachePath = path.resolve(__dirname, ".native"); const devloadCachePath = path.resolve(__dirname, ".devload"); const packageFile = path.resolve(__dirname, "package.json"); const packageBakFile = path.resolve(__dirname, "package-bak.json"); -const platform = ["build-mac", "build-win"]; +const platforms = ["build-mac", "build-win"]; const comSuffix = os.type() == 'Windows_NT' ? '.cmd' : ''; // 克隆 Drawio @@ -60,7 +60,11 @@ function changeLog() { } // 通用发布 -function genericPublish({url, version, output}) { +function genericPublish({url, key, version, output}) { + if (!/https*:\/\//i.test(url)) { + console.warn("publish url error: " + url) + return + } const filePath = path.resolve(__dirname, output) fs.readdir(filePath, async (err, files) => { if (err) { @@ -81,7 +85,8 @@ function genericPublish({url, version, output}) { maxContentLength: Infinity, maxBodyLength: Infinity, headers: { - 'Generic-Version': version, + 'Publish-Version': version, + 'Publish-Key': key, 'Content-Type': 'multipart/form-data;boundary=' + formData.getBoundary(), } }).then(_ => { @@ -116,6 +121,7 @@ function startBuild(data, publish, release) { console.log("Version: " + config.version); console.log("Platform: " + data.platform); console.log("Publish: " + (publish ? 'Yes' : 'No')); + console.log("Release: " + (release ? 'Yes' : 'No')); // drawio cloneDrawio(systemInfo) } @@ -163,32 +169,29 @@ function startBuild(data, publish, release) { econfig.build.directories.output = `dist/${data.id.replace(/\./g, '-')}/${data.platform}`; econfig.build.artifactName = appName + "-v${version}-${os}-${arch}.${ext}"; econfig.build.nsis.artifactName = appName + "-v${version}-${os}-${arch}.${ext}"; - if (!process.env.APPLEID || !process.env.APPLEIDPASS || publish !== true) { - delete econfig.build.afterSign; - } - if (process.env.RELEASE_BODY) { - econfig.build.releaseInfo.releaseNotes = process.env.RELEASE_BODY - } else { - econfig.build.releaseInfo.releaseNotes = changeLog() - } + econfig.build.releaseInfo.releaseNotes = changeLog() if (release) { econfig.build.releaseInfo.releaseNotes = econfig.build.releaseInfo.releaseNotes.replace(`## [${config.version}]`, `## [${config.version}-Release]`) } - if (utils.isJson(data.publish)) { - econfig.build.publish = data.publish + if (publish !== true || !process.env.APPLEID || !process.env.APPLEIDPASS) { + delete econfig.build.afterSign; } fs.writeFileSync(packageFile, JSON.stringify(econfig, null, 2), 'utf8'); // build - child_process.spawnSync("npm" + comSuffix, ["run", data.platform + (publish === true ? "-publish" : "")], {stdio: "inherit", cwd: "electron"}); + child_process.spawnSync("npm" + comSuffix, ["run", data.platform], {stdio: "inherit", cwd: "electron"}); // package.json Recovery fse.copySync(packageBakFile, packageFile) - // generic publish - if (publish === true && econfig.build.publish.provider === "generic") { - genericPublish({ - url: econfig.build.publish.url, - version: config.version, - output: econfig.build.directories.output - }) + // publish + if (publish === true) { + // generic + if (process.env.DP_KEY) { + genericPublish({ + url: data.publish, + key: process.env.DP_KEY, + version: config.version, + output: econfig.build.directories.output + }) + } } } @@ -210,50 +213,30 @@ if (["dev"].includes(argv[2])) { platform: '', url: 'http://public/', }, false, false) -} else if (platform.includes(argv[2])) { +} else if (["workflows"].includes(argv[2])) { // 自动编译 - let data = config.app.find(({id, publish}) => id === process.env.APPID && publish.provider === process.env.PROVIDER); - if (data) { - data.platform = argv[2]; - startBuild(data, true, false) - } else { - console.warn("not build appid!"); - } -} else { - // 自定义编译 - let appChoices = []; - config.app.forEach(data => { - appChoices.push({ - name: `${data.name} (${data.publish.provider})`, - value: data + platforms.forEach(platform => { + config.app.forEach(data => { + data.platform = platform + startBuild(data, true, false) }) }) - if (config.app.filter(({publish}) => publish.provider === 'generic').length > 1) { - appChoices.push({ - name: "All generic", - value: 'generic' - }) - } +} else { + // 手动编译(默认) const questions = [ { type: 'list', - name: 'app', - message: "选择编译应用", - choices: appChoices - }, - { - type: 'list', - name: 'platform', + name: 'platforms', message: "选择编译系统", choices: [{ name: "MacOS", - value: [platform[0]] + value: [platforms[0]] }, { name: "Window", - value: [platform[1]] + value: [platforms[1]] }, { name: "All platforms", - value: platform + value: platforms }] }, { @@ -282,14 +265,8 @@ if (["dev"].includes(argv[2])) { } ]; inquirer.prompt(questions).then(answers => { - answers.platform.forEach(platform => { - let array = []; - if (answers.app === 'generic') { - array = config.app.filter(({publish}) => publish.provider === 'generic') - } else { - array.push(answers.app) - } - array.forEach(data => { + answers.platforms.forEach(platform => { + config.app.forEach(data => { data.platform = platform startBuild(data, answers.publish, answers.release) }) diff --git a/package.json b/package.json index 8156b0250..029552c7d 100644 --- a/package.json +++ b/package.json @@ -71,25 +71,7 @@ "id": "com.dootask.task", "name": "DooTask", "url": "http://public/", - "publish": { - "provider": "github", - "owner": "kuaifan", - "repo": "dootask" - } - }, - { - "id": "com.dootask.task", - "name": "DooTask", - "url": "http://public/", - "urls": [ - "https://dootask.com/", - "https://www.dootask.com/", - "https://t.hitosea.com/" - ], - "publish": { - "provider": "generic", - "url": "https://www.dootask.com/desktop/publish" - } + "publish": "https://www.dootask.com/desktop/publish" } ] }