diff options
Diffstat (limited to 'Jellyfin.Versioning')
| -rw-r--r-- | Jellyfin.Versioning/AssemblyExtendedVersion.cs | 48 | ||||
| -rw-r--r-- | Jellyfin.Versioning/ExtendedVersion.cs | 133 | ||||
| -rw-r--r-- | Jellyfin.Versioning/Jellyfin.Versioning.csproj | 20 | ||||
| -rw-r--r-- | Jellyfin.Versioning/Properties/AssemblyInfo.cs | 21 | ||||
| -rw-r--r-- | Jellyfin.Versioning/SharedVersion.cs | 8 | ||||
| -rwxr-xr-x | Jellyfin.Versioning/update-version | 44 | ||||
| -rw-r--r-- | Jellyfin.Versioning/update-version.bat | 23 | ||||
| -rw-r--r-- | Jellyfin.Versioning/update-version.ps1 | 31 |
8 files changed, 328 insertions, 0 deletions
diff --git a/Jellyfin.Versioning/AssemblyExtendedVersion.cs b/Jellyfin.Versioning/AssemblyExtendedVersion.cs new file mode 100644 index 000000000..b2453fc8d --- /dev/null +++ b/Jellyfin.Versioning/AssemblyExtendedVersion.cs @@ -0,0 +1,48 @@ +// Jellyfin.Versioning/AssemblyExtendedVersion.cs +// Part of the Jellyfin project (https://jellyfin.media) +// +// All copyright belongs to the Jellyfin contributors; a full list can +// be found in the file CONTRIBUTORS.md +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; + +namespace Jellyfin.Versioning +{ + [AttributeUsage(AttributeTargets.Assembly)] + public sealed class AssemblyExtendedVersion : Attribute + { + public ExtendedVersion ExtendedVersion { get; } + + public AssemblyExtendedVersion(ExtendedVersion ExtendedVersion) + { + this.ExtendedVersion = ExtendedVersion; + } + + public AssemblyExtendedVersion(string apiVersion, bool readResource = true) + { + var assembly = Assembly.GetExecutingAssembly(); + var resourceName = "Jellyfin.Versioning.jellyfin_version.ini"; + + using (var stream = assembly.GetManifestResourceStream(resourceName)) + { + ExtendedVersion = new ExtendedVersion(new Version(apiVersion), stream); + } + } + } +} diff --git a/Jellyfin.Versioning/ExtendedVersion.cs b/Jellyfin.Versioning/ExtendedVersion.cs new file mode 100644 index 000000000..de54d3829 --- /dev/null +++ b/Jellyfin.Versioning/ExtendedVersion.cs @@ -0,0 +1,133 @@ +// Jellyfin.Versioning/ExtendedVersion.cs +// Part of the Jellyfin project (https://jellyfin.media) +// +// All copyright belongs to the Jellyfin contributors; a full list can +// be found in the file CONTRIBUTORS.md +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + + +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.Serialization; +using System.Text; + +namespace Jellyfin.Versioning +{ + public class ExtendedVersion + { + [IgnoreDataMember] + public Version ApiVersion { get; } + + public string CommitHash { get; } = String.Empty; + + public long Revision { get; } = 0; + + public string Branch { get; } = String.Empty; + + public string TagDescription { get; } = String.Empty; + + [IgnoreDataMember] + public Uri Remote { get; } = null; + + public ExtendedVersion(Version apiVersion, Stream extendedVersionFileStream) + { + ApiVersion = apiVersion; + int line = 1; + using (var reader = new StreamReader(extendedVersionFileStream)) + { + while (!reader.EndOfStream) + { + string item = reader.ReadLine(); + + if (string.IsNullOrWhiteSpace(item.Trim())) + { + //empty line, skip + continue; + } + var kvpair = item.Split('='); + if (kvpair.Length != 2) + { + throw new ArgumentException(nameof(extendedVersionFileStream), + $"ExtendedVersionFile contains bad key-value pair '{item}' at line {line}."); + } + var key = kvpair[0].Trim().ToLower(); + var value = kvpair[1].Trim(); + switch (key) + { + case "commit": + if (value.Length < 7 || value.Length > 40) + { + throw new ArgumentException(nameof(extendedVersionFileStream), + $"ExtendedVersionFile has a bad commit hash '{value}' on line {line}, it should be a string between 7 and 40 characters."); + } + CommitHash = value; + break; + case "branch": + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException(nameof(extendedVersionFileStream), + $"ExtendedVersionFile has a bad branch '{value}' on line {line}, it can not be empty."); + } + Branch = value; + break; + case "revision": + if (!long.TryParse(value, out long rev)) + { + throw new ArgumentException(nameof(extendedVersionFileStream), + $"ExtendedVersionFile has a bad revision '{value}' on line {line}, it should be an integer."); + } + Revision = rev; + break; + case "tagdesc": + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException(nameof(extendedVersionFileStream), + $"ExtendedVersionFile has a bad tag description '{value}' on line {line}, it can not be empty."); + } + TagDescription = value; + break; + case "remote": + var remoteRepo = value.Replace(".git", string.Empty).Replace("git@github.com:", "https://github.com/"); + if (Uri.IsWellFormedUriString(remoteRepo, UriKind.Absolute)) + { + Remote = new Uri(remoteRepo); + } + else if (Uri.IsWellFormedUriString(value, UriKind.Absolute)) + { + //fallback if the replace about broke the Uri + Remote = new Uri(value); + } + else + { + throw new ArgumentException(nameof(extendedVersionFileStream), + $"ExtendedVersionFile has a bad remote URI '{value}' on line {line}, it should be a valid remote URI (ssh or https)."); + } + break; + default: + throw new ArgumentException(nameof(extendedVersionFileStream), + $"ExtendedVersionFile contains an unrecognized key-value pair '{item}' at line {line}."); + } + line++; + } + } + } + + public override string ToString() + { + return $"{ApiVersion};{CommitHash};{Revision};{Branch};{TagDescription};{Remote}"; + } + } +} diff --git a/Jellyfin.Versioning/Jellyfin.Versioning.csproj b/Jellyfin.Versioning/Jellyfin.Versioning.csproj new file mode 100644 index 000000000..8dc45dde1 --- /dev/null +++ b/Jellyfin.Versioning/Jellyfin.Versioning.csproj @@ -0,0 +1,20 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>netstandard2.0</TargetFramework> + <GenerateAssemblyInfo>false</GenerateAssemblyInfo> + </PropertyGroup> + + <ItemGroup> + <None Remove="jellyfin_version.ini" /> + </ItemGroup> + + <ItemGroup> + <EmbeddedResource Include="jellyfin_version.ini" /> + </ItemGroup> + + <Target Name="PreBuild" BeforeTargets="PreBuildEvent"> + <Exec Command="$(ProjectDir)update-version" /> + </Target> + +</Project> diff --git a/Jellyfin.Versioning/Properties/AssemblyInfo.cs b/Jellyfin.Versioning/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..5ccba7ad5 --- /dev/null +++ b/Jellyfin.Versioning/Properties/AssemblyInfo.cs @@ -0,0 +1,21 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Jellyfin.Versioning")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Jellyfin Project")] +[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")] +[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: NeutralResourcesLanguage("en")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] diff --git a/Jellyfin.Versioning/SharedVersion.cs b/Jellyfin.Versioning/SharedVersion.cs new file mode 100644 index 000000000..574a852e4 --- /dev/null +++ b/Jellyfin.Versioning/SharedVersion.cs @@ -0,0 +1,8 @@ +using System.Reflection; +using Jellyfin.Versioning; + +//To keep compatibility with Emby do not remove the revision (fourth number) +[assembly: AssemblyVersion("10.0.1.0")] +[assembly: AssemblyFileVersion("10.0.1.0")] +[assembly: AssemblyInformationalVersion("10.0.1.0")] +[assembly: AssemblyExtendedVersion("3.5.2.0", true)] diff --git a/Jellyfin.Versioning/update-version b/Jellyfin.Versioning/update-version new file mode 100755 index 000000000..e8d4fab6d --- /dev/null +++ b/Jellyfin.Versioning/update-version @@ -0,0 +1,44 @@ +#!/usr/bin/env sh +# Jellyfin.Versioning/update-version +# Part of the Jellyfin project (https://jellyfin.media) +# +# All copyright belongs to the Jellyfin contributors; a full list can +# be found in the file CONTRIBUTORS.md +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +if [ -d "$(dirname "$0")/../.git" ]; then + commit=`git rev-parse HEAD` + count=`git rev-list HEAD --count` + branch=`git rev-parse --abbrev-ref HEAD` + desc=`git describe --tags --always --long` + remote=`git config --get remote.origin.url` + tee jellyfin_version.ini <<EOF +commit=$commit +revision=$count +branch=$branch +tagdesc=$desc +remote=$remote +EOF + cat <<EOF +Updated build version in jellyfin_version.ini +commit=$commit +revision=$count +branch=$branch +tagdesc=$desc +remote=$remote +EOF +else + echo Did not update build version because there was no .git directory. +fi diff --git a/Jellyfin.Versioning/update-version.bat b/Jellyfin.Versioning/update-version.bat new file mode 100644 index 000000000..709867ba7 --- /dev/null +++ b/Jellyfin.Versioning/update-version.bat @@ -0,0 +1,23 @@ +@ECHO OFF +goto licenseblock +update-version.bat +Part of the Jellyfin project (https://jellyfin.media) + + All copyright belongs to the Jellyfin contributors; a full list can + be found in the file CONTRIBUTORS.md + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. +:licenseblock + +powershell.exe -executionpolicy Bypass -file update-version.ps1
\ No newline at end of file diff --git a/Jellyfin.Versioning/update-version.ps1 b/Jellyfin.Versioning/update-version.ps1 new file mode 100644 index 000000000..2f9f0cf7b --- /dev/null +++ b/Jellyfin.Versioning/update-version.ps1 @@ -0,0 +1,31 @@ +# Jellyfin.Versioning/update-version.ps1 +# Part of the Jellyfin project (https://jellyfin.media) +# +# All copyright belongs to the Jellyfin contributors; a full list can +# be found in the file CONTRIBUTORS.md +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +if(Test-Path -Path '..\.git' ){ + $commit = (git rev-parse HEAD) + $count = (git rev-list HEAD --count) + $branch = (git rev-parse --abbrev-ref HEAD) + $desc = (git describe --tags --always --long) + $remote = (git config --get remote.origin.url) + Set-Content -Path "jellyfin_version.ini" -Value "commit=$commit`r`nrevision=$count`r`nbranch=$branch`r`ntagdesc=$desc`r`nremote=$remote" + Write-Host Updated build version in jellyfin_version.ini + Write-Host "commit=$commit`r`nrevision=$count`r`nbranch=$branch`r`ntagdesc=$desc`r`nremote=$remote`r`n" +} else { + Write-Host Did not update build version because there was no .git directory. +}
\ No newline at end of file |
