test jellyfin plugin, would be nice
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user