From 8e6a5d8e80dbb9110e9404ae1a118b32890581f6 Mon Sep 17 00:00:00 2001 From: ConfusedPolarBear <33811686+ConfusedPolarBear@users.noreply.github.com> Date: Wed, 27 Jul 2022 21:30:57 -0500 Subject: [PATCH] Add packaging script --- .github/workflows/package.sh | 61 +++++++++++++++++++ .github/workflows/publish.yml | 43 +++++++++++++ .gitignore | 1 + .../TestAudioFingerprinting.cs | 15 +++-- build.yaml | 16 ----- 5 files changed, 116 insertions(+), 20 deletions(-) create mode 100755 .github/workflows/package.sh create mode 100644 .github/workflows/publish.yml delete mode 100644 build.yaml diff --git a/.github/workflows/package.sh b/.github/workflows/package.sh new file mode 100755 index 0000000..49e3e52 --- /dev/null +++ b/.github/workflows/package.sh @@ -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 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..796c575 --- /dev/null +++ b/.github/workflows/publish.yml @@ -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 diff --git a/.gitignore b/.gitignore index cafeae8..3722249 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ bin/ obj/ BenchmarkDotNet.Artifacts/ +/package/ # Ignore pre compiled web interface docker/dist diff --git a/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestAudioFingerprinting.cs b/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestAudioFingerprinting.cs index 528984b..91ece56 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestAudioFingerprinting.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestAudioFingerprinting.cs @@ -3,7 +3,6 @@ */ using System.Collections.Generic; -using System.Collections.ObjectModel; using Xunit; using Microsoft.Extensions.Logging; @@ -11,7 +10,7 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper.Tests; public class TestAudioFingerprinting { - [Fact] + [FactSkipFFmpegTests] public void TestInstallationCheck() { Assert.True(Chromaprint.CheckFFmpegVersion()); @@ -29,7 +28,7 @@ public class TestAudioFingerprinting Assert.Equal(expectedBits, FingerprinterTask.CountBits(number)); } - [Fact] + [FactSkipFFmpegTests] public void TestFingerprinting() { // Generated with `fpcalc -raw audio/big_buck_bunny_intro.mp3` @@ -83,7 +82,7 @@ public class TestAudioFingerprinting Assert.Equal(expected, actual); } - [Fact] + [FactSkipFFmpegTests] public void TestIntroDetection() { 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 +} diff --git a/build.yaml b/build.yaml deleted file mode 100644 index c0d39fa..0000000 --- a/build.yaml +++ /dev/null @@ -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