115 lines
4.0 KiB
YAML
115 lines
4.0 KiB
YAML
name: Create Release
|
|
on:
|
|
pull_request:
|
|
types: [closed]
|
|
branches:
|
|
- main
|
|
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
publish-release:
|
|
name: Publish Release
|
|
if: gitea.event_name == 'pull_request' && gitea.event.pull_request.merged == true && startsWith(gitea.event.pull_request.head.ref, 'release-please')
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
token: ${{ secrets.GT_TOKEN }}
|
|
|
|
- name: Get version
|
|
id: version
|
|
run: |
|
|
VERSION=$(jq -r '."."' .release-please-manifest.json)
|
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Get changelog from PR body
|
|
id: changelog
|
|
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')
|
|
|
|
# Strip the instruction blockquote lines (lines starting with >)
|
|
CHANGELOG=$(echo "$PR_BODY" | sed '/^[[:space:]]*>/d' | sed '/^$/N;/^\n$/d')
|
|
|
|
echo "$CHANGELOG" > /tmp/pr_changelog
|
|
echo "Changelog from PR body:"
|
|
echo "$CHANGELOG"
|
|
|
|
- name: Update CHANGELOG.md with PR body text
|
|
env:
|
|
VERSION: ${{ steps.version.outputs.version }}
|
|
GIT_TOKEN: ${{ secrets.GT_TOKEN }}
|
|
run: |
|
|
CHANGELOG=$(cat /tmp/pr_changelog)
|
|
|
|
# Replace the auto-generated changelog entry with the manually edited one
|
|
python3 << PYEOF
|
|
import re
|
|
|
|
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
|
|
|
|
# Commit updated CHANGELOG
|
|
git config user.name "Gitea Actions"
|
|
git config user.email "actions@git.tdpi.dev"
|
|
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 }}
|
|
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 }}"
|
|
|
|
- name: Create Release
|
|
env:
|
|
GIT_TOKEN: ${{ secrets.GT_TOKEN }}
|
|
VERSION: ${{ steps.version.outputs.version }}
|
|
run: |
|
|
CHANGELOG=$(cat /tmp/pr_changelog)
|
|
|
|
PAYLOAD=$(jq -n \
|
|
--arg tag "v$VERSION" \
|
|
--arg name "v$VERSION" \
|
|
--arg body "$CHANGELOG" \
|
|
'{tag_name: $tag, name: $name, body: $body, draft: false, prerelease: false}')
|
|
|
|
curl -X POST "https://git.tdpi.dev/api/v1/repos/TDPI/jellyfin-plugin-smartnotify/releases" \
|
|
-H "Authorization: token $GIT_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$PAYLOAD"
|
|
|
|
- name: Cleanup Release Branch
|
|
env:
|
|
GIT_TOKEN: ${{ secrets.GT_TOKEN }}
|
|
run: |
|
|
git push --delete origin release-please--branches--main || true
|