153 lines
6.4 KiB
YAML
153 lines
6.4 KiB
YAML
name: Release Plugins
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- 'v*'
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
description: 'Release version (e.g. v1.0.1). Leave blank to use the tag or "latest".'
|
|
required: false
|
|
default: ''
|
|
|
|
jobs:
|
|
release:
|
|
name: Package & Release
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
# ── Determine the release tag ─────────────────────────────────────────
|
|
- name: Determine release tag
|
|
id: tag
|
|
run: |
|
|
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
|
|
echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
|
|
elif [[ -n "${{ github.event.inputs.version }}" ]]; then
|
|
echo "tag=${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "tag=latest" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
# ── Build ZIP archives ────────────────────────────────────────────────
|
|
- name: Create plugin ZIPs
|
|
run: |
|
|
TAG="${{ steps.tag.outputs.tag }}"
|
|
mkdir -p dist
|
|
|
|
# Full suite ZIP (LocalFlowPlugins + FlowHelpers)
|
|
zip -r "dist/Tdarr-plugins-${TAG}.zip" \
|
|
LocalFlowPlugins/ \
|
|
FlowHelpers/ \
|
|
-x "*.git*"
|
|
|
|
# Individual plugin ZIPs (one per plugin folder)
|
|
for dir in LocalFlowPlugins/*/*/1.0.0; do
|
|
plugin_name=$(echo "$dir" | awk -F'/' '{print $(NF-1)}')
|
|
zip -j "dist/${plugin_name}-${TAG}.zip" "$dir/index.js"
|
|
done
|
|
|
|
echo "=== Built assets ==="
|
|
ls -lh dist/
|
|
|
|
# ── Gitea release via REST API ────────────────────────────────────────
|
|
# github.server_url can be empty on some self-hosted runners, so we
|
|
# derive it from GITHUB_SERVER_URL env var with a hardcoded fallback.
|
|
- name: Publish Gitea release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
TAG="${{ steps.tag.outputs.tag }}"
|
|
|
|
# Resolve base URL: env var → context → hardcoded fallback
|
|
BASE_URL="${GITHUB_SERVER_URL:-${{ github.server_url }}}"
|
|
BASE_URL="${BASE_URL:-https://git.cdtech.freeddns.org}"
|
|
REPO="${GITHUB_REPOSITORY:-${{ github.repository }}}"
|
|
|
|
API="${BASE_URL}/api/v1/repos/${REPO}"
|
|
AUTH="Authorization: token ${GITEA_TOKEN}"
|
|
|
|
IS_PRERELEASE="false"
|
|
[[ "${TAG}" == "latest" ]] && IS_PRERELEASE="true"
|
|
|
|
RELEASE_BODY="## Tdarr Plugins ${TAG}\n\nInstall the full suite:\n\`\`\`bash\ncurl -fsSL ${BASE_URL}/${REPO}/archive/main.zip -o /tmp/tp.zip\nunzip -q -o /tmp/tp.zip -d /tmp/tpx\ncp -r /tmp/tpx/Tdarr-plugin/LocalFlowPlugins \${PLUGIN_DIR}/\ncp -r /tmp/tpx/Tdarr-plugin/FlowHelpers \${PLUGIN_DIR}/\nrm -rf /tmp/tp.zip /tmp/tpx\n\`\`\`\n\nSee [README](${BASE_URL}/${REPO}) for full docs."
|
|
|
|
echo "=== API endpoint: ${API} ==="
|
|
echo "=== Repo: ${REPO} ==="
|
|
|
|
# ── 1. Check for existing release with this tag ──────────────────
|
|
echo "Looking up existing release for tag '${TAG}'..."
|
|
EXISTING=$(curl -sf -H "$AUTH" "${API}/releases/tags/${TAG}" 2>/dev/null || echo "")
|
|
RELEASE_ID=$(echo "$EXISTING" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('id',''))" 2>/dev/null || true)
|
|
|
|
if [[ -n "$RELEASE_ID" ]]; then
|
|
echo "Found release id=${RELEASE_ID} — removing old assets..."
|
|
|
|
# Delete all existing assets
|
|
ASSETS=$(curl -sf -H "$AUTH" "${API}/releases/${RELEASE_ID}/assets" || echo "[]")
|
|
echo "$ASSETS" | python3 -c "
|
|
import sys, json
|
|
assets = json.load(sys.stdin)
|
|
for a in assets:
|
|
print(a['id'])
|
|
" 2>/dev/null | while read -r asset_id; do
|
|
echo " Deleting asset id=${asset_id}"
|
|
curl -sf -X DELETE -H "$AUTH" "${API}/releases/${RELEASE_ID}/assets/${asset_id}" \
|
|
&& echo " ✓ deleted" || echo " ✗ delete failed (ignored)"
|
|
done
|
|
|
|
# Patch release name/body
|
|
curl -sf -X PATCH -H "$AUTH" -H "Content-Type: application/json" \
|
|
"${API}/releases/${RELEASE_ID}" \
|
|
-d "{\"name\":\"Tdarr Plugins ${TAG}\",\"body\":\"${RELEASE_BODY}\",\"prerelease\":${IS_PRERELEASE}}" \
|
|
> /dev/null && echo "Release updated."
|
|
|
|
else
|
|
echo "No existing release — creating one..."
|
|
|
|
# Ensure the lightweight tag exists on the repo
|
|
git tag "${TAG}" 2>/dev/null || echo "Tag already exists."
|
|
git push origin "${TAG}" 2>/dev/null || echo "Tag push skipped (may already exist)."
|
|
|
|
RESPONSE=$(curl -sf -X POST -H "$AUTH" -H "Content-Type: application/json" \
|
|
"${API}/releases" \
|
|
-d "{
|
|
\"tag_name\": \"${TAG}\",
|
|
\"name\": \"Tdarr Plugins ${TAG}\",
|
|
\"body\": \"${RELEASE_BODY}\",
|
|
\"prerelease\": ${IS_PRERELEASE},
|
|
\"draft\": false
|
|
}")
|
|
|
|
RELEASE_ID=$(echo "$RESPONSE" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('id',''))" 2>/dev/null || true)
|
|
echo "Created release id=${RELEASE_ID}"
|
|
fi
|
|
|
|
if [[ -z "$RELEASE_ID" ]]; then
|
|
echo "ERROR: Could not determine release ID. Aborting asset upload."
|
|
exit 1
|
|
fi
|
|
|
|
# ── 2. Upload all assets ─────────────────────────────────────────
|
|
echo ""
|
|
echo "Uploading assets to release id=${RELEASE_ID}..."
|
|
for asset in dist/*.zip; do
|
|
filename=$(basename "$asset")
|
|
echo " Uploading ${filename}..."
|
|
curl -sf -X POST \
|
|
-H "$AUTH" \
|
|
-F "attachment=@${asset};type=application/zip" \
|
|
"${API}/releases/${RELEASE_ID}/assets?name=${filename}" \
|
|
> /dev/null \
|
|
&& echo " ✓ ${filename}" \
|
|
|| { echo " ✗ Failed: ${filename}"; exit 1; }
|
|
done
|
|
|
|
echo ""
|
|
echo "✅ Release complete: ${BASE_URL}/${REPO}/releases/tag/${TAG}"
|