From 82d732a59504651c91f4cf43778249a7ae686386 Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Wed, 18 Nov 2020 20:56:24 +0100 Subject: [PATCH 1/7] Modernise for newer target frameworks - Target newer frameworks including net5 and netstandard2.1 for greater compatibility - Include symbols package - Use License Expression - Add Package References for reference assemblies for NET Framework - Add SourceLink - Add GitVersion Properties - Use GitHub Actions - Remove legacy global.json - Remove .travis.yml - Remove Dockerfile - Remove Makefile as it was only used for docker tests --- .github/workflows/ci.yml | 66 ++++++++++++++++++++++++++ .travis.yml | 7 --- src/ByteSizeLib.sln => ByteSizeLib.sln | 6 +-- Dockerfile | 27 ----------- Makefile | 28 ----------- global.json | 8 ---- src/ByteSizeLib/ByteSizeLib.csproj | 42 ++++++++++++---- 7 files changed, 102 insertions(+), 82 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml rename src/ByteSizeLib.sln => ByteSizeLib.sln (93%) delete mode 100644 Dockerfile delete mode 100644 Makefile delete mode 100644 global.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b99472b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,66 @@ +name: DotNet + +on: + pull_request: + branches: + - master + push: + branches: + - master + release: + types: [published] + +jobs: + test: + runs-on: ubuntu-latest + name: Build + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - uses: actions/cache@v2 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-nuget- + + - name: Setup dotnet + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '3.1' + + - name: Setup dotnet + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '5.0' + + - name: Install GitVersion + run: dotnet tool install -g GitVersion.Tool + + - name: GitVersion + run: dotnet gitversion /l console /output buildserver + + - name: DotNet Build + shell: pwsh + run: | + dotnet restore + dotnet build --no-restore + dotnet build --configuration Release --no-restore + dotnet pack --configuration Release --no-restore --no-build + + - name: DotNet Test + shell: pwsh + run: | + dotnet test --no-build --no-restore + + - name: Push NuGet + if: | + github.event.action == 'published' + shell: pwsh + run: dotnet nuget push **/*.nupkg --source $Env:SOURCE --api-key $Env:TOKEN + env: + SOURCE: 'https://api.nuget.org/v3/index.json' + TOKEN: ${{ secrets.NUGET_API_KEY }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index dbdaaf9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -langauge: generic - -services: - - docker - -script: - - make test-in-docker diff --git a/src/ByteSizeLib.sln b/ByteSizeLib.sln similarity index 93% rename from src/ByteSizeLib.sln rename to ByteSizeLib.sln index 0c13f7b..d180747 100644 --- a/src/ByteSizeLib.sln +++ b/ByteSizeLib.sln @@ -2,9 +2,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26124.0 MinimumVisualStudioVersion = 15.0.26124.0 -Project("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC") = "ByteSizeLib", "ByteSizeLib\ByteSizeLib.csproj", "{7B49A533-D1CE-4826-926B-10187E7C45F6}" +Project("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC") = "ByteSizeLib", "src\ByteSizeLib\ByteSizeLib.csproj", "{7B49A533-D1CE-4826-926B-10187E7C45F6}" EndProject -Project("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC") = "ByteSizeLib.Tests", "ByteSizeLib.Tests\ByteSizeLib.Tests.csproj", "{C676A686-F1B5-48CB-90B3-B1F78FA42691}" +Project("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC") = "ByteSizeLib.Tests", "src\ByteSizeLib.Tests\ByteSizeLib.Tests.csproj", "{C676A686-F1B5-48CB-90B3-B1F78FA42691}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -44,4 +44,4 @@ Global {C676A686-F1B5-48CB-90B3-B1F78FA42691}.Release|x86.ActiveCfg = Release|Any CPU {C676A686-F1B5-48CB-90B3-B1F78FA42691}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection -EndGlobal \ No newline at end of file +EndGlobal diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index a8a939e..0000000 --- a/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -# Adapted from https://github.com/andrewlock/docker-dotnet-mono/blob/master/Dockerfile -FROM mcr.microsoft.com/dotnet/core/sdk:2.1.700 AS builder - -# Install mono -ENV MONO_VERSION 5.18.0.225 - -RUN apt-get update \ - && apt-get install -y --no-install-recommends gnupg dirmngr \ - && rm -rf /var/lib/apt/lists/* \ - && export GNUPGHOME="$(mktemp -d)" \ - && gpg --batch --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \ - && gpg --batch --export --armor 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF > /etc/apt/trusted.gpg.d/mono.gpg.asc \ - && gpgconf --kill all \ - && rm -rf "$GNUPGHOME" \ - && apt-key list | grep Xamarin \ - && apt-get purge -y --auto-remove gnupg dirmngr - -RUN echo "deb http://download.mono-project.com/repo/debian stable-stretch/snapshots/$MONO_VERSION main" > /etc/apt/sources.list.d/mono-official-stable.list \ - && apt-get update \ - && apt-get install -y mono-runtime \ - && rm -rf /var/lib/apt/lists/* /tmp/* - -RUN apt-get update \ - && apt-get install -y binutils curl mono-devel ca-certificates-mono fsharp mono-vbnc nuget referenceassemblies-pcl \ - && rm -rf /var/lib/apt/lists/* /tmp/* - -WORKDIR /sln \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 34cd919..0000000 --- a/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -.PHONY: build test pack - -# Check to see if Mono exists. If it does, use that path to build against .NET 4.5 -ifneq ("$(wildcard /usr/local/lib/mono/)","") - # MONO_REFERENCE_ASSEMBLIES is automatically pulled in ByteSizeLib.csproj - # to allow building against .NET Framework on a Mac where I do most of my - # development. - export MONO_REFERENCE_ASSEMBLIES=/usr/local/lib/mono -endif - -build: - dotnet build src - -test: - dotnet test src - -pack: - dotnet pack src/ByteSizeLib -c Release -o pack - -test-in-docker: - # Stop and delete conatiner if already exists - docker stop bytesize || true && docker rm bytesize || true - # Use an image with both Mono and .NET Core SDK installed so we can build - # against .NET Framework 4.5 - docker build -t bytesize-build . - docker run -td --name bytesize -v $(CURDIR):/bytesize bytesize-build - docker exec bytesize bash -c "cd /bytesize/src && msbuild -t:restore ByteSizeLib.sln" - docker exec bytesize bash -c "cd /bytesize/src && dotnet test ByteSizeLib.Tests" diff --git a/global.json b/global.json deleted file mode 100644 index c6c08c9..0000000 --- a/global.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "projects": [ - "src" - ], - "sdk": { - "version": "2.1.700" - } -} diff --git a/src/ByteSizeLib/ByteSizeLib.csproj b/src/ByteSizeLib/ByteSizeLib.csproj index 3cb0121..d205a3f 100755 --- a/src/ByteSizeLib/ByteSizeLib.csproj +++ b/src/ByteSizeLib/ByteSizeLib.csproj @@ -5,20 +5,17 @@ ByteSize is a utility class that makes byte size representation in code easier by removing ambiguity of the value being represented. ByteSize is to bytes what System.TimeSpan is to time. Copyright © Omar Khudeira 2013-2020 ByteSize - 2.0.0 - 2.0.0 Omar Khudeira - netstandard1.0;net45 + net5.0;netstandard2.1;netstandard2.0;net45 true - portable ByteSize ByteSize bytes **HUGE BREAKING CHANGE**: -By default `ByteSize` now assumes `1 KB == 1000 B` and `1 KiB == 1024 B` to -adhere to the IEC and NIST standards (https://en.wikipedia.org/wiki/Binary_prefix). +By default `ByteSize` now assumes `1 KB == 1000 B` and `1 KiB == 1024 B` to +adhere to the IEC and NIST standards (https://en.wikipedia.org/wiki/Binary_prefix). In the past `ByteSize` assumed `1 KB == 1024 B`, that means if you're upgrading from v1, you'll see differences in values. @@ -35,14 +32,41 @@ New Features: View all release notes at https://github.com/omar/ByteSize/releases. https://github.com/omar/ByteSize - https://raw.githubusercontent.com/omar/ByteSize/master/LICENSE git https://github.com/omar/ByteSize en + MIT + true + true + snupkg - - $(MONO_REFERENCE_ASSEMBLIES)/4.5-api + + true + true + + + + + + + + false + false + false + + $(GitVersion_FullSemVer) + $(GitVersion_MajorMinorPatch) + $(GitVersion_NuGetPreReleaseTag) + $(GitVersion_PreReleaseTag) + $(GitVersion_NuGetVersion) + $(GitVersion_FullSemVer) + $(GitVersion_InformationalVersion) + $(GitVersion_AssemblySemVer) + $(GitVersion_AssemblySemFileVer) + $(GitVersion_BranchName) + $(GitVersion_Sha) + From a60c9d6b427faf05b21220d9580f62d1be276c59 Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Wed, 18 Nov 2020 21:43:00 +0100 Subject: [PATCH 2/7] Let Visual Studio update the solution file --- ByteSizeLib.sln | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ByteSizeLib.sln b/ByteSizeLib.sln index d180747..47b9388 100644 --- a/ByteSizeLib.sln +++ b/ByteSizeLib.sln @@ -1,10 +1,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26124.0 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30709.64 MinimumVisualStudioVersion = 15.0.26124.0 -Project("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC") = "ByteSizeLib", "src\ByteSizeLib\ByteSizeLib.csproj", "{7B49A533-D1CE-4826-926B-10187E7C45F6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ByteSizeLib", "src\ByteSizeLib\ByteSizeLib.csproj", "{7B49A533-D1CE-4826-926B-10187E7C45F6}" EndProject -Project("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC") = "ByteSizeLib.Tests", "src\ByteSizeLib.Tests\ByteSizeLib.Tests.csproj", "{C676A686-F1B5-48CB-90B3-B1F78FA42691}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ByteSizeLib.Tests", "src\ByteSizeLib.Tests\ByteSizeLib.Tests.csproj", "{C676A686-F1B5-48CB-90B3-B1F78FA42691}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,9 +15,6 @@ Global Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {7B49A533-D1CE-4826-926B-10187E7C45F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7B49A533-D1CE-4826-926B-10187E7C45F6}.Debug|Any CPU.Build.0 = Debug|Any CPU @@ -44,4 +41,10 @@ Global {C676A686-F1B5-48CB-90B3-B1F78FA42691}.Release|x86.ActiveCfg = Release|Any CPU {C676A686-F1B5-48CB-90B3-B1F78FA42691}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E3DAEEF5-8A32-45AA-B3FA-DCE6A079997E} + EndGlobalSection EndGlobal From f6ed05b7126b7820200124cb8dc92058a015b958 Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Wed, 18 Nov 2020 21:43:22 +0100 Subject: [PATCH 3/7] add .vs/ and .idea/ to git ignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 19398a8..823e3a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # use glob syntax syntax: glob +.vs/ +.idea/ *.userprefs *.obj *.pdb From ebd21f8783932ab73cd66d48c05896b18ccb80e9 Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Wed, 18 Nov 2020 21:55:52 +0100 Subject: [PATCH 4/7] Add support for culture info in ToBinaryString noted that test failed on my machine using danish culture info --- .../Binary/ToBinaryStringMethod.cs | 17 ++++++++++++++++- src/ByteSizeLib.Tests/ByteSizeLib.Tests.csproj | 9 ++++----- src/ByteSizeLib.Tests/ParsingMethods.cs | 18 +++++++++++++++--- src/ByteSizeLib/BinaryByteSize.cs | 5 +++++ 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/ByteSizeLib.Tests/Binary/ToBinaryStringMethod.cs b/src/ByteSizeLib.Tests/Binary/ToBinaryStringMethod.cs index 3fc2cbe..072361d 100644 --- a/src/ByteSizeLib.Tests/Binary/ToBinaryStringMethod.cs +++ b/src/ByteSizeLib.Tests/Binary/ToBinaryStringMethod.cs @@ -1,3 +1,4 @@ +using System.Globalization; using Xunit; namespace ByteSizeLib.Tests.BinaryByteSizeTests @@ -12,10 +13,24 @@ public void ReturnsDefaultRepresenation() var b = ByteSize.FromKiloBytes(10); // Act - var result = b.ToBinaryString(); + var result = b.ToBinaryString(CultureInfo.InvariantCulture); // Assert Assert.Equal("9.77 KiB", result); } + + [Fact] + public void ReturnsDefaultRepresenationCurrentCulture() + { + // Arrange + var b = ByteSize.FromKiloBytes(10); + var s = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator; + + // Act + var result = b.ToBinaryString(CultureInfo.CurrentCulture); + + // Assert + Assert.Equal($"9{s}77 KiB", result); + } } } diff --git a/src/ByteSizeLib.Tests/ByteSizeLib.Tests.csproj b/src/ByteSizeLib.Tests/ByteSizeLib.Tests.csproj index e5a5676..cffd256 100755 --- a/src/ByteSizeLib.Tests/ByteSizeLib.Tests.csproj +++ b/src/ByteSizeLib.Tests/ByteSizeLib.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1 + netcoreapp3.1 false @@ -11,10 +11,9 @@ - - - - + + + diff --git a/src/ByteSizeLib.Tests/ParsingMethods.cs b/src/ByteSizeLib.Tests/ParsingMethods.cs index a8d4e50..d2e863e 100644 --- a/src/ByteSizeLib.Tests/ParsingMethods.cs +++ b/src/ByteSizeLib.Tests/ParsingMethods.cs @@ -98,10 +98,22 @@ public void ParsePartialBits() Assert.Throws(() => { - ByteSize.Parse(val); + ByteSize.Parse(val, CultureInfo.InvariantCulture); }); } + [Fact] + public void ParsePartialBitsCurrentCulture() + { + var s = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator; + string val = $"10{s}5b"; + + Assert.Throws(() => + { + ByteSize.Parse(val, CultureInfo.CurrentCulture); + }); + } + // Parse method throws exceptions [Fact] public void ParseThrowsOnInvalid() @@ -130,7 +142,7 @@ public void ParseBits() { string val = "1b"; var expected = ByteSize.FromBits(1); - + var result = ByteSize.Parse(val); Assert.Equal(expected, result); @@ -157,7 +169,7 @@ public void ParseCultureNumberSeparator() var result = ByteSize.Parse(val); Assert.Equal(expected, result); - + CultureInfo.CurrentCulture = new CultureInfo("en-US"); } diff --git a/src/ByteSizeLib/BinaryByteSize.cs b/src/ByteSizeLib/BinaryByteSize.cs index dd13efa..1d3adad 100644 --- a/src/ByteSizeLib/BinaryByteSize.cs +++ b/src/ByteSizeLib/BinaryByteSize.cs @@ -77,5 +77,10 @@ public string ToBinaryString() { return this.ToString("0.##", CultureInfo.CurrentCulture, useBinaryByte: true); } + + public string ToBinaryString(IFormatProvider formatProvider) + { + return this.ToString("0.##", formatProvider, useBinaryByte: true); + } } } From b2f7afc4e47da19f9a10d837c2c9860c36eeeeaa Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Wed, 18 Nov 2020 21:59:19 +0100 Subject: [PATCH 5/7] let test project target net 5 --- src/ByteSizeLib.Tests/ByteSizeLib.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ByteSizeLib.Tests/ByteSizeLib.Tests.csproj b/src/ByteSizeLib.Tests/ByteSizeLib.Tests.csproj index cffd256..34d2a8f 100755 --- a/src/ByteSizeLib.Tests/ByteSizeLib.Tests.csproj +++ b/src/ByteSizeLib.Tests/ByteSizeLib.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net5.0 false From 878b6d2c08c828fd8e641065e81876f4cf3bc35e Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sun, 13 Dec 2020 18:17:29 +0100 Subject: [PATCH 6/7] continue to target netstandard1.0 --- src/ByteSizeLib/ByteSizeLib.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ByteSizeLib/ByteSizeLib.csproj b/src/ByteSizeLib/ByteSizeLib.csproj index d205a3f..19318ef 100755 --- a/src/ByteSizeLib/ByteSizeLib.csproj +++ b/src/ByteSizeLib/ByteSizeLib.csproj @@ -6,7 +6,7 @@ Copyright © Omar Khudeira 2013-2020 ByteSize Omar Khudeira - net5.0;netstandard2.1;netstandard2.0;net45 + netstandard1.0;netstandard2.1;netstandard2.0;net45;net5.0; true ByteSize ByteSize From c1a98a57cf9d5cf6a8193d28857d56db1f454786 Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sun, 13 Dec 2020 18:24:33 +0100 Subject: [PATCH 7/7] use default branch macro --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b99472b..c52a290 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,10 +3,10 @@ name: DotNet on: pull_request: branches: - - master + - $default-branch push: branches: - - master + - $default-branch release: types: [published]