From 0df3228abd9001e572b4a47df6a0a5ef697d81d1 Mon Sep 17 00:00:00 2001 From: iBug Date: Mon, 27 Jul 2020 01:19:19 +0800 Subject: [PATCH] Tweak build scripts, update README --- .github/workflows/build.yml | 4 +--- .gitignore | 1 + README.md | 2 +- build.py | 2 +- release-info.py | 14 ++++++++++---- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0149d7a..230d368 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,7 @@ on: branches: - master schedule: - - cron: "0 20 * * 5" # 4 AM CST every Saturday + - cron: "0 12 * * 6" # 8 PM CST every Saturday jobs: build: @@ -16,8 +16,6 @@ jobs: - name: Generate release info id: release-info run: python3 release-info.py - env: - TZ: Asia/Shanghai - uses: actions/create-release@v1 id: create_release env: diff --git a/.gitignore b/.gitignore index 2d0706e..85d347b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Output +release-info.md *.pac dist/ diff --git a/README.md b/README.md index 1ae8c3c..ca5ebc3 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ PAC scripts for proxies ## 使用 -获取方式:[本仓库的 `dist` 分支](https://github.com/iBug/pac/tree/dist) +获取方式:[本仓库的 Releases](https://github.com/iBug/pac/releases/latest) 每周六 12:00 (UTC) 会自动使用 GitHub Actions 运行[生成脚本](build.py)从数据源获取 IP 地址列表并生成 PAC 文件。 diff --git a/build.py b/build.py index d2941ea..5092b82 100755 --- a/build.py +++ b/build.py @@ -45,7 +45,7 @@ def main(): continue except HTTPError: continue - filename = f"pac-{date}-{key}.txt" + filename = f"pac-{key}.txt" with open(os.path.join(OUT_DIR, filename), "w") as f: f.write(code) f.write(data) diff --git a/release-info.py b/release-info.py index 86c4473..df9cafe 100755 --- a/release-info.py +++ b/release-info.py @@ -13,21 +13,27 @@ def create_output(name, content, target=sys.stdout): def main(): + if "GITHUB_ACTIONS" not in os.environ: + print("GitHub Actions environment expected but not found, abort.", file=sys.stderr) + sys.exit(1) + # Credits: https://stackoverflow.com/a/1398742/5958455 # Depends on os.environ["TZ"] + os.environ["TZ"] = "Etc/UTC" time.tzset() now = time.localtime(time.time()) create_output("tag_name", "release-{}".format(time.strftime("%Y%m%d", now))) - create_output("release_name", "Release {}".format(time.strftime("%Y-%m-%d", now))) + create_output("release_name", "{} (Auto)".format(time.strftime("%Y-%m-%d", now))) create_output("body_path", RELEASE_MARKDOWN_PATH) # Produce the markdown with open(RELEASE_MARKDOWN_PATH, "w") as f: - body = "This is an automatic release created from GitHub Actions run {} on {} ({})".format( - os.environ.get("GITHUB_RUN_NUMBER", "<unknown>"), + body = "This is an automatic release created from [GitHub Actions run {}](https://github.com/{}/actions/runs/{}) on {},".format( + os.environ["GITHUB_RUN_NUMBER"], + os.environ["GITHUB_REPOSITORY"], + os.environ["GITHUB_RUN_ID"], time.strftime("%B %-d, %Y", now), - os.environ.get("TZ", "UTC"), ) print(body, file=f)