From 9237f17f2ffdec3a1d1408b5409c88463d0426ca Mon Sep 17 00:00:00 2001 From: Xu <34770031+Blinue@users.noreply.github.com> Date: Tue, 28 Nov 2023 20:11:37 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=94=AF=E6=8C=81=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E7=89=88=E5=92=8C=E7=94=9F=E6=88=90=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=8F=91=E8=A1=8C=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 5 +++++ publish.py | 37 ++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 03169280e..4153c3219 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,6 +19,10 @@ on: description: 'Tag' required: false type: string + prerelease: + description: 'Prerelease' + required: true + type: boolean jobs: release: runs-on: windows-latest @@ -46,4 +50,5 @@ jobs: MINOR: ${{ inputs.minor }} PATCH: ${{ inputs.patch }} TAG: ${{ inputs.tag }} + PRERELEASE: ${{ inputs.prerelease }} ACCESS_TOKEN: ${{ secrets.CONTENTS_ACCESS_TOKEN }} diff --git a/publish.py b/publish.py index 3161bb363..9831aeb6b 100644 --- a/publish.py +++ b/publish.py @@ -38,6 +38,8 @@ if tag == "": tag = f"v{majorVersion}.{minorVersion}.{patchVersion}" + isPrerelease = os.environ["PRERELEASE"].lower() == "true" + githubAccessToken = os.environ["ACCESS_TOKEN"] repo = os.environ["GITHUB_REPOSITORY"] actor = os.environ["GITHUB_ACTOR"] @@ -254,17 +256,50 @@ def remove_file(file): shutil.make_archive(pkgName, "zip", "publish") pkgName += ".zip" - # 发布 release headers = { "Accept": "application/vnd.github+json", "Authorization": "Bearer " + githubAccessToken, "X-GitHub-Api-Version": "2022-11-28", } + + # 获取前一个发布版本来生成默认发行说明 + prevReleaseTag = None + try: + if isPrerelease: + # 发布预发行版与最新的版本(无论是正式版还是预发行版)对比 + response = requests.get( + f"https://api.github.com/repos/{repo}/releases", + json={ + "per_page": 1 + }, + headers=headers + ) + if response.ok: + prevReleaseTag = response.json()[0]["tag_name"] + else: + # 发布正式版则与最新的正式版对比 + # 由于可以自己选择最新版本,此接口可能不会返回时间上最新发布的版本,不是大问题 + response = requests.get(f"https://api.github.com/repos/{repo}/releases/latest", headers=headers) + if response.ok: + prevReleaseTag = response.json()["tag_name"] + except: + # 忽略错误 + pass + + # 发布 release + if prevReleaseTag == None: + body = "" + else: + # 默认发行说明为比较两个 tag + body = f"https://github.com/{repo}/compare/{prevReleaseTag}...{tag}" + response = requests.post( f"https://api.github.com/repos/{repo}/releases", json={ "tag_name": tag, "name": tag, + "prerelease": isPrerelease, + "body": body, "discussion_category_name": "Announcements", }, headers=headers,