From 10a567449035e14e5952872dad8faaaa1ebf1826 Mon Sep 17 00:00:00 2001 From: SmallMain Date: Fri, 1 Nov 2024 11:47:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E8=84=9A=E6=9C=AC=E5=AE=B9=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/index.js | 85 ++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/scripts/index.js b/scripts/index.js index 21194fbd..6ac1257b 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -419,48 +419,55 @@ const needPublish = await confirm({ default: true, }); if (needPublish && !DRYRUN) { - - const octokit = new Octokit({ - auth: env.GITHUB_TOKEN, - }); - - console.log("创建 Release:", tag); - - let releaseId = 0; try { - const { data } = await octokit.rest.repos.getReleaseByTag({ - owner: "smallmain", - repo: "cocos-enhance-kit", - tag: tag, + const octokit = new Octokit({ + auth: env.GITHUB_TOKEN, }); - releaseId = data.id; - releaseUrl = data.html_url; - } catch (error) { - const { data } = await octokit.rest.repos.createRelease({ - owner: "smallmain", - repo: "cocos-enhance-kit", - name: tag, - tag_name: tag, - body: `适配 Cocos Creator v${engineVersion} 版本\n\n> 注意,如果你需要使用模拟器预览,请按照官方的 [引擎定制文档](https://docs.cocos.com/creator/2.4/manual/zh/advanced-topics/engine-customization.html#25-%E7%BC%96%E8%AF%91%E6%A8%A1%E6%8B%9F%E5%99%A8) 重新编译原生模拟器。`, - prerelease: false, - make_latest: "legacy", - }); - releaseId = data.id; - releaseUrl = data.html_url; - } - console.log("上传至 Release:", zipPath); - const fileContent = readFileSync(zipPath); - await octokit.rest.repos.uploadReleaseAsset({ - owner: "smallmain", - repo: "cocos-enhance-kit", - release_id: releaseId, - data: fileContent, - name: basename(zipPath), - headers: { - 'content-type': 'application/zip', - }, - }); + console.log("创建 Release:", tag); + + let releaseId = 0; + try { + const { data } = await octokit.rest.repos.getReleaseByTag({ + owner: "smallmain", + repo: "cocos-enhance-kit", + tag: tag, + }); + releaseId = data.id; + releaseUrl = data.html_url; + } catch (error) { + const { data } = await octokit.rest.repos.createRelease({ + owner: "smallmain", + repo: "cocos-enhance-kit", + name: tag, + tag_name: tag, + body: `适配 Cocos Creator v${engineVersion} 版本\n\n> 注意,如果你需要使用模拟器预览,请按照官方的 [引擎定制文档](https://docs.cocos.com/creator/2.4/manual/zh/advanced-topics/engine-customization.html#25-%E7%BC%96%E8%AF%91%E6%A8%A1%E6%8B%9F%E5%99%A8) 重新编译原生模拟器。`, + prerelease: false, + make_latest: "legacy", + }); + releaseId = data.id; + releaseUrl = data.html_url; + } + + console.log("上传至 Release:", zipPath); + const fileContent = readFileSync(zipPath); + await octokit.rest.repos.uploadReleaseAsset({ + owner: "smallmain", + repo: "cocos-enhance-kit", + release_id: releaseId, + data: fileContent, + name: basename(zipPath), + headers: { + 'content-type': 'application/zip', + }, + }); + } catch (error) { + console.error(error); + await confirm({ + message: `自动上传至 Github Release 失败,请手动上传后继续`, + default: true, + }); + } } console.log("已发布到 Github Release:", tag);