Add packaging script

This commit is contained in:
ConfusedPolarBear 2022-07-27 21:30:57 -05:00
parent bb4397cc22
commit 8e6a5d8e80
5 changed files with 116 additions and 20 deletions

61
.github/workflows/package.sh vendored Executable file
View File

@ -0,0 +1,61 @@
#!/bin/bash
# Check argument count
if [[ $# -ne 1 ]]; then
echo "Usage: $0 VERSION"
exit 1
fi
# Use provided tag to derive archive filename and short tag
version="$1"
zip="intro-skipper-$version.zip"
short="$(echo "$version" | sed "s/^v//")"
# Get the assembly version
CSPROJ="ConfusedPolarBear.Plugin.IntroSkipper/ConfusedPolarBear.Plugin.IntroSkipper.csproj"
assemblyVersion="$(grep -m1 -oE "([0-9]\.){3}[0-9]" "$CSPROJ")"
# Get the date
date="$(date --utc -Iseconds | sed "s/\+00:00/Z/")"
# Debug
echo "Version: $version ($short)"
echo "Archive: $zip"
echo
echo "Running unit tests"
dotnet test -p:DefineConstants=SKIP_FFMPEG_TESTS || exit 1
echo
echo "Building plugin in Release mode"
dotnet build -c Release || exit 1
echo
# Create packaging directory
mkdir package
cd package || exit 1
# Copy the freshly built plugin DLL to the packaging directory and archive
cp "../ConfusedPolarBear.Plugin.IntroSkipper/bin/Release/net6.0/ConfusedPolarBear.Plugin.IntroSkipper.dll" ./ || exit 1
zip "$zip" ConfusedPolarBear.Plugin.IntroSkipper.dll || exit 1
# Calculate the checksum of the archive
checksum="$(md5sum "$zip" | cut -f 1 -d " ")"
# Generate the manifest entry for this plugin
cat > manifest.json <<'EOF'
{
"version": "ASSEMBLY",
"changelog": "- See the full changelog at [GitHub](https://github.com/ConfusedPolarBear/intro-skipper/blob/master/CHANGELOG.md)\n",
"targetAbi": "10.8.1.0",
"sourceUrl": "https://github.com/ConfusedPolarBear/intro-skipper/releases/download/VERSION/ZIP",
"checksum": "CHECKSUM",
"timestamp": "DATE"
}
EOF
sed -i "s/ASSEMBLY/$assemblyVersion/" manifest.json
sed -i "s/VERSION/$version/" manifest.json
sed -i "s/ZIP/$zip/" manifest.json
sed -i "s/CHECKSUM/$checksum/" manifest.json
sed -i "s/DATE/$date/" manifest.json

43
.github/workflows/publish.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: 'Package plugin'
on:
workflow_dispatch:
jobs:
build:
# 18.04 = bionic LTS, supported until April 2023
runs-on: ubuntu-18.04
steps:
# set fetch-depth to 0 in order to clone all tags instead of just the current commit
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Checkout latest tag
id: tag
run: |
tag="$(git tag --sort=committerdate | tail -n 1)"
git checkout "$tag"
echo "::set-output name=tag::$tag"
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Package
run: .github/workflows/package.sh ${{ steps.tag.outputs.tag }}
- name: Upload plugin archive
uses: actions/upload-artifact@v3.1.0
with:
name: intro-skipper-bundle-${{ steps.tag.outputs.tag }}.zip
path: |
package/*.zip
package/*.json
if-no-files-found: error

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
bin/ bin/
obj/ obj/
BenchmarkDotNet.Artifacts/ BenchmarkDotNet.Artifacts/
/package/
# Ignore pre compiled web interface # Ignore pre compiled web interface
docker/dist docker/dist

View File

@ -3,7 +3,6 @@
*/ */
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using Xunit; using Xunit;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -11,7 +10,7 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper.Tests;
public class TestAudioFingerprinting public class TestAudioFingerprinting
{ {
[Fact] [FactSkipFFmpegTests]
public void TestInstallationCheck() public void TestInstallationCheck()
{ {
Assert.True(Chromaprint.CheckFFmpegVersion()); Assert.True(Chromaprint.CheckFFmpegVersion());
@ -29,7 +28,7 @@ public class TestAudioFingerprinting
Assert.Equal(expectedBits, FingerprinterTask.CountBits(number)); Assert.Equal(expectedBits, FingerprinterTask.CountBits(number));
} }
[Fact] [FactSkipFFmpegTests]
public void TestFingerprinting() public void TestFingerprinting()
{ {
// Generated with `fpcalc -raw audio/big_buck_bunny_intro.mp3` // Generated with `fpcalc -raw audio/big_buck_bunny_intro.mp3`
@ -83,7 +82,7 @@ public class TestAudioFingerprinting
Assert.Equal(expected, actual); Assert.Equal(expected, actual);
} }
[Fact] [FactSkipFFmpegTests]
public void TestIntroDetection() public void TestIntroDetection()
{ {
var task = new FingerprinterTask(new LoggerFactory()); var task = new FingerprinterTask(new LoggerFactory());
@ -111,3 +110,11 @@ public class TestAudioFingerprinting
}; };
} }
} }
public class FactSkipFFmpegTests : FactAttribute {
#if SKIP_FFMPEG_TESTS
public FactSkipFFmpegTests() {
Skip = "SKIP_FFMPEG_TESTS defined, skipping unit tests that require FFmpeg to be installed";
}
#endif
}

View File

@ -1,16 +0,0 @@
---
name: "Template"
guid: "eb5d7894-8eef-4b36-aa6f-5d124e828ce1"
version: "1.0.0.0"
targetAbi: "10.7.0.0"
framework: "net5.0"
overview: "Short description about your plugin"
description: >
This is a longer description that can span more than one
line and include details about your plugin.
category: "General"
owner: "jellyfin"
artifacts:
- "ConfusedPolarBear.Plugin.IntroSkipper.dll"
changelog: >
changelog