From 0d189ca617cfaeca50d84793525982112deff099 Mon Sep 17 00:00:00 2001 From: GyDi Date: Sun, 13 Mar 2022 00:52:31 +0800 Subject: [PATCH] chore: green version bundle --- .github/workflows/ci.yml | 4 +++ package.json | 1 + scripts/green.mjs | 56 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 scripts/green.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9d7e16..3ba0ddc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,6 +67,10 @@ jobs: releaseDraft: false prerelease: true + - name: Green zip bundle + runs: | + yarn run green + release-update: needs: release runs-on: macos-11 diff --git a/package.json b/package.json index 2439d87..7885b51 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "web:build": "tsc && vite build", "web:serve": "vite preview", "check": "node scripts/check.mjs", + "green": "node scripts/green.mjs", "publish": "node scripts/publish.mjs", "release": "node scripts/release.mjs", "prepare": "husky install" diff --git a/scripts/green.mjs b/scripts/green.mjs new file mode 100644 index 0000000..05a53d3 --- /dev/null +++ b/scripts/green.mjs @@ -0,0 +1,56 @@ +import fs from "fs-extra"; +import path from "path"; +import AdmZip from "adm-zip"; +import { createRequire } from "module"; +import { getOctokit, context } from "@actions/github"; + +/// Script for ci +/// 打包绿色版/便携版 (only Windows) +async function resolveGreen() { + if (process.platform !== "win32") return; + + const releaseDir = "./src-tauri/target/release"; + + if (!(await fs.pathExists(releaseDir))) { + throw new Error("could not found the release dir"); + } + + const zip = new AdmZip(); + + zip.addLocalFile(path.join(releaseDir, "Clash Verge.exe")); + zip.addLocalFile(path.join(releaseDir, "clash.exe")); + zip.addLocalFolder(path.join(releaseDir, "resources"), "resources"); + + const require = createRequire(import.meta.url); + const packageJson = require("../package.json"); + const { version } = packageJson; + + const zipFile = `Clash.Verge_${version}_x64_green.zip`; + zip.writeZip(zipFile); + + console.log("[INFO]: create green zip successfully"); + + // push release assets + if (process.env.GITHUB_TOKEN === undefined) { + throw new Error("GITHUB_TOKEN is required"); + } + + const options = { owner: context.repo.owner, repo: context.repo.repo }; + const github = getOctokit(process.env.GITHUB_TOKEN); + + const { data: release } = await github.rest.repos.getReleaseByTag({ + ...options, + tag: `v${version}`, + }); + + console.log(release.name); + + await github.rest.repos.uploadReleaseAsset({ + ...options, + release_id: release.id, + name: zipFile, + data: zip.toBuffer(), + }); +} + +resolveGreen().catch(console.error);