fix: Claude ist ein dummer Hurensohn!

This commit is contained in:
2026-03-05 17:12:18 +01:00
parent c3a7c504db
commit 948c4f8768
2 changed files with 103 additions and 109 deletions

View File

@@ -26,14 +26,14 @@ jobs:
- name: Install dependencies
run: |
pip install packaging
pip install gitpython packaging
- name: Create Release PR
env:
GIT_TOKEN: ${{ secrets.GT_TOKEN }}
REPO: "TDPI/jellyfin-plugin-smartnotify"
run: |
python3 << 'PYEOF'
python3 << 'EOF'
import re
import subprocess
import json
@@ -94,45 +94,78 @@ jobs:
print(f'Bumping version from {current_version} to {new_version}')
# Build changelog content for PR body (template for manual editing)
changelog_body = ''
# Update version in manifest
with open('.release-please-manifest.json', 'r') as f:
manifest = json.load(f)
manifest['.'] = new_version
with open('.release-please-manifest.json', 'w') as f:
json.dump(manifest, f, indent=2)
# Update version in .csproj
csproj_path = 'Jellyfin.Plugin.SmartNotify/Jellyfin.Plugin.SmartNotify.csproj'
with open(csproj_path, 'r') as f:
csproj = f.read()
csproj = re.sub(r'<AssemblyVersion>.*?</AssemblyVersion>', f'<AssemblyVersion>{new_version}.0</AssemblyVersion>', csproj)
csproj = re.sub(r'<FileVersion>.*?</FileVersion>', f'<FileVersion>{new_version}.0</FileVersion>', csproj)
with open(csproj_path, 'w') as f:
f.write(csproj)
# Generate CHANGELOG
changelog_entry = f'## {new_version} ({subprocess.check_output(["date", "+%Y-%m-%d"], text=True).strip()})\n\n'
if has_breaking:
changelog_body += '### BREAKING CHANGES\n\n'
changelog_entry += '### BREAKING CHANGES\n\n'
for c in commits:
if '!' in c.split(':')[0] or 'BREAKING CHANGE' in c:
changelog_body += f'* {c}\n'
changelog_body += '\n'
changelog_entry += f'* {c}\n'
changelog_entry += '\n'
if has_feat:
changelog_body += '### Features\n\n'
changelog_entry += '### Features\n\n'
for c in commits:
if c.startswith('feat'):
changelog_body += f'* {c}\n'
changelog_body += '\n'
changelog_entry += f'* {c}\n'
changelog_entry += '\n'
if has_fix:
changelog_body += '### Bug Fixes\n\n'
changelog_entry += '### Bug Fixes\n\n'
for c in commits:
if c.startswith('fix'):
changelog_body += f'* {c}\n'
changelog_body += '\n'
changelog_entry += f'* {c}\n'
changelog_entry += '\n'
if has_chore:
changelog_body += '### Chores\n\n'
changelog_entry += '### Chores\n\n'
for c in commits:
if c.startswith('chore'):
changelog_body += f'* {c}\n'
changelog_body += '\n'
changelog_entry += f'* {c}\n'
changelog_entry += '\n'
try:
with open('CHANGELOG.md', 'r') as f:
old_changelog = f.read()
except:
old_changelog = '# Changelog\n\n'
with open('CHANGELOG.md', 'w') as f:
f.write('# Changelog\n\n' + changelog_entry + '\n' + old_changelog.replace('# Changelog\n', '').lstrip())
subprocess.run(['git', 'config', 'user.name', 'Gitea Actions'])
subprocess.run(['git', 'config', 'user.email', 'actions@git.tdpi.dev'])
subprocess.run(['git', 'add', '.release-please-manifest.json', 'CHANGELOG.md', csproj_path])
subprocess.run(['git', 'commit', '-m', f'chore(main): release {new_version}'])
# Write version and changelog to temp files for shell script
with open('/tmp/new_version', 'w') as f:
f.write(new_version)
# Write changelog body (without header) for PR body
with open('/tmp/changelog_body', 'w') as f:
f.write(changelog_body.strip())
PYEOF
f.write(changelog_entry)
EOF
NEW_VERSION=$(cat /tmp/new_version 2>/dev/null || echo "")
if [ -z "$NEW_VERSION" ]; then
@@ -141,37 +174,32 @@ jobs:
fi
BRANCH_NAME="release-please--branches--main"
# Build PR body with changelog as editable template
CHANGELOG_BODY=$(cat /tmp/changelog_body)
# PR body with instructions
PR_BODY=$(cat <<BODYEOF
> **Bearbeite diesen Text!** Der Changelog unten wurde automatisch aus Commits generiert.
> Passe ihn an bevor du den PR mergest - dieser Text wird als Changelog für die Version verwendet.
> **Bearbeite diesen Text!** Der Changelog unten wurde automatisch aus Commits generiert.
> Passe ihn an bevor du den PR mergest - dieser Text wird als Changelog verwendet.
## ${NEW_VERSION}
${CHANGELOG_BODY}
BODYEOF
${CHANGELOG_BODY}
BODYEOF
)
PR_BODY_JSON=$(echo "$PR_BODY" | jq -Rs .)
# Check if branch already exists
# Push changes
if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then
# Update existing branch - force push placeholder commit
git config user.name "Gitea Actions"
git config user.email "actions@git.tdpi.dev"
git checkout -b "$BRANCH_NAME" origin/"$BRANCH_NAME" 2>/dev/null || git checkout -b "$BRANCH_NAME"
# Reset to main to get latest changes
git reset --hard origin/main
git push -f origin HEAD:"$BRANCH_NAME"
PR_EXISTS=true
else
git push origin HEAD:"$BRANCH_NAME"
PR_EXISTS=false
fi
# Update existing PR
if [ "$PR_EXISTS" = true ]; then
PR_NUMBER=$(curl -s "https://git.tdpi.dev/api/v1/repos/$REPO/pulls?state=open&head=$BRANCH_NAME" \
-H "Authorization: token $GIT_TOKEN" | jq -r '.[0].number')
if [ "$PR_NUMBER" != "null" ] && [ -n "$PR_NUMBER" ]; then
if [ "$PR_NUMBER" != "null" ]; then
curl -X PATCH "https://git.tdpi.dev/api/v1/repos/$REPO/pulls/$PR_NUMBER" \
-H "Authorization: token $GIT_TOKEN" \
-H "Content-Type: application/json" \
@@ -181,10 +209,6 @@ jobs:
}"
fi
else
# Create new branch (identical to main for now)
git push origin HEAD:"$BRANCH_NAME"
# Create new PR
curl -X POST "https://git.tdpi.dev/api/v1/repos/$REPO/pulls" \
-H "Authorization: token $GIT_TOKEN" \
-H "Content-Type: application/json" \

View File

@@ -20,17 +20,14 @@ jobs:
fetch-depth: 0
token: ${{ secrets.GT_TOKEN }}
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
- name: Get version
id: version
run: |
pip install packaging
VERSION=$(jq -r '."."' .release-please-manifest.json)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Extract version and changelog from PR
id: release-info
- name: Get changelog from PR body
id: changelog
env:
GIT_TOKEN: ${{ secrets.GT_TOKEN }}
REPO: "TDPI/jellyfin-plugin-smartnotify"
@@ -40,89 +37,62 @@ jobs:
PR_BODY=$(curl -s "https://git.tdpi.dev/api/v1/repos/$REPO/pulls/$PR_NUMBER" \
-H "Authorization: token $GIT_TOKEN" | jq -r '.body')
# Extract version from PR title: "chore(main): release X.Y.Z"
PR_TITLE="${{ gitea.event.pull_request.title }}"
VERSION=$(echo "$PR_TITLE" | grep -oP '\d+\.\d+\.\d+')
if [ -z "$VERSION" ]; then
echo "Could not extract version from PR title: $PR_TITLE"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Strip the instruction blockquote lines (lines starting with >) from PR body
# Strip the instruction blockquote lines (lines starting with >)
CHANGELOG=$(echo "$PR_BODY" | sed '/^[[:space:]]*>/d' | sed '/^$/N;/^\n$/d')
# Save changelog for later steps
echo "$CHANGELOG" > /tmp/pr_changelog
echo "Version: $VERSION"
echo "Changelog:"
echo "Changelog from PR body:"
echo "$CHANGELOG"
- name: Update version files and CHANGELOG.md
- name: Update CHANGELOG.md with PR body text
env:
VERSION: ${{ steps.release-info.outputs.version }}
VERSION: ${{ steps.version.outputs.version }}
GIT_TOKEN: ${{ secrets.GT_TOKEN }}
run: |
CHANGELOG=$(cat /tmp/pr_changelog)
DATE=$(date +%Y-%m-%d)
# Update .release-please-manifest.json
# Replace the auto-generated changelog entry with the manually edited one
python3 << PYEOF
import json
import re
with open('.release-please-manifest.json', 'r') as f:
manifest = json.load(f)
manifest['.'] = '${VERSION}'
with open('.release-please-manifest.json', 'w') as f:
json.dump(manifest, f, indent=2)
version = "${VERSION}"
changelog = open('/tmp/pr_changelog').read().strip()
with open('CHANGELOG.md', 'r') as f:
content = f.read()
# Find and replace the section for this version
# Pattern: ## VERSION (DATE) ... until next ## or end
pattern = r'(## ' + re.escape(version) + r' \([^)]+\)\n\n).*?(?=\n## |\Z)'
replacement = r'\1' + changelog
new_content = re.sub(pattern, replacement, content, flags=re.DOTALL)
with open('CHANGELOG.md', 'w') as f:
f.write(new_content)
PYEOF
# Update .csproj version
CSPROJ="Jellyfin.Plugin.SmartNotify/Jellyfin.Plugin.SmartNotify.csproj"
sed -i "s|<AssemblyVersion>.*</AssemblyVersion>|<AssemblyVersion>${VERSION}.0</AssemblyVersion>|" "$CSPROJ"
sed -i "s|<FileVersion>.*</FileVersion>|<FileVersion>${VERSION}.0</FileVersion>|" "$CSPROJ"
# Update CHANGELOG.md - prepend new entry
CHANGELOG_ENTRY="## ${VERSION} (${DATE})
${CHANGELOG}"
if [ -f CHANGELOG.md ]; then
OLD_CHANGELOG=$(cat CHANGELOG.md | tail -n +2) # Remove "# Changelog" header
else
OLD_CHANGELOG=""
fi
cat > CHANGELOG.md << CLEOF
# Changelog
${CHANGELOG_ENTRY}
${OLD_CHANGELOG}
CLEOF
# Commit changes
# Commit updated CHANGELOG
git config user.name "Gitea Actions"
git config user.email "actions@git.tdpi.dev"
git add .release-please-manifest.json "$CSPROJ" CHANGELOG.md
git commit -m "chore(main): release ${VERSION}"
git push https://x-access-token:${{ secrets.GT_TOKEN }}@git.tdpi.dev/TDPI/jellyfin-plugin-smartnotify.git HEAD:main
git add CHANGELOG.md
git diff --cached --quiet || {
git commit -m "docs: update changelog for v${VERSION}"
git push https://x-access-token:${GIT_TOKEN}@git.tdpi.dev/TDPI/jellyfin-plugin-smartnotify.git HEAD:main
}
- name: Create Git Tag
env:
GIT_TOKEN: ${{ secrets.GT_TOKEN }}
VERSION: ${{ steps.release-info.outputs.version }}
run: |
git config user.name "Gitea Actions"
git config user.email "actions@git.tdpi.dev"
git tag -a "v${VERSION}" -m "Release v${VERSION}"
git push https://x-access-token:${GIT_TOKEN}@git.tdpi.dev/TDPI/jellyfin-plugin-smartnotify.git "v${VERSION}"
git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
git push https://x-access-token:${GIT_TOKEN}@git.tdpi.dev/TDPI/jellyfin-plugin-smartnotify.git "v${{ steps.version.outputs.version }}"
- name: Create Release
env:
GIT_TOKEN: ${{ secrets.GT_TOKEN }}
VERSION: ${{ steps.release-info.outputs.version }}
VERSION: ${{ steps.version.outputs.version }}
run: |
CHANGELOG=$(cat /tmp/pr_changelog)