From eb29a86ce16b85a44aa5e1d9c31262bd0aba1bc1 Mon Sep 17 00:00:00 2001 From: yichengchen <11733500+yichengchen@users.noreply.github.com> Date: Mon, 30 Sep 2019 14:42:28 +0800 Subject: [PATCH] add clash build version in ci --- .gitignore | 1 + .travis.yml | 6 ++--- ClashX/ci_build_clash.py | 50 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 ClashX/ci_build_clash.py diff --git a/.gitignore b/.gitignore index 9fcc586..60b4984 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ ClashX/Resources/dashboard ClashX.app *.dmg **/xcuserdata/ +.idea diff --git a/.travis.yml b/.travis.yml index b6da598..c15c0a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,9 +20,9 @@ install: - cd .. - brew update - echo `go version` -- brew upgrade go || true -- echo `go version` -- CGO_CFLAGS=-mmacosx-version-min=10.10 CGO_LDFLAGS=-mmacosx-version-min=10.10 go build -buildmode=c-archive +#- brew upgrade go || true +#- echo `go version` +- python3 ci_build_clash.py - cd $TRAVIS_BUILD_DIR script: diff --git a/ClashX/ci_build_clash.py b/ClashX/ci_build_clash.py new file mode 100644 index 0000000..6646b34 --- /dev/null +++ b/ClashX/ci_build_clash.py @@ -0,0 +1,50 @@ +import subprocess +import datetime +import plistlib + + +def get_version(): + with open('./go.mod') as file: + for line in file.readlines(): + if "require" in line: + return line.split(" ")[-1].strip() + return "unknown" + + +def build_clash(version): + build_time = datetime.datetime.now().strftime("%Y-%m-%d-%H%M") + command = f"""CGO_CFLAGS=-mmacosx-version-min=10.12 \ +CGO_LDFLAGS=-mmacosx-version-min=10.10 \ +GOBUILD=CGO_ENABLED=0 \ +go build -ldflags '-X "github.com/Dreamacro/clash/constant.Version={version}" \ +-X "github.com/Dreamacro/clash/constant.BuildTime={build_time}"' \ +-buildmode=c-archive """ + subprocess.check_output(command, shell=True) + + +def write_to_info(version): + path = "info.plist" + + with open(path, 'rb') as f: + contents = plistlib.load(f) + + if not contents: + exit(-1) + + contents["coreVersion"] = version + with open(path, 'wb') as f: + plistlib.dump(contents, f, sort_keys=False) + + +def run(): + version = get_version() + print("current clash version: ", version) + build_clash(version) + print("build static library complete!") + print("writing info.plist") + write_to_info(version) + print("done") + + +if __name__ == "__main__": + run()