From a661d55d1fd0832f5bc5466236431c6864a12da0 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sat, 20 Apr 2024 22:51:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=8D=E5=A6=A5=E5=8D=8F=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy.py | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/deploy.py b/deploy.py index 453ec53..05f2fd0 100644 --- a/deploy.py +++ b/deploy.py @@ -8,28 +8,38 @@ ON_CF = os.getenv("CF_PAGES") == "1" if ON_CF: print("Running on Cloudflare Pages, trying to git fetch --all") + # add remote + run( + ["git", "remote", "add", "origin", "https://github.com/shenjackyuanjie/fast-namerena.git"], + ) result = run(["git", "fetch", "--all"], check=False) - print(f"git fetch --all: {result.stdout}") + print(f"git fetch --all: {result}") def get_env_info() -> dict[str, str]: # 读取环境变量 env_info = {} # git branch - branch = run( - ["git", "branch", "--show-current"], - capture_output=True, - text=True, - encoding="utf-8", - ).stdout + if ON_CF: + branch = os.getenv("CF_PAGES_BRANCH") or "unknown" + else: + branch = run( + ["git", "branch", "--show-current"], + capture_output=True, + text=True, + encoding="utf-8", + ).stdout env_info["branch"] = branch.strip() # git commit hash - commit = run( - ["git", "rev-parse", "HEAD"], - capture_output=True, - text=True, - encoding="utf-8", - ).stdout + if ON_CF: + commit = os.getenv("CF_PAGES_COMMIT_SHA") or "unknown" + else: + commit = run( + ["git", "rev-parse", "HEAD"], + capture_output=True, + text=True, + encoding="utf-8", + ).stdout env_info["commit"] = commit.strip() # git commit message message = run( @@ -40,9 +50,12 @@ def get_env_info() -> dict[str, str]: ) env_info["message"] = message.stdout.strip() # git tag - tag = run( - ["git", "describe", "--tags"], capture_output=True, text=True, encoding="utf-8" - ).stdout + if ON_CF: + tag = "cf_pages" + else: + tag = run( + ["git", "describe", "--tags"], capture_output=True, text=True, encoding="utf-8" + ).stdout env_info["tag"] = tag.strip() return env_info