feat: own changelog
All checks were successful
Create Release PR / Create Release PR (push) Successful in 11s
All checks were successful
Create Release PR / Create Release PR (push) Successful in 11s
This commit is contained in:
@@ -26,19 +26,19 @@ jobs:
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install gitpython packaging
|
||||
pip install packaging
|
||||
|
||||
- name: Create Release PR
|
||||
env:
|
||||
GIT_TOKEN: ${{ secrets.GT_TOKEN }}
|
||||
REPO: "TDPI/jellyfin-plugin-smartnotify"
|
||||
run: |
|
||||
python3 << 'EOF'
|
||||
python3 << 'PYEOF'
|
||||
import re
|
||||
import subprocess
|
||||
import json
|
||||
from packaging import version as pkg_version
|
||||
|
||||
|
||||
def get_commits_since_last_tag():
|
||||
try:
|
||||
last_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0'], text=True).strip()
|
||||
@@ -46,14 +46,14 @@ jobs:
|
||||
except:
|
||||
commits = subprocess.check_output(['git', 'log', '--pretty=format:%s'], text=True).strip().split('\n')
|
||||
return [c for c in commits if c]
|
||||
|
||||
|
||||
def analyze_commits(commits):
|
||||
has_feat = any(c.startswith('feat') for c in commits)
|
||||
has_fix = any(c.startswith('fix') for c in commits)
|
||||
has_breaking = any('!' in c.split(':')[0] or 'BREAKING CHANGE' in c for c in commits)
|
||||
has_chore = any(c.startswith('chore') for c in commits)
|
||||
return has_breaking, has_feat, has_fix, has_chore
|
||||
|
||||
|
||||
def get_current_version():
|
||||
try:
|
||||
with open('.release-please-manifest.json', 'r') as f:
|
||||
@@ -61,11 +61,11 @@ jobs:
|
||||
return manifest.get('.', '1.0.0')
|
||||
except:
|
||||
return '1.0.0'
|
||||
|
||||
|
||||
def bump_version(current, has_breaking, has_feat, has_fix, has_chore):
|
||||
v = pkg_version.parse(current)
|
||||
major, minor, patch = v.major, v.minor, v.micro
|
||||
|
||||
|
||||
if has_breaking:
|
||||
return f'{major + 1}.0.0'
|
||||
elif has_feat:
|
||||
@@ -73,130 +73,118 @@ jobs:
|
||||
elif has_fix or has_chore:
|
||||
return f'{major}.{minor}.{patch + 1}'
|
||||
return None
|
||||
|
||||
|
||||
commits = get_commits_since_last_tag()
|
||||
if not commits or commits == ['']:
|
||||
print('No commits to release')
|
||||
exit(0)
|
||||
|
||||
|
||||
has_breaking, has_feat, has_fix, has_chore = analyze_commits(commits)
|
||||
|
||||
if not (has_breaking or has_feat or has_fix or has_chore):
|
||||
print('No release-worthy commits')
|
||||
exit(0)
|
||||
|
||||
|
||||
current_version = get_current_version()
|
||||
new_version = bump_version(current_version, has_breaking, has_feat, has_fix, has_chore)
|
||||
|
||||
|
||||
if not new_version:
|
||||
print('No version bump needed')
|
||||
exit(0)
|
||||
|
||||
|
||||
print(f'Bumping version from {current_version} to {new_version}')
|
||||
|
||||
# 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'
|
||||
|
||||
|
||||
# Build changelog content for PR body (template for manual editing)
|
||||
changelog_body = ''
|
||||
|
||||
if has_breaking:
|
||||
changelog_entry += '### BREAKING CHANGES\n\n'
|
||||
changelog_body += '### BREAKING CHANGES\n\n'
|
||||
for c in commits:
|
||||
if '!' in c.split(':')[0] or 'BREAKING CHANGE' in c:
|
||||
changelog_entry += f'* {c}\n'
|
||||
changelog_entry += '\n'
|
||||
|
||||
changelog_body += f'* {c}\n'
|
||||
changelog_body += '\n'
|
||||
|
||||
if has_feat:
|
||||
changelog_entry += '### Features\n\n'
|
||||
changelog_body += '### Features\n\n'
|
||||
for c in commits:
|
||||
if c.startswith('feat'):
|
||||
changelog_entry += f'* {c}\n'
|
||||
changelog_entry += '\n'
|
||||
changelog_body += f'* {c}\n'
|
||||
changelog_body += '\n'
|
||||
|
||||
if has_fix:
|
||||
changelog_entry += '### Bug Fixes\n\n'
|
||||
changelog_body += '### Bug Fixes\n\n'
|
||||
for c in commits:
|
||||
if c.startswith('fix'):
|
||||
changelog_entry += f'* {c}\n'
|
||||
changelog_entry += '\n'
|
||||
changelog_body += f'* {c}\n'
|
||||
changelog_body += '\n'
|
||||
|
||||
if has_chore:
|
||||
changelog_entry += '### Chores\n\n'
|
||||
changelog_body += '### Chores\n\n'
|
||||
for c in commits:
|
||||
if c.startswith('chore'):
|
||||
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}'])
|
||||
|
||||
changelog_body += f'* {c}\n'
|
||||
changelog_body += '\n'
|
||||
|
||||
# Write version and changelog to temp files for shell script
|
||||
with open('/tmp/new_version', 'w') as f:
|
||||
f.write(new_version)
|
||||
EOF
|
||||
|
||||
|
||||
with open('/tmp/changelog_body', 'w') as f:
|
||||
f.write(changelog_body.strip())
|
||||
|
||||
PYEOF
|
||||
|
||||
NEW_VERSION=$(cat /tmp/new_version 2>/dev/null || echo "")
|
||||
if [ -z "$NEW_VERSION" ]; then
|
||||
echo "No version bump needed"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
BRANCH_NAME="release-please--branches--main"
|
||||
|
||||
# Push changes
|
||||
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.
|
||||
|
||||
## ${NEW_VERSION}
|
||||
|
||||
${CHANGELOG_BODY}
|
||||
BODYEOF
|
||||
)
|
||||
|
||||
PR_BODY_JSON=$(echo "$PR_BODY" | jq -Rs .)
|
||||
|
||||
# Check if branch already exists
|
||||
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
|
||||
|
||||
# Get changelog content for PR body
|
||||
CHANGELOG_CONTENT=$(awk '/^## '"$NEW_VERSION"'/{flag=1} /^## / && flag && !/^## '"$NEW_VERSION"'/{exit} flag' CHANGELOG.md | jq -Rs .)
|
||||
|
||||
if [ "$PR_EXISTS" = true ]; then
|
||||
|
||||
# Update existing PR
|
||||
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" ]; then
|
||||
|
||||
if [ "$PR_NUMBER" != "null" ] && [ -n "$PR_NUMBER" ]; 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" \
|
||||
-d "{
|
||||
\"title\": \"chore(main): release $NEW_VERSION\",
|
||||
\"body\": $CHANGELOG_CONTENT
|
||||
\"body\": $PR_BODY_JSON
|
||||
}"
|
||||
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" \
|
||||
@@ -204,6 +192,6 @@ jobs:
|
||||
\"title\": \"chore(main): release $NEW_VERSION\",
|
||||
\"head\": \"$BRANCH_NAME\",
|
||||
\"base\": \"main\",
|
||||
\"body\": $CHANGELOG_CONTENT
|
||||
\"body\": $PR_BODY_JSON
|
||||
}"
|
||||
fi
|
||||
|
||||
@@ -20,27 +20,111 @@ jobs:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GT_TOKEN }}
|
||||
|
||||
- name: Get version
|
||||
id: version
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
VERSION=$(jq -r '."."' .release-please-manifest.json)
|
||||
pip install packaging
|
||||
|
||||
- name: Extract version and changelog from PR
|
||||
id: release-info
|
||||
env:
|
||||
GIT_TOKEN: ${{ secrets.GT_TOKEN }}
|
||||
REPO: "TDPI/jellyfin-plugin-smartnotify"
|
||||
PR_NUMBER: ${{ gitea.event.pull_request.number }}
|
||||
run: |
|
||||
# Get PR body (the manually edited changelog)
|
||||
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
|
||||
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"
|
||||
|
||||
- name: Update version files and CHANGELOG.md
|
||||
env:
|
||||
VERSION: ${{ steps.release-info.outputs.version }}
|
||||
run: |
|
||||
CHANGELOG=$(cat /tmp/pr_changelog)
|
||||
DATE=$(date +%Y-%m-%d)
|
||||
|
||||
# Update .release-please-manifest.json
|
||||
python3 << PYEOF
|
||||
import json
|
||||
|
||||
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)
|
||||
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
|
||||
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
|
||||
|
||||
- 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${{ 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 }}"
|
||||
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}"
|
||||
|
||||
- name: Create Release
|
||||
env:
|
||||
GIT_TOKEN: ${{ secrets.GT_TOKEN }}
|
||||
VERSION: ${{ steps.version.outputs.version }}
|
||||
VERSION: ${{ steps.release-info.outputs.version }}
|
||||
run: |
|
||||
CHANGELOG=$(awk '/^## '"$VERSION"'/{flag=1} /^## / && flag && !/^## '"$VERSION"'/{exit} flag' CHANGELOG.md)
|
||||
CHANGELOG=$(cat /tmp/pr_changelog)
|
||||
|
||||
PAYLOAD=$(jq -n \
|
||||
--arg tag "v$VERSION" \
|
||||
|
||||
Reference in New Issue
Block a user