Jellyfin-AutoBackup/.gitea/workflows/publish.yml

198 lines
7.4 KiB
YAML

name: Publish Release
on:
push:
tags:
- 'v*'
jobs:
build-net9:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
9.0.x
10.0.x
- name: Build and package (net9.0 / Jellyfin 10.x)
run: |
VER="${GITHUB_REF_NAME#v}"
dotnet publish AutoBackup.csproj -f net9.0 -c Release \
-p:Version=${VER} -p:AssemblyVersion=${VER} -p:FileVersion=${VER} \
-o publish/net9
zip -j "autobackup-net9.zip" publish/net9/Jellyfin.Plugin.AutoBackup.dll
- uses: actions/upload-artifact@v3
with:
name: build-net9
path: autobackup-net9.zip
build-net10:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
9.0.x
10.0.x
- name: Build and package (net10.0 / Jellyfin 12.x)
run: |
VER="${GITHUB_REF_NAME#v}"
dotnet publish AutoBackup.csproj -f net10.0 -c Release \
-p:Version=${VER} -p:AssemblyVersion=${VER} -p:FileVersion=${VER} \
-o publish/net10
zip -j "autobackup-net10.zip" publish/net10/Jellyfin.Plugin.AutoBackup.dll
- uses: actions/upload-artifact@v3
with:
name: build-net10
path: autobackup-net10.zip
release:
runs-on: ubuntu-latest
needs: [build-net9, build-net10]
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changelog from commit message
run: |
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
git log -1 --format="%B" "${{ github.sha }}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Rename artifacts
run: |
VER="${GITHUB_REF_NAME#v}"
mv artifacts/build-net9/autobackup-net9.zip "artifacts/build-net9/Jellyfin-AutoBackup-${VER}-10.11.x.zip"
mv artifacts/build-net10/autobackup-net10.zip "artifacts/build-net10/Jellyfin-AutoBackup-${VER}-12.0.x.zip"
- name: Update manifest.json
run: |
VER="${GITHUB_REF_NAME#v}"
export VER
export BASE_URL="${{ github.server_url }}/${{ github.repository }}/releases/download/${{ github.ref_name }}"
export TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
export NET9_MD5=$(md5sum "artifacts/build-net9/Jellyfin-AutoBackup-${VER}-10.11.x.zip" | cut -d' ' -f1)
export NET10_MD5=$(md5sum "artifacts/build-net10/Jellyfin-AutoBackup-${VER}-12.0.x.zip" | cut -d' ' -f1)
python3 - <<'PYEOF'
import json, os
ver = os.environ['VER']
base_url = os.environ['BASE_URL']
timestamp = os.environ['TIMESTAMP']
net9_md5 = os.environ['NET9_MD5']
net10_md5 = os.environ['NET10_MD5']
changelog = os.environ.get('CHANGELOG', '').strip()
guid = '1175543c-6d20-4cfa-93a6-1476836df34c'
with open('manifest.json') as f:
manifest = json.load(f)
plugin = next((p for p in manifest if p['guid'] == guid), None)
if not plugin:
plugin = {
'guid': guid,
'name': 'Auto Backup',
'description': 'Automated scheduled ZIP backups of Jellyfin data.',
'overview': 'Automated scheduled ZIP backups of Jellyfin data.',
'owner': 'Filtik',
'category': 'General',
'imageUrl': 'https://gitea.home.filtik.de/Filtik/Jellyfin-AutoBackup/raw/branch/main/images/logo.png',
'versions': []
}
manifest.append(plugin)
plugin['versions'] = [v for v in plugin['versions'] if v['version'] != ver]
plugin['versions'].insert(0, {
'version': ver, 'changelog': changelog, 'targetAbi': '12.0.0.0',
'sourceUrl': f'{base_url}/Jellyfin-AutoBackup-{ver}-12.0.x.zip',
'checksum': net10_md5, 'timestamp': timestamp
})
plugin['versions'].insert(0, {
'version': ver, 'changelog': changelog, 'targetAbi': '10.11.0.0',
'sourceUrl': f'{base_url}/Jellyfin-AutoBackup-{ver}-10.11.x.zip',
'checksum': net9_md5, 'timestamp': timestamp
})
with open('manifest.json', 'w') as f:
json.dump(manifest, f, indent=4)
print('manifest.json updated')
PYEOF
env:
CHANGELOG: ${{ env.CHANGELOG }}
- name: Commit manifest.json
run: |
git config user.name "gitea-actions"
git config user.email "actions@noreply.local"
cp manifest.json /tmp/manifest_updated.json
git fetch origin main
git checkout -f main
git pull --rebase origin main
cp /tmp/manifest_updated.json manifest.json
git add manifest.json
git diff --staged --quiet || git commit -m "chore: update manifest for ${{ github.ref_name }}"
git push origin main
- name: Create release and upload assets
run: |
API="${{ github.server_url }}/api/v1"
REPO="${{ github.repository }}"
TAG="${{ github.ref_name }}"
TOKEN="${{ secrets.GITHUB_TOKEN }}"
VER="${GITHUB_REF_NAME#v}"
BODY=$(python3 -c "import sys,json,os; print(json.dumps(os.environ.get('CHANGELOG','').strip()))")
# Delete existing release if present
EXISTING=$(curl -s "${API}/repos/${REPO}/releases/tags/${TAG}" \
-H "Authorization: token ${TOKEN}")
EXISTING_ID=$(echo "${EXISTING}" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('id',''))" 2>/dev/null || true)
if [ -n "${EXISTING_ID}" ]; then
echo "Deleting existing release ${EXISTING_ID}..."
curl -s -X DELETE "${API}/repos/${REPO}/releases/${EXISTING_ID}" \
-H "Authorization: token ${TOKEN}"
fi
# Create fresh release
RELEASE=$(curl -s -X POST "${API}/repos/${REPO}/releases" \
-H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"body\":${BODY}}")
RELEASE_ID=$(echo "${RELEASE}" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")
echo "Release ID: ${RELEASE_ID}"
# Upload assets
for file in \
"artifacts/build-net9/Jellyfin-AutoBackup-${VER}-10.11.x.zip" \
"artifacts/build-net10/Jellyfin-AutoBackup-${VER}-12.0.x.zip"; do
NAME=$(basename "${file}")
echo "Uploading ${NAME}..."
HTTP_CODE=$(curl -s -o /tmp/upload_response.json -w "%{http_code}" \
-X POST "${API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${NAME}" \
-H "Authorization: token ${TOKEN}" \
-F "attachment=@${file};type=application/zip")
echo "HTTP ${HTTP_CODE}: $(cat /tmp/upload_response.json)"
if [ "${HTTP_CODE}" != "201" ]; then
echo "Failed to upload ${NAME}" && exit 1
fi
done
env:
CHANGELOG: ${{ env.CHANGELOG }}