From 643d12ff182827e724e1569a583bd625a0d1dd0c Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Fri, 3 Apr 2026 11:40:09 -0500 Subject: [PATCH] refactor(build): changes to auto release when we cahnge version --- .changeset/pre.json | 2 +- .gitea/workflows/release.yml | 119 +++++++++++++++++++++++++++++++++++ docker-compose.yml | 2 +- scripts/dockerscripts.md | 2 +- 4 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 .gitea/workflows/release.yml diff --git a/.changeset/pre.json b/.changeset/pre.json index bc397a3..ea8767d 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -2,7 +2,7 @@ "mode": "pre", "tag": "alpha", "initialVersions": { - "lst_v3": "1.0.1" + "lst_v3": "0.0.1" }, "changesets": [ "neat-years-unite", diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..868fe75 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,119 @@ +name: Create Gitea Release + +on: + push: + tags: + - "v*" + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Prepare release metadata + shell: bash + run: | + TAG="${GITHUB_REF_NAME:-${GITHUB_REF##refs/tags/}}" + VERSION="${TAG#v}" + + echo "TAG=$TAG" >> "$GITHUB_ENV" + echo "VERSION=$VERSION" >> "$GITHUB_ENV" + + if [[ "$TAG" == *-* ]]; then + echo "PRERELEASE=true" >> "$GITHUB_ENV" + else + echo "PRERELEASE=false" >> "$GITHUB_ENV" + fi + + - name: Extract matching CHANGELOG section + shell: bash + run: | + python <<'PY' + import os + import re + from pathlib import Path + + version = os.environ["VERSION"] + changelog_path = Path("CHANGELOG.md") + + if not changelog_path.exists(): + body = f"# {version}\n\nNo CHANGELOG.md found." + Path("release_body.md").write_text(body, encoding="utf-8") + raise SystemExit(0) + + text = changelog_path.read_text(encoding="utf-8") + + # Matches headings like: + # ## 1.2.3 + # ## 1.2.3-alpha.0 + # ## [1.2.3] + pattern = re.compile( + rf"^##\s+\[?{re.escape(version)}\]?(?:\s*-.*)?\n(.*?)(?=^##\s|\Z)", + re.MULTILINE | re.DOTALL, + ) + + match = pattern.search(text) + if match: + body = match.group(1).strip() + else: + body = text.strip() + + if not body: + body = f"Release {version}" + + Path("release_body.md").write_text(body + "\n", encoding="utf-8") + PY + + - name: Create Gitea release + env: + RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }} + GITEA_SERVER_URL: ${{ gitea.server_url }} + GITEA_REPOSITORY: ${{ gitea.repository }} + shell: bash + run: | + python <<'PY' + import json + import os + import urllib.request + + 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"] + + with open("release_body.md", "r", encoding="utf-8") as f: + body = f.read() + + 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 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 09e7327..d89cb9d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ services: environment: - NODE_ENV=production - LOG_LEVEL=info - - EXTERNAL_URL=192.168.8.222:3600 + - EXTERNAL_URL=http://192.168.8.222:3600 - DATABASE_HOST=host.docker.internal # if running on the same docker then do this - DATABASE_PORT=5433 - DATABASE_USER=${DATABASE_USER} diff --git a/scripts/dockerscripts.md b/scripts/dockerscripts.md index b495f36..37282a8 100644 --- a/scripts/dockerscripts.md +++ b/scripts/dockerscripts.md @@ -74,7 +74,7 @@ stage the change log file git commit -m "chore(release): version packages" -git tag v1.0.1 this will be the new version +git tag v0.0.1-alpha.0 this will be the new version then push it