diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 35e2130..d2e5410 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,10 +22,11 @@ jobs: - name: Checkout uses: actions/checkout@v4 + # ── Determine the release tag ───────────────────────────────────────── - name: Determine release tag id: tag run: | - if [[ "${{ github.ref }}" == refs/tags/* ]]; then + 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" @@ -33,56 +34,119 @@ jobs: 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 (all LocalFlowPlugins + FlowHelpers) - zip -r dist/Tdarr-plugins-${{ steps.tag.outputs.tag }}.zip \ + # Full suite ZIP (LocalFlowPlugins + FlowHelpers) + zip -r "dist/Tdarr-plugins-${TAG}.zip" \ LocalFlowPlugins/ \ FlowHelpers/ \ -x "*.git*" - # Individual plugin ZIPs + # 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}-${{ steps.tag.outputs.tag }}.zip" "$dir/index.js" + zip -j "dist/${plugin_name}-${TAG}.zip" "$dir/index.js" done + echo "=== Built assets ===" ls -lh dist/ - - name: Delete existing "latest" release (if re-releasing) - if: steps.tag.outputs.tag == 'latest' + # ── 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: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh release delete latest --yes --cleanup-tag 2>/dev/null || true + TAG="${{ steps.tag.outputs.tag }}" - - name: Create GitHub Release - uses: softprops/action-gh-release@v2 - with: - tag_name: ${{ steps.tag.outputs.tag }} - name: "Tdarr Plugins ${{ steps.tag.outputs.tag }}" - body: | - ## Tdarr Local Flow Plugin Suite — ${{ 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 }}}" - ### Installation (curl) + API="${BASE_URL}/api/v1/repos/${REPO}" + AUTH="Authorization: token ${GITEA_TOKEN}" - Download the full suite: - ```bash - curl -L https://github.com/${{ github.repository }}/releases/download/${{ steps.tag.outputs.tag }}/Tdarr-plugins-${{ steps.tag.outputs.tag }}.zip -o plugins.zip - unzip plugins.zip -d /path/to/tdarr/plugins/ - ``` + IS_PRERELEASE="false" + [[ "${TAG}" == "latest" ]] && IS_PRERELEASE="true" - Or download an individual plugin (example: `transcode2PassX265`): - ```bash - curl -L https://github.com/${{ github.repository }}/releases/download/${{ steps.tag.outputs.tag }}/transcode2PassX265-${{ steps.tag.outputs.tag }}.zip -o transcode2PassX265.zip - unzip transcode2PassX265.zip -d /path/to/tdarr/plugins/LocalFlowPlugins/video/transcode2PassX265/1.0.0/ - ``` + 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." - See the [README](https://github.com/${{ github.repository }}#readme) for full installation instructions. - files: dist/*.zip - prerelease: ${{ steps.tag.outputs.tag == 'latest' }} - make_latest: ${{ steps.tag.outputs.tag != 'latest' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + 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}"