@@ -84,38 +84,38 @@ jobs:
8484 run : |
8585 set -euo pipefail
8686 python - <<'PY'
87- import json
88- import os
89- import urllib.error
90- import urllib.request
91-
92- # The release is always published under a single tag to keep download URLs stable.
93- token = os.environ["GITHUB_TOKEN"]
94- repo = os.environ["GITHUB_REPOSITORY"]
95- tag = "rolling-release"
96- base = f"https://api.github.com/repos/{repo}"
97- headers = {"Authorization" : f"Bearer {token}", "Accept": "application/vnd.github+json"}
98-
99-
100- def request(method : str, url: str) -> tuple[int, bytes]:
101- req = urllib.request.Request(url, method=method, headers=headers)
102- try :
103- with urllib.request.urlopen(req) as resp :
104- return resp.status, resp.read()
105- except urllib.error.HTTPError as exc : # The API returns 404 when the tag or release is absent.
106- return exc.code, exc.read()
107-
108-
109- status, body = request("GET", f"{base}/releases/tags/{tag}")
110- if status == 200 :
111- release = json.loads(body.decode())
112- release_id = release.get("id")
113- if release_id :
114- request("DELETE", f"{base}/releases/{release_id}")
115-
116- # Remove the tag ref so the next release always attaches to the latest commit.
117- request("DELETE", f"{base}/git/refs/tags/{tag}")
118- PY
87+ import json
88+ import os
89+ import urllib.error
90+ import urllib.request
91+
92+ # The release is always published under a single tag to keep download URLs stable.
93+ token = os.environ["GITHUB_TOKEN"]
94+ repo = os.environ["GITHUB_REPOSITORY"]
95+ tag = "rolling-release"
96+ base = f"https://api.github.com/repos/{repo}"
97+ headers = {"Authorization": f"Bearer {token}", "Accept": "application/vnd.github+json"}
98+
99+
100+ def request(method: str, url: str) -> tuple[int, bytes]:
101+ req = urllib.request.Request(url, method=method, headers=headers)
102+ try:
103+ with urllib.request.urlopen(req) as resp:
104+ return resp.status, resp.read()
105+ except urllib.error.HTTPError as exc: # The API returns 404 when the tag or release is absent.
106+ return exc.code, exc.read()
107+
108+
109+ status, body = request("GET", f"{base}/releases/tags/{tag}")
110+ if status == 200:
111+ release = json.loads(body.decode())
112+ release_id = release.get("id")
113+ if release_id:
114+ request("DELETE", f"{base}/releases/{release_id}")
115+
116+ # Remove the tag ref so the next release always attaches to the latest commit.
117+ request("DELETE", f"{base}/git/refs/tags/{tag}")
118+ PY
119119
120120 - name : Publish release
121121 uses : softprops/action-gh-release@v1
0 commit comments