Skip to content

Commit 1d78b8e

Browse files
committed
feat(release): add semantic-release + chart-releaser and bump versions without sed
1 parent 3133aca commit 1d78b8e

7 files changed

Lines changed: 190 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Helm Chart Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Configure Git
21+
run: |
22+
git config user.name "github-actions[bot]"
23+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
24+
25+
- name: Run chart-releaser
26+
uses: helm/chart-releaser-action@v1.6.0
27+
env:
28+
CR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
with:
30+
charts_dir: charts
31+

.github/workflows/release.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
permissions:
8+
contents: write
9+
issues: write
10+
pull-requests: write
11+
12+
jobs:
13+
semantic-release:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up Git user
22+
run: |
23+
git config user.name "github-actions[bot]"
24+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
25+
26+
- name: Set up Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 'lts/*'
30+
cache: 'npm'
31+
32+
- name: Set up Python
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: '3.12'
36+
37+
- name: Install Python deps (bump tools)
38+
run: |
39+
python -m pip install --upgrade pip
40+
pip install tomlkit pyyaml
41+
42+
- name: Install semantic-release and plugins
43+
run: |
44+
npm install --no-audit --no-fund
45+
46+
- name: Semantic Release
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
run: npx semantic-release

.releaserc.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"branches": ["main"],
3+
"tagFormat": "v${version}",
4+
"plugins": [
5+
["@semantic-release/commit-analyzer", { "preset": "conventionalcommits" }],
6+
["@semantic-release/release-notes-generator", { "preset": "conventionalcommits" }],
7+
["@semantic-release/changelog", { "changelogFile": "CHANGELOG.md" }],
8+
[
9+
"@semantic-release/exec",
10+
{
11+
"prepareCmd": "bash scripts/prepare_release.sh ${nextRelease.version}"
12+
}
13+
],
14+
[
15+
"@semantic-release/git",
16+
{
17+
"assets": [
18+
"CHANGELOG.md",
19+
"pyproject.toml",
20+
"charts/discord-rag-bot/Chart.yaml"
21+
],
22+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
23+
}
24+
],
25+
["@semantic-release/github"]
26+
]
27+
}
28+

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file by semantic-release.
4+

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "discord-rag-bot-release",
3+
"private": true,
4+
"version": "0.0.0",
5+
"description": "CI release tooling (semantic-release and plugins)",
6+
"license": "UNLICENSED",
7+
"devDependencies": {
8+
"semantic-release": "^24.0.0",
9+
"@semantic-release/commit-analyzer": "^12.0.0",
10+
"@semantic-release/release-notes-generator": "^12.0.0",
11+
"@semantic-release/changelog": "^6.0.0",
12+
"@semantic-release/git": "^12.0.0",
13+
"@semantic-release/github": "^10.0.0",
14+
"@semantic-release/exec": "^6.0.3"
15+
}
16+
}
17+

scripts/bump_version.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
from pathlib import Path
4+
5+
def bump_pyproject(version: str) -> None:
6+
try:
7+
import tomlkit # type: ignore
8+
except Exception as e:
9+
print("tomlkit not available; please install tomlkit", file=sys.stderr)
10+
raise
11+
12+
p = Path("pyproject.toml")
13+
if not p.exists():
14+
return
15+
data = tomlkit.parse(p.read_text(encoding="utf-8"))
16+
if "project" in data and isinstance(data["project"], dict):
17+
data["project"]["version"] = version
18+
p.write_text(tomlkit.dumps(data), encoding="utf-8")
19+
20+
def bump_chart_yaml(version: str) -> None:
21+
try:
22+
import yaml # type: ignore
23+
except Exception as e:
24+
print("pyyaml not available; please install pyyaml", file=sys.stderr)
25+
raise
26+
27+
chart = Path("charts/discord-rag-bot/Chart.yaml")
28+
if not chart.exists():
29+
return
30+
data = yaml.safe_load(chart.read_text(encoding="utf-8")) or {}
31+
data["version"] = str(version)
32+
data["appVersion"] = str(version)
33+
chart.write_text(yaml.safe_dump(data, sort_keys=False), encoding="utf-8")
34+
35+
def main() -> int:
36+
if len(sys.argv) < 2:
37+
print("Usage: bump_version.py <version>", file=sys.stderr)
38+
return 2
39+
version = sys.argv[1]
40+
bump_pyproject(version)
41+
bump_chart_yaml(version)
42+
print(f"Bumped versions to {version}")
43+
return 0
44+
45+
if __name__ == "__main__":
46+
raise SystemExit(main())
47+

scripts/prepare_release.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
VERSION="${1:-}"
5+
if [[ -z "${VERSION}" ]]; then
6+
echo "Usage: $0 <version>" >&2
7+
exit 1
8+
fi
9+
10+
echo "Preparing release ${VERSION}"
11+
12+
# Use Python helper to bump versions (avoids sed)
13+
python3 scripts/bump_version.py "${VERSION}"
14+

0 commit comments

Comments
 (0)