fix: rewrite release workflow to use Gitea REST API directly (drop softprops/action-gh-release)
Release Plugins / Package & Release (push) Successful in 10s

This commit is contained in:
PickleRick committed 2026-09-19 14:07:35 +02:00
1 parent 778d6e51ed
commit 7f90b366eb
1 file changed
+97 -33
+97 -33
View File
@@ -22,10 +22,11 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
# ── Determine the release tag ─────────────────────────────────────────
- name: Determine release tag - name: Determine release tag
id: tag id: tag
run: | run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
elif [[ -n "${{ github.event.inputs.version }}" ]]; then elif [[ -n "${{ github.event.inputs.version }}" ]]; then
echo "tag=${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT" echo "tag=${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT"
@@ -33,56 +34,119 @@ jobs:
echo "tag=latest" >> "$GITHUB_OUTPUT" echo "tag=latest" >> "$GITHUB_OUTPUT"
fi fi
# ── Build ZIP archives ────────────────────────────────────────────────
- name: Create plugin ZIPs - name: Create plugin ZIPs
run: | run: |
TAG="${{ steps.tag.outputs.tag }}"
mkdir -p dist mkdir -p dist
# Full suite ZIP (all LocalFlowPlugins + FlowHelpers) # Full suite ZIP (LocalFlowPlugins + FlowHelpers)
zip -r dist/Tdarr-plugins-${{ steps.tag.outputs.tag }}.zip \ zip -r "dist/Tdarr-plugins-${TAG}.zip" \
LocalFlowPlugins/ \ LocalFlowPlugins/ \
FlowHelpers/ \ FlowHelpers/ \
-x "*.git*" -x "*.git*"
# Individual plugin ZIPs # Individual plugin ZIPs (one per plugin folder)
for dir in LocalFlowPlugins/*/*/1.0.0; do for dir in LocalFlowPlugins/*/*/1.0.0; do
plugin_name=$(echo "$dir" | awk -F'/' '{print $(NF-1)}') 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 done
echo "=== Built assets ==="
ls -lh dist/ ls -lh dist/
- name: Delete existing "latest" release (if re-releasing) # ── Gitea release via REST API ────────────────────────────────────────
if: steps.tag.outputs.tag == 'latest' # 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: env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
gh release delete latest --yes --cleanup-tag 2>/dev/null || true TAG="${{ steps.tag.outputs.tag }}"
- name: Create GitHub Release # Resolve base URL: env var → context → hardcoded fallback
uses: softprops/action-gh-release@v2 BASE_URL="${GITHUB_SERVER_URL:-${{ github.server_url }}}"
with: BASE_URL="${BASE_URL:-https://git.cdtech.freeddns.org}"
tag_name: ${{ steps.tag.outputs.tag }} REPO="${GITHUB_REPOSITORY:-${{ github.repository }}}"
name: "Tdarr Plugins ${{ steps.tag.outputs.tag }}"
body: |
## Tdarr Local Flow Plugin Suite — ${{ steps.tag.outputs.tag }}
### Installation (curl) API="${BASE_URL}/api/v1/repos/${REPO}"
AUTH="Authorization: token ${GITEA_TOKEN}"
Download the full suite: IS_PRERELEASE="false"
```bash [[ "${TAG}" == "latest" ]] && IS_PRERELEASE="true"
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/
```
Or download an individual plugin (example: `transcode2PassX265`): 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."
```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/
```
See the [README](https://github.com/${{ github.repository }}#readme) for full installation instructions. echo "=== API endpoint: ${API} ==="
files: dist/*.zip echo "=== Repo: ${REPO} ==="
prerelease: ${{ steps.tag.outputs.tag == 'latest' }}
make_latest: ${{ steps.tag.outputs.tag != 'latest' }} # ── 1. Check for existing release with this tag ──────────────────
env: echo "Looking up existing release for tag '${TAG}'..."
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 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}"