test jellyfin plugin, would be nice

This commit is contained in:
2026-08-22 22:00:28 +02:00
parent 7d6405c776
commit 4baee3fafe
23 changed files with 1713 additions and 1 deletions
@@ -0,0 +1,174 @@
name: Release Jellyfin plugin
on:
push:
tags:
- "jellyfin/*/v*"
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Parse tag
id: meta
run: |
set -euo pipefail
TAG="${GITHUB_REF_NAME}"
# jellyfin/<plugin-slug>/v1.2.3
if [[ ! "$TAG" =~ ^jellyfin/([a-z0-9-]+)/v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
echo "Tag must match jellyfin/<plugin-slug>/vX.Y.Z (got: $TAG)"
exit 1
fi
SLUG="${BASH_REMATCH[1]}"
VERSION="${BASH_REMATCH[2]}"
PLUGIN_DIR="Jellyfin/${SLUG}"
if [[ ! -f "${PLUGIN_DIR}/build.yaml" ]]; then
echo "Missing ${PLUGIN_DIR}/build.yaml"
exit 1
fi
echo "slug=${SLUG}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "plugin_dir=${PLUGIN_DIR}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version4=${VERSION}.0" >> "$GITHUB_OUTPUT"
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.0.x"
- name: Install jprm
run: |
python3 -m venv /tmp/jprm-venv
/tmp/jprm-venv/bin/pip install --upgrade pip jprm
- name: Build plugin package
id: build
run: |
set -euo pipefail
PLUGIN_DIR="${{ steps.meta.outputs.plugin_dir }}"
mkdir -p "${PLUGIN_DIR}/artifacts"
sed -i -E "s/^version:.*/version: \"${{ steps.meta.outputs.version4 }}\"/" "${PLUGIN_DIR}/build.yaml"
/tmp/jprm-venv/bin/jprm --verbosity=info plugin build "${PLUGIN_DIR}" --output "${PLUGIN_DIR}/artifacts"
ARTIFACT=$(find "${PLUGIN_DIR}/artifacts" -type f -name '*.zip' | head -n1)
if [[ -z "$ARTIFACT" ]]; then
echo "No zip produced by jprm"
ls -laR "${PLUGIN_DIR}/artifacts" || true
exit 1
fi
NAME=$(basename "$ARTIFACT")
CHECKSUM=$(sha256sum "$ARTIFACT" | awk '{print $1}')
echo "artifact=${ARTIFACT}" >> "$GITHUB_OUTPUT"
echo "artifact_name=${NAME}" >> "$GITHUB_OUTPUT"
echo "checksum=${CHECKSUM}" >> "$GITHUB_OUTPUT"
echo "Built ${NAME} sha256=${CHECKSUM}"
- name: Create Gitea release and upload asset
id: release
env:
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
GITEA_URL="${{ github.server_url }}"
REPO_OWNER="${{ github.repository_owner }}"
REPO_NAME="${{ github.event.repository.name }}"
TAG="${{ steps.meta.outputs.tag }}"
VERSION="${{ steps.meta.outputs.version }}"
SLUG="${{ steps.meta.outputs.slug }}"
ARTIFACT="${{ steps.build.outputs.artifact }}"
ARTIFACT_NAME="${{ steps.build.outputs.artifact_name }}"
BODY=$(printf 'Jellyfin plugin **%s** %s\n\nAdd the raw Jellyfin/manifest.json URL from this repo as a plugin repository.' \
"$SLUG" "$VERSION")
BODY_JSON=$(printf '%s' "$BODY" | jq -Rs .)
RESPONSE=$(curl -sS -w "\n%{http_code}" -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
"${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases" \
-d "{
\"tag_name\": \"${TAG}\",
\"name\": \"${SLUG} ${VERSION}\",
\"body\": ${BODY_JSON},
\"draft\": false,
\"prerelease\": false
}")
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
RESP_BODY=$(echo "$RESPONSE" | sed '$d')
if [[ "$HTTP_CODE" != "201" && "$HTTP_CODE" != "200" ]]; then
echo "Failed to create release: HTTP $HTTP_CODE"
echo "$RESP_BODY"
exit 1
fi
RELEASE_ID=$(echo "$RESP_BODY" | jq -r '.id')
echo "release_id=${RELEASE_ID}" >> "$GITHUB_OUTPUT"
curl -sS -f -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/zip" \
--data-binary "@${ARTIFACT}" \
"${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases/${RELEASE_ID}/assets?name=${ARTIFACT_NAME}"
DOWNLOAD_URL="${GITEA_URL}/${REPO_OWNER}/${REPO_NAME}/releases/download/${TAG}/${ARTIFACT_NAME}"
echo "download_url=${DOWNLOAD_URL}" >> "$GITHUB_OUTPUT"
- name: Update Jellyfin/manifest.json
env:
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
SLUG="${{ steps.meta.outputs.slug }}"
VERSION="${{ steps.meta.outputs.version4 }}"
CHECKSUM="${{ steps.build.outputs.checksum }}"
DOWNLOAD_URL="${{ steps.release.outputs.download_url }}"
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
PLUGIN_DIR="${{ steps.meta.outputs.plugin_dir }}"
GUID=$(grep -E '^guid:' "${PLUGIN_DIR}/build.yaml" | head -1 | sed -E 's/guid:[[:space:]]*"?([^"]*)"?/\1/')
TARGET_ABI=$(grep -E '^targetAbi:' "${PLUGIN_DIR}/build.yaml" | head -1 | sed -E 's/targetAbi:[[:space:]]*"?([^"]*)"?/\1/')
NEW_VERSION=$(jq -n \
--arg version "$VERSION" \
--arg changelog "Release ${VERSION}" \
--arg targetAbi "$TARGET_ABI" \
--arg sourceUrl "$DOWNLOAD_URL" \
--arg checksum "$CHECKSUM" \
--arg timestamp "$TIMESTAMP" \
'{
version: $version,
changelog: $changelog,
targetAbi: $targetAbi,
sourceUrl: $sourceUrl,
checksum: $checksum,
timestamp: $timestamp
}')
jq --arg guid "$GUID" --argjson newver "$NEW_VERSION" '
map(if .guid == $guid then .versions = ([$newver] + (.versions // [])) else . end)
' Jellyfin/manifest.json > Jellyfin/manifest.json.tmp
mv Jellyfin/manifest.json.tmp Jellyfin/manifest.json
git config user.name "gitea-actions"
git config user.email "actions@local"
# Detach from tag checkout: update default branch
DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
git fetch origin "$DEFAULT_BRANCH"
git checkout -B "$DEFAULT_BRANCH" "origin/${DEFAULT_BRANCH}"
# Re-apply manifest change if checkout overwrote
jq --arg guid "$GUID" --argjson newver "$NEW_VERSION" '
map(if .guid == $guid then .versions = ([$newver] + (.versions // [])) else . end)
' Jellyfin/manifest.json > Jellyfin/manifest.json.tmp
mv Jellyfin/manifest.json.tmp Jellyfin/manifest.json
git add Jellyfin/manifest.json
if git diff --staged --quiet; then
echo "Manifest already up to date"
exit 0
fi
git commit -m "chore(jellyfin): publish ${SLUG} ${VERSION} to catalog"
git push origin "$DEFAULT_BRANCH"
@@ -0,0 +1,149 @@
name: Scaffold Jellyfin plugin
on:
workflow_dispatch:
inputs:
plugin_slug:
description: "Directory name under Jellyfin/ (e.g. jellyfin-plugin-myfeature)"
required: true
type: string
plugin_name:
description: "Display name in Jellyfin"
required: true
type: string
overview:
description: "Short overview"
required: false
default: "Jellyfin plugin"
type: string
description:
description: "Longer description"
required: false
default: "Jellyfin plugin scaffolded from template"
type: string
jobs:
scaffold:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Create plugin from template
env:
PLUGIN_SLUG: ${{ inputs.plugin_slug }}
PLUGIN_NAME: ${{ inputs.plugin_name }}
PLUGIN_OVERVIEW: ${{ inputs.overview }}
PLUGIN_DESCRIPTION: ${{ inputs.description }}
run: |
set -euo pipefail
SLUG="${PLUGIN_SLUG}"
if [[ ! "$SLUG" =~ ^[a-z0-9][a-z0-9-]*$ ]]; then
echo "plugin_slug must be lowercase alphanumeric/hyphen"
exit 1
fi
TARGET="Jellyfin/${SLUG}"
if [[ -e "$TARGET" ]]; then
echo "Target already exists: $TARGET"
exit 1
fi
# PascalCase assembly from slug: jellyfin-plugin-foo-bar -> Jellyfin.Plugin.FooBar
PASCAL=$(echo "$SLUG" | sed -E 's/^jellyfin-plugin-//; s/^jellyfin-//' | awk -F'-' '{
out="Jellyfin.Plugin"
for (i=1; i<=NF; i++) {
if ($i == "") continue
w=toupper(substr($i,1,1)) substr($i,2)
out=out "." w
}
print out
}')
ASSEMBLY="$PASCAL"
NAMESPACE="$PASCAL"
PAGE_ID=$(echo "$PASCAL" | tr -d '.')
GUID=$(cat /proc/sys/kernel/random/uuid)
mkdir -p "${TARGET}/${ASSEMBLY}/Configuration"
replace() {
local src="$1"
local dst="$2"
sed -e "s/{{PLUGIN_SLUG}}/${SLUG}/g" \
-e "s/{{PLUGIN_NAME}}/${PLUGIN_NAME}/g" \
-e "s/{{PLUGIN_OVERVIEW}}/${PLUGIN_OVERVIEW}/g" \
-e "s/{{PLUGIN_DESCRIPTION}}/${PLUGIN_DESCRIPTION}/g" \
-e "s/{{PLUGIN_GUID}}/${GUID}/g" \
-e "s/{{ASSEMBLY_NAME}}/${ASSEMBLY}/g" \
-e "s/{{NAMESPACE}}/${NAMESPACE}/g" \
-e "s/{{PAGE_ID}}/${PAGE_ID}/g" \
"$src" > "$dst"
}
replace Jellyfin/_template/build.yaml.template "${TARGET}/build.yaml"
replace Jellyfin/_template/README.md.template "${TARGET}/README.md"
replace Jellyfin/_template/Plugin/Plugin.csproj.template "${TARGET}/${ASSEMBLY}/${ASSEMBLY}.csproj"
replace Jellyfin/_template/Plugin/Plugin.cs.template "${TARGET}/${ASSEMBLY}/Plugin.cs"
replace Jellyfin/_template/Plugin/Configuration/PluginConfiguration.cs.template \
"${TARGET}/${ASSEMBLY}/Configuration/PluginConfiguration.cs"
replace Jellyfin/_template/Plugin/Configuration/configPage.html.template \
"${TARGET}/${ASSEMBLY}/Configuration/configPage.html"
cat > "${TARGET}/${ASSEMBLY}.sln" <<EOF
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "${ASSEMBLY}", "${ASSEMBLY}/${ASSEMBLY}.csproj", "{${GUID}}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{${GUID}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{${GUID}}.Debug|Any CPU.Build.0 = Debug|Any CPU
{${GUID}}.Release|Any CPU.ActiveCfg = Release|Any CPU
{${GUID}}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
EOF
# Fix accidental leading spaces in generated sln from heredoc
sed -i 's/^ //' "${TARGET}/${ASSEMBLY}.sln"
# Append to aggregated catalog if missing
if ! jq -e --arg g "$GUID" 'map(select(.guid == $g)) | length > 0' Jellyfin/manifest.json >/dev/null; then
jq --arg guid "$GUID" \
--arg name "$PLUGIN_NAME" \
--arg desc "$PLUGIN_DESCRIPTION" \
--arg overview "$PLUGIN_OVERVIEW" \
'. + [{
guid: $guid,
name: $name,
description: $desc,
overview: $overview,
owner: "bram",
category: "General",
versions: []
}]' Jellyfin/manifest.json > Jellyfin/manifest.json.tmp
mv Jellyfin/manifest.json.tmp Jellyfin/manifest.json
fi
echo "Created ${TARGET}"
echo "guid=${GUID}" >> "$GITHUB_OUTPUT"
echo "assembly=${ASSEMBLY}" >> "$GITHUB_OUTPUT"
- name: Commit and push
run: |
set -euo pipefail
git config user.name "gitea-actions"
git config user.email "actions@local"
git add Jellyfin/
if git diff --staged --quiet; then
echo "Nothing to commit"
exit 0
fi
git commit -m "chore(jellyfin): scaffold ${{ inputs.plugin_slug }}"
git push