Skip to content

feat: disable per-tracker/MPPT entities by default (#445) #468

feat: disable per-tracker/MPPT entities by default (#445)

feat: disable per-tracker/MPPT entities by default (#445) #468

name: Release Drafter
on:
push:
branches:
- main
pull_request:
types: [opened, reopened, synchronize]
permissions:
contents: read
jobs:
update_release_draft:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.14'
- name: Install victron-mqtt library
run: pip install victron-mqtt
- name: Find previous release tag
id: prev_tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
prev=$(gh release list --json tagName,isDraft -q '[.[] | select(.isDraft | not)] | .[0].tagName')
echo "Previous release tag: $prev"
echo "tag=$prev" >> $GITHUB_OUTPUT
- name: Get commit messages since previous tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
prev_tag="${{ steps.prev_tag.outputs.tag }}"
if [ -z "$prev_tag" ]; then
prev_tag=$(git rev-list --max-parents=0 HEAD)
fi
COMMITS=$(git log "$prev_tag"..HEAD --pretty=format:"- %s" | head -20)
echo "COMMITS<<EOF" >> $GITHUB_ENV
echo "$COMMITS" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Collect unique commit authors as GitHub usernames
AUTHORS=$(git log "$prev_tag"..HEAD --pretty=format:"%an" | sort -u | while read -r name; do
email=$(git log --author="$name" --pretty=format:"%ae" -1)
username=$(echo "$email" | sed -n 's/.*+\(.*\)@users.noreply.github.com/\1/p')
if [ -n "$username" ]; then
echo "@$username"
else
username=$(gh api "/search/users?q=$email+in:email" --jq '.items[0].login // empty' 2>&1 || echo "")
# If gh api failed, username will contain error JSON — reject anything that's not a simple word
if [[ "$username" =~ ^[a-zA-Z0-9_-]+$ ]]; then
echo "@$username"
else
echo "@$name"
fi
fi
done | sort -u | paste -sd ',' | sed 's/,/, /g')
echo "AUTHORS=$AUTHORS" >> $GITHUB_ENV
- name: Detect breaking changes
id: breaking
run: |
prev_tag="${{ steps.prev_tag.outputs.tag }}"
if [ -z "$prev_tag" ]; then
echo "found=false" >> $GITHUB_OUTPUT
exit 0
fi
git show "${prev_tag}:victron_mqtt.json" > old.json 2>/dev/null || true
if [ ! -f old.json ] || [ ! -s old.json ]; then
echo "found=false" >> $GITHUB_OUTPUT
exit 0
fi
set +e
breaking_output=$(python -m victron_mqtt.utils.detect_breaking_changes old.json victron_mqtt.json 2>/dev/null)
exit_code=$?
set -e
rm -f old.json
if [ $exit_code -eq 1 ] && [ -n "$breaking_output" ]; then
echo "found=true" >> $GITHUB_OUTPUT
echo "BREAKING_CONTENT<<EOF" >> $GITHUB_ENV
echo "$breaking_output" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
else
echo "found=false" >> $GITHUB_OUTPUT
fi
- name: Collect library release notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
prev_tag="${{ steps.prev_tag.outputs.tag }}"
# Get old and new library versions
old_ver=""
if [ -n "$prev_tag" ]; then
old_ver=$(git show "${prev_tag}:custom_components/victron_mqtt/_vendor/__init__.py" 2>/dev/null \
| sed -n 's/.*VICTRON_MQTT_VERSION *= *"\(.*\)".*/\1/p')
fi
new_ver=$(sed -n 's/.*VICTRON_MQTT_VERSION *= *"\(.*\)".*/\1/p' custom_components/victron_mqtt/_vendor/__init__.py)
echo "Old library version: $old_ver"
echo "New library version: $new_ver"
if [ -z "$old_ver" ] || [ "$old_ver" = "$new_ver" ]; then
echo "LIB_NOTES=" >> $GITHUB_ENV
exit 0
fi
# Fetch all library releases between old and new version
lib_notes=""
releases=$(gh release list --repo tomer-w/victron_mqtt --json tagName,isDraft -q '[.[] | select(.isDraft | not)] | .[].tagName')
collecting=false
while IFS= read -r tag; do
ver="${tag#v}"
if [ "$ver" = "$old_ver" ]; then
break
fi
if [ "$ver" = "$new_ver" ]; then
collecting=true
fi
if [ "$collecting" = true ]; then
body=$(gh release view "$tag" --repo tomer-w/victron_mqtt --json body -q .body 2>/dev/null || true)
if [ -n "$body" ]; then
lib_notes="${lib_notes}
### ${tag}
${body}
"
fi
fi
done <<< "$releases"
echo "LIB_NOTES<<EOF" >> $GITHUB_ENV
echo "$lib_notes" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: release-drafter/release-drafter@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Enhance draft release notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
DRAFT_TAG=$(gh release list --limit 50 --json isDraft,tagName -q '[.[] | select(.isDraft)] | .[0].tagName')
if [ -z "$DRAFT_TAG" ] || [ "$DRAFT_TAG" = "null" ]; then
echo "No draft release found"
exit 0
fi
BODY=$(gh release view "$DRAFT_TAG" --json body -q .body)
if [ -n "$COMMITS" ]; then
export BODY
BODY=$(python3 -c "
import os, re
body = os.environ['BODY']
commits = os.environ['COMMITS']
authors = os.environ.get('AUTHORS', '').strip()
lib_notes = os.environ.get('LIB_NOTES', '').strip()
# Clean up library notes: remove Contributors section and Changes headers
if lib_notes:
# Remove ## Contributors section and everything after it per release
lib_notes = re.sub(r'## Contributors[^\n]*\n.*?(?=###|\Z)', '', lib_notes, flags=re.DOTALL)
# Remove ## Changes headers (keep the content)
lib_notes = re.sub(r'^## Changes[^\n]*\n+', '', lib_notes, flags=re.MULTILINE)
# Downgrade any remaining ## headers to ####
lib_notes = re.sub(r'^## ', '#### ', lib_notes, flags=re.MULTILINE)
lib_notes = lib_notes.strip()
# Remove release-drafter's empty placeholders
body = body.replace('No changes\n', '').replace('No changes', '')
body = body.replace('No contributors\n', '').replace('No contributors', '')
# Split body into sections
parts = re.split(r'(## [^\n]+)', body)
# Modify section contents
for i, part in enumerate(parts):
if part.strip() == '## Changes' and i + 1 < len(parts):
existing = parts[i + 1].strip()
# Remove lone asterisk (release-drafter empty placeholder)
if existing == '*':
existing = ''
items = []
if existing:
items.append(existing)
items.append(commits)
parts[i + 1] = '\n\n' + '\n'.join(items) + '\n\n'
# Append library changes section after Changes
if lib_notes:
parts[i + 1] += '## Library Changes\n\n' + lib_notes + '\n\n'
elif part.strip() == '## Contributors' and i + 1 < len(parts):
existing = parts[i + 1].strip()
if not existing and authors:
parts[i + 1] = '\n\n' + authors + '\n'
body = ''.join(parts)
# If no Changes section existed, append library changes at the end
if lib_notes and '## Library Changes' not in body:
body = body.rstrip() + '\n\n## Library Changes\n\n' + lib_notes
if '## Contributors' not in body and authors:
body = body.rstrip() + '\n\n## Contributors\n\n' + authors
print(body.rstrip())
")
fi
# Prepend breaking changes
if [ "${{ steps.breaking.outputs.found }}" = "true" ]; then
BODY="${BREAKING_CONTENT}
${BODY}"
fi
gh release edit "$DRAFT_TAG" --notes "$BODY"
autolabeler:
if: github.event_name == 'pull_request'
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v7
with:
dry-run: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}