From d4cc561d9033b6f16af7bcc1cce0fb0c2ff80565 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Tue, 21 Dec 2021 23:47:08 +0800 Subject: [PATCH] add workflows --- .github/workflows/electron.yml | 60 +++++++++++++++++++ cmd | 20 +++---- electron/build.js | 104 ++++++++++++++++++++------------- electron/package.json | 33 +++++++++-- package.json | 26 ++++++++- version.js | 6 ++ 6 files changed, 190 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/electron.yml diff --git a/.github/workflows/electron.yml b/.github/workflows/electron.yml new file mode 100644 index 00000000..8d1649ff --- /dev/null +++ b/.github/workflows/electron.yml @@ -0,0 +1,60 @@ +name: Build + +on: + push: + tags: + - 'v*' + +jobs: + release: + runs-on: ubuntu-latest + + if: startsWith(github.event.ref, 'refs/tags/v') + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Build Changelog + id: github_release + uses: mikepenz/release-changelog-builder-action@v1 + env: + GITHUB_TOKEN: ${{ secrets.GH_PAT }} + + - name: Create Release + uses: actions/create-release@v1 + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + body: ${{steps.github_release.outputs.changelog}} + env: + GITHUB_TOKEN: ${{ secrets.GH_PAT }} + + build: + runs-on: ${{ matrix.os }} + environment: build + + strategy: + matrix: + os: [macos-11] + platform: [ + build-mac, + build-mac-arm, + build-win + ] + + if: startsWith(github.event.ref, 'refs/tags/v') + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Use Node.js 14.x + uses: actions/setup-node@v1 + with: + node-version: 14.x + + - name: Build + env: + GH_TOKEN: ${{ secrets.GH_PAT }} + EP_PRE_RELEASE: true + run: ./cmd electron ${{ matrix.platform }} + diff --git a/cmd b/cmd index 25de4eb2..d34516cb 100755 --- a/cmd +++ b/cmd @@ -87,7 +87,7 @@ run_compile() { } run_electron() { - local type=$1 + local argv=$@ check_node if [ ! -d "./electron/node_modules" ]; then pushd electron @@ -97,11 +97,7 @@ run_electron() { if [ -d "./electron/dist" ]; then rm -rf "./electron/dist" fi - if [ "$type" = "prod" ]; then - node ./electron/build.js --build - else - node ./electron/build.js - fi + node ./electron/build.js $argv } run_exec() { @@ -200,8 +196,10 @@ env_init() { #################################################################################### #################################################################################### -check_docker -env_init +if [[ "$1" != "electron" ]]; then + check_docker + env_init +fi if [ $# -gt 0 ]; then if [[ "$1" == "init" ]] || [[ "$1" == "install" ]]; then @@ -260,11 +258,7 @@ if [ $# -gt 0 ]; then run_compile prod elif [[ "$1" == "electron" ]]; then shift 1 - if [[ "$@" == "dev" ]]; then - run_electron dev - else - run_electron prod - fi + run_electron $@ elif [[ "$1" == "doc" ]]; then shift 1 run_exec php "php app/Http/Controllers/Api/apidoc.php" diff --git a/electron/build.js b/electron/build.js index 34fcf2e6..b23a3ef7 100644 --- a/electron/build.js +++ b/electron/build.js @@ -1,5 +1,4 @@ const fs = require('fs'); -const fse = require('fs-extra') const path = require('path') const inquirer = require('inquirer'); const child_process = require('child_process'); @@ -103,19 +102,57 @@ function rightExists(string, find) { const electronDir = path.resolve(__dirname, "public"); const nativeCachePath = path.resolve(__dirname, ".native"); const devloadCachePath = path.resolve(__dirname, ".devload"); +const platform = ["build-mac", "build-mac-arm", "build-win"]; -if (argv[2] === "--build") { +// 编译网站 +function step1() { if (fs.existsSync(electronDir)) { deleteFile(electronDir); } fs.mkdirSync(electronDir); copyFile(path.resolve(__dirname, "index.html"), electronDir + "/index.html") + // + child_process.spawnSync("mix", ["--production", "--", "--env", "--electron"], {stdio: "inherit"}); +} - const platform = ["build-mac-intel", "build-mac-m1", "build-win"]; +// 生成配置、编译应用 +function step2(data, publish) { + let systemInfo = `window.systemInformation = { + version: "${config.version}", + origin: "./", + apiUrl: "${formatUrl(data.url)}api/" +}`; + fs.writeFileSync(electronDir + "/config.js", systemInfo, 'utf8'); + fs.writeFileSync(nativeCachePath, formatUrl(data.url)); + fs.writeFileSync(devloadCachePath, "", 'utf8'); + // + let packageFile = path.resolve(__dirname, "package.json"); + let packageString = fs.readFileSync(packageFile, 'utf8'); + packageString = packageString.replace(/"name":\s*"(.*?)"/, `"name": "${data.name}"`); + packageString = packageString.replace(/"appId":\s*"(.*?)"/, `"appId": "${data.id}"`); + packageString = packageString.replace(/"version":\s*"(.*?)"/, `"version": "${config.version}"`); + packageString = packageString.replace(/"artifactName":\s*"(.*?)"/g, '"artifactName": "' + getDomain(data.url) + '-${version}-${os}-${arch}.${ext}"'); + fs.writeFileSync(packageFile, packageString, 'utf8'); + // + child_process.spawnSync("npm", ["run", data.platform + (publish === true ? "-publish" : "")], {stdio: "inherit", cwd: "electron"}); +} + +// 还原配置 +function step3() { + let packageFile = path.resolve(__dirname, "package.json"); + let packageString = fs.readFileSync(packageFile, 'utf8'); + packageString = packageString.replace(/"name":\s*"(.*?)"/, `"name": "${config.name}"`); + packageString = packageString.replace(/"appId":\s*"(.*?)"/, `"appId": "${config.app.id}"`); + packageString = packageString.replace(/"artifactName":\s*"(.*?)"/g, '"artifactName": "${productName}-${version}-${os}-${arch}.${ext}"'); + fs.writeFileSync(packageFile, packageString, 'utf8'); +} + +if (["build", "prod"].includes(argv[2])) { + // 自定义编译 const questions = [ { type: 'input', - name: 'targetUrl', + name: 'website', message: "请输入网站地址", default: () => { if (fs.existsSync(nativeCachePath)) { @@ -135,10 +172,10 @@ if (argv[2] === "--build") { name: 'platform', message: "选择编译系统平台", choices: [{ - name: "MacOS Intel", + name: "MacOS", value: [platform[0]] }, { - name: "MacOS M1", + name: "MacOS arm64", value: [platform[1]] }, { name: "Window x86_64", @@ -149,43 +186,30 @@ if (argv[2] === "--build") { }] } ]; - inquirer.prompt(questions).then(answers => { - let data = `window.systemInformation = { - version: "${config.version}", - origin: "./", - apiUrl: "${formatUrl(answers.targetUrl)}api/" - }`; - fs.writeFileSync(nativeCachePath, formatUrl(answers.targetUrl)); - fs.writeFileSync(electronDir + "/config.js", data, 'utf8'); - // - fs.writeFileSync(devloadCachePath, "", 'utf8'); - let packageFile = path.resolve(__dirname, "package.json"); - let packageString = fs.readFileSync(packageFile, 'utf8'); - packageString = packageString.replace(/"version":\s*"(.*?)"/, `"version": "${config.version}"`); - packageString = packageString.replace(/"name":\s*"(.*?)"/, `"name": "${config.name}"`); - fs.writeFileSync(packageFile, packageString, 'utf8'); - // - child_process.spawnSync("mix", ["--production", "--", "--env", "--electron"], {stdio: "inherit"}); - answers.platform.forEach(arg => { - child_process.spawnSync("npm", ["run", arg], {stdio: "inherit", cwd: "electron"}); - let name = "" - if (arg == "build-mac-intel") { - name = config.name + "-" + config.version + ".dmg" - } else if (arg == "build-mac-m1") { - name = config.name + "-" + config.version + "-arm64.dmg" - } else if (arg == "build-win") { - name = config.name + " Setup " + config.version + ".exe" - } - if (name != "") { - fse.copySync( - path.resolve(__dirname, "dist", name), - path.resolve(__dirname, "build", getDomain(answers.targetUrl), config.version, name) - ) - } - }) + step1(); + answers.platform.forEach(platform => { + step2({ + "name": config.name, + "id": config.app.id, + "url": answers.website, + "platform": platform + }, false) + }); + step3(); }); +} else if (platform.includes(argv[2])) { + // 自动编译 + step1(); + config.app.sites.forEach((data) => { + if (data.name && data.id && data.url) { + data.platform = argv[2]; + step2(data, true) + } + }) + step3(); } else { + // 开发模式 fs.writeFileSync(devloadCachePath, formatUrl("127.0.0.1:" + env.parsed.APP_PORT), 'utf8'); child_process.spawn("mix", ["watch", "--hot", "--", "--env", "--electron"], {stdio: "inherit"}); child_process.spawn("npm", ["run", "start-quiet"], {stdio: "inherit", cwd: "electron"}); diff --git a/electron/package.json b/electron/package.json index 9f1d6f71..98418d30 100644 --- a/electron/package.json +++ b/electron/package.json @@ -1,6 +1,6 @@ { "name": "DooTask", - "version": "0.3.99", + "version": "0.4.0", "description": "DooTask is task management system.", "main": "main.js", "license": "MIT", @@ -8,13 +8,25 @@ "start": "electron-forge start", "start-quiet": "sleep 3 && electron-forge start &> /dev/null", "build": "electron-builder", - "build-mac-intel": "electron-builder --mac", - "build-mac-m1": "electron-builder --mac --arm64", + "build-mac": "electron-builder --mac", + "build-mac-arm": "electron-builder --mac --arm64", "build-win": "electron-builder --win", + "build-mac-publish": "electron-builder -p always --mac", + "build-mac-arm-publish": "electron-builder -p always --mac --arm64", + "build-win-publish": "electron-builder -p always --win", "package": "electron-forge package", "make": "electron-forge make", "publish": "electron-forge publish" }, + "author": { + "name": "KuaiFan", + "email": "aipaw@live.cn", + "url": "https://github.com/kuaifan" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/kuaifan/dootask.git" + }, "devDependencies": { "@electron-forge/cli": "^6.0.0-beta.61", "@electron-forge/maker-deb": "^6.0.0-beta.61", @@ -32,16 +44,27 @@ "xlsx": "^0.17.2" }, "build": { + "appId": "com.dootask.task", + "artifactName": "${productName}-${version}-${os}-${arch}.${ext}", "files": [ "public", "main.js", "preload.js" ], "mac": { - "icon": "../resources/assets/statics/public/images/logo-app.png" + "icon": "../resources/assets/statics/public/images/logo-app.png", + "target": "dmg", + "publish": ["github"] }, "win": { - "icon": "../resources/assets/statics/public/images/logo-app.ico" + "icon": "../resources/assets/statics/public/images/logo-app.ico", + "target": ["tar.gz", "nsis"], + "publish": ["github"] + }, + "nsis": { + "oneClick": false, + "artifactName": "${productName}-${version}-${os}-${arch}.${ext}", + "allowToChangeInstallationDirectory": true } }, "config": { diff --git a/package.json b/package.json index 2b41ad7e..c1660d88 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,36 @@ { "name": "DooTask", - "version": "0.3.99", + "version": "0.4.0", "description": "DooTask is task management system.", "scripts": { "start": "./cmd dev", "build": "./cmd prod", "version": "node ./version.js" }, + "app": { + "id": "com.dootask.task", + "sites": [ + { + "name": "DooTask", + "id": "com.dootask.task", + "url": "https://www.dootask.com/" + }, + { + "name": "HitoseaTask", + "id": "com.hitosea.task", + "url": "https://t.hitosea.com/" + } + ] + }, + "author": { + "name": "KuaiFan", + "email": "aipaw@live.cn", + "url": "https://github.com/kuaifan" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/kuaifan/dootask.git" + }, "devDependencies": { "axios": "^0.21", "cross-env": "^7.0.2", diff --git a/version.js b/version.js index b9120ef1..66ba3b6a 100644 --- a/version.js +++ b/version.js @@ -2,6 +2,7 @@ const fs = require('fs'); const path = require("path"); const exec = require('child_process').exec; const packageFile = path.resolve(process.cwd(), "package.json"); +const packageElectronFile = path.resolve(process.cwd(), "electron/package.json"); function runExec(command, cb) { exec(command, function (err, stdout, stderr) { @@ -26,7 +27,12 @@ runExec("git rev-list --all --count", function (err, response) { return; } let ver = Math.floor(num / 10000) + "." + Math.floor(num / 100) + "." + Math.floor(num % 100) + // let newResult = fs.readFileSync(packageFile, 'utf8').replace(/"version":\s*"(.*?)"/, `"version": "${ver}"`); fs.writeFileSync(packageFile, newResult, 'utf8'); + // + let newElectronResult = fs.readFileSync(packageElectronFile, 'utf8').replace(/"version":\s*"(.*?)"/, `"version": "${ver}"`); + fs.writeFileSync(packageElectronFile, newElectronResult, 'utf8'); + // console.log("new version: " + ver); });