优化发布

This commit is contained in:
kuaifan 2023-03-19 22:11:47 +08:00
parent 33b1450547
commit f2f9e433b5
7 changed files with 90 additions and 281 deletions

View File

@ -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

View File

@ -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

31
.github/workflows/publish-desktop.yml vendored Normal file
View File

@ -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

View File

@ -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

View File

@ -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);
}

97
electron/build.js vendored
View File

@ -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)
})

View File

@ -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"
}
]
}