refactor(release): changes to only have the changelog in the release
This commit is contained in:
@@ -104,53 +104,16 @@ jobs:
|
|||||||
docker tag "$IMAGE_NAME:$TAG" "$IMAGE_NAME:$CHANNEL"
|
docker tag "$IMAGE_NAME:$TAG" "$IMAGE_NAME:$CHANNEL"
|
||||||
docker push "$IMAGE_NAME:$CHANNEL"
|
docker push "$IMAGE_NAME:$CHANNEL"
|
||||||
|
|
||||||
- name: Create Gitea release
|
- name: Extract matching CHANGELOG section
|
||||||
env:
|
|
||||||
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
||||||
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
|
||||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
python3 - <<'PY'
|
python3 - <<'PY'
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import urllib.request
|
|
||||||
import urllib.error
|
|
||||||
|
|
||||||
tag = os.environ["TAG"]
|
|
||||||
prerelease = os.environ["PRERELEASE"].lower() == "true"
|
|
||||||
server_url = os.environ["GITEA_SERVER_URL"].rstrip("/")
|
|
||||||
repo = os.environ["GITEA_REPOSITORY"]
|
|
||||||
token = os.environ["RELEASE_TOKEN"]
|
|
||||||
|
|
||||||
image_name = os.environ["IMAGE_NAME"]
|
|
||||||
tag = os.environ["TAG"]
|
|
||||||
|
|
||||||
with open("release_body.md", "r", encoding="utf-8") as f:
|
|
||||||
changelog_body = f.read()
|
|
||||||
|
|
||||||
header = (
|
|
||||||
"## 🚀 How to run this release\n\n"
|
|
||||||
"### Pull image\n"
|
|
||||||
f"```bash\n"
|
|
||||||
f"docker pull {image_name}:{tag}\n"
|
|
||||||
f"```\n\n"
|
|
||||||
"### Run container\n"
|
|
||||||
f"```bash\n"
|
|
||||||
f"docker run -d \\\n"
|
|
||||||
f" --name lst \\\n"
|
|
||||||
f" -p 3000:3000 \\\n"
|
|
||||||
f" {image_name}:{tag}\n"
|
|
||||||
f"```\n\n"
|
|
||||||
"---\n\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
version = os.environ["VERSION"]
|
version = os.environ["VERSION"]
|
||||||
changelog_path = Path("CHANGELOG.md")
|
changelog_path = Path("lst_v3/CHANGELOG.md")
|
||||||
|
|
||||||
if not changelog_path.exists():
|
if not changelog_path.exists():
|
||||||
Path("release_body.md").write_text(f"Release {version}\n", encoding="utf-8")
|
Path("release_body.md").write_text(f"Release {version}\n", encoding="utf-8")
|
||||||
@@ -159,45 +122,19 @@ jobs:
|
|||||||
text = changelog_path.read_text(encoding="utf-8")
|
text = changelog_path.read_text(encoding="utf-8")
|
||||||
|
|
||||||
pattern = re.compile(
|
pattern = re.compile(
|
||||||
rf"^##\s+{re.escape(version)}(?:\s*\([^)]+\))?\n(.*?)(?=^##\s+[0-9]|\Z)",
|
rf"^##\s+\[?{re.escape(version)}\]?[^\n]*\n(.*?)(?=^##\s+\[?[0-9]|\Z)",
|
||||||
re.MULTILINE | re.DOTALL,
|
re.MULTILINE | re.DOTALL,
|
||||||
)
|
)
|
||||||
|
|
||||||
match = pattern.search(text)
|
match = pattern.search(text)
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
body = match.group(1).strip()
|
body = match.group(1).strip()
|
||||||
else:
|
else:
|
||||||
body = f"Release {version}"
|
body = f"Release {version}"
|
||||||
|
|
||||||
|
if not body:
|
||||||
|
body = f"Release {version}"
|
||||||
|
|
||||||
Path("release_body.md").write_text(body + "\n", encoding="utf-8")
|
Path("release_body.md").write_text(body + "\n", encoding="utf-8")
|
||||||
|
print(body)
|
||||||
url = f"{server_url}/api/v1/repos/{repo}/releases"
|
|
||||||
payload = {
|
|
||||||
"tag_name": tag,
|
|
||||||
"name": tag,
|
|
||||||
"body": body,
|
|
||||||
"draft": False,
|
|
||||||
"prerelease": prerelease,
|
|
||||||
}
|
|
||||||
|
|
||||||
data = json.dumps(payload).encode("utf-8")
|
|
||||||
req = urllib.request.Request(
|
|
||||||
url,
|
|
||||||
data=data,
|
|
||||||
method="POST",
|
|
||||||
headers={
|
|
||||||
"Authorization": f"token {token}",
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"Accept": "application/json",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
with urllib.request.urlopen(req) as resp:
|
|
||||||
print(resp.read().decode("utf-8"))
|
|
||||||
except urllib.error.HTTPError as e:
|
|
||||||
details = e.read().decode("utf-8", errors="replace")
|
|
||||||
print(details)
|
|
||||||
raise
|
|
||||||
PY
|
PY
|
||||||
Reference in New Issue
Block a user