diff --git a/.editorconfig b/.editorconfig index 92cbdb1d6..5b84cc53b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -33,3 +33,7 @@ indent_size = 2 end_of_line = lf [*.{cmd, bat}] end_of_line = crlf + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/on-push.yml b/.github/workflows/on-push.yml new file mode 100644 index 000000000..45a56e0d1 --- /dev/null +++ b/.github/workflows/on-push.yml @@ -0,0 +1,79 @@ +name: Build master on push + +env: + PUBLISH_DEV_PACKS: disabled + +on: + push: + branches: [ master ] + +jobs: + BuildAndTest: + runs-on: ${{ matrix.os }}-latest + strategy: + fail-fast: false + matrix: + configuration: [debug, release] + os: [ubuntu, windows, macos] + libtarget: [netstandard2] + testtarget: [netcoreapp3.1] + include: + - configuration: debug + os: windows + libtarget: net45 + testtarget: net45 + - configuration: release + os: windows + libtarget: net45 + testtarget: net45 + steps: + - uses: actions/checkout@v2 + + - name: Setup .NET Core + if: matrix.libtarget == 'netstandard2' + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '3.1.x' + + - name: Build library + run: dotnet build -c ${{ matrix.configuration }} -f ${{ matrix.libtarget }} src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj + + - name: Restore test dependencies + run: dotnet restore + + - name: Run tests + run: dotnet test -c ${{ matrix.configuration }} -f ${{ matrix.testtarget }} --no-restore + + + Package: + if: env.PUBLISH_DEV_PACKS != 'disabled' + needs: [BuildAndTest] + runs-on: windows-latest + env: + NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '3.1.x' + source-url: https://nuget.pkg.github.com/icsharpcode/index.json + + - name: Build library for .NET Standard 2 + run: dotnet build -c Release -f netstandard2 src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj + - name: Build library for .NET Framework 4.5 + run: dotnet build -c Release -f net45 src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj + + - name: Create nuget package + run: dotnet pack src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj --configuration Release --output dist /p:Version=$(git describe --abbrev | % { $_.substring(1) }) + + - name: Show package name + run: ls dist\*.nupkg + + - name: Publish the package to GPR + if: env.PUBLISH_DEV_PACKS == 'enabled' + run: dotnet nuget push dist\*.nupkg diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 000000000..72f6556d2 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,93 @@ +name: Build and Test PR + +on: + pull_request: + branches: [ master ] + +jobs: + Build: + runs-on: ${{ matrix.os }}-latest + strategy: + fail-fast: false + matrix: + configuration: [debug, release] + os: [ubuntu, windows, macos] + target: [netstandard2] + include: + - configuration: Debug + os: windows + target: net45 + - configuration: Release + os: windows + target: net45 + steps: + - uses: actions/checkout@v2 + + - name: Setup .NET Core + if: matrix.target == 'netstandard2' + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '3.1.x' + + - name: Build library + run: dotnet build -c ${{ matrix.configuration }} -f ${{ matrix.target }} src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj + + Test: + runs-on: ${{ matrix.os }}-latest + strategy: + fail-fast: false + matrix: + configuration: [debug, release] + os: [ubuntu, windows, macos] + target: [netcoreapp3.1] + include: + - configuration: debug + os: windows + target: net45 + - configuration: release + os: windows + target: net45 + steps: + - uses: actions/checkout@v2 + + - name: Setup .NET Core + if: matrix.target == 'netcoreapp3.1' + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '3.1.x' + + - name: Restore test dependencies + run: dotnet restore + + - name: Run tests + run: dotnet test -c ${{ matrix.configuration }} -f ${{ matrix.target }} --no-restore + + Pack: + needs: [Build, Test] + runs-on: windows-latest + env: + NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '3.1.x' + + - name: Build library for .NET Standard 2 + run: dotnet build -c Release -f netstandard2 src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj + - name: Build library for .NET Framework 4.5 + run: dotnet build -c Release -f net45 src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj + + - name: Create nuget package + run: dotnet pack src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj --configuration Release --output dist /p:Version=$(git describe --abbrev | % { $_.substring(1) })-PR + + - name: Upload nuget package artifact + uses: actions/upload-artifact@v2 + with: + name: Nuget package + path: dist/*.nupkg diff --git a/appveyor.yml b/appveyor.yml index a6197ff29..df3ffb4ba 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,5 @@ version: '{build}' -image: Visual Studio 2017 +image: Visual Studio 2019 configuration: - Debug - Release @@ -31,4 +31,4 @@ test_script: artifacts: - path: docs\help\_site type: zip - name: Documentation \ No newline at end of file + name: Documentation diff --git a/test/ICSharpCode.SharpZipLib.Tests/ICSharpCode.SharpZipLib.Tests.csproj b/test/ICSharpCode.SharpZipLib.Tests/ICSharpCode.SharpZipLib.Tests.csproj index fa214385c..bf9e5b926 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/ICSharpCode.SharpZipLib.Tests.csproj +++ b/test/ICSharpCode.SharpZipLib.Tests/ICSharpCode.SharpZipLib.Tests.csproj @@ -2,7 +2,7 @@ Library - netcoreapp2.0;net46 + netcoreapp3.1;net46 diff --git a/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipEntryFactoryHandling.cs b/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipEntryFactoryHandling.cs index c1ba17f64..5a892abde 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipEntryFactoryHandling.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipEntryFactoryHandling.cs @@ -87,99 +87,181 @@ public void CreateInMemoryValues() [Test] [Category("Zip")] [Category("CreatesTempFile")] - public void CreatedValues() + [Platform("Win32NT")] + public void CreatedFileEntriesUsesExpectedAttributes() { string tempDir = GetTempFilePath(); - Assert.IsNotNull(tempDir, "No permission to execute this test?"); + if (tempDir == null) Assert.Inconclusive("No permission to execute this test?"); tempDir = Path.Combine(tempDir, "SharpZipTest"); + Directory.CreateDirectory(tempDir); - if (tempDir != null) + try { - Directory.CreateDirectory(tempDir); + string tempFile = Path.Combine(tempDir, "SharpZipTest.Zip"); + + using (FileStream f = File.Create(tempFile, 1024)) + { + f.WriteByte(0); + } + + FileAttributes attributes = FileAttributes.Hidden; + + File.SetAttributes(tempFile, attributes); + ZipEntryFactory factory = null; + ZipEntry entry; + int combinedAttributes = 0; try { - // Note the seconds returned will be even! - var createTime = new DateTime(2100, 2, 27, 11, 07, 56); - var lastWriteTime = new DateTime(2050, 11, 3, 7, 23, 32); - var lastAccessTime = new DateTime(2050, 11, 3, 0, 42, 12); - - string tempFile = Path.Combine(tempDir, "SharpZipTest.Zip"); - - using (FileStream f = File.Create(tempFile, 1024)) - { - f.WriteByte(0); - } - - File.SetCreationTime(tempFile, createTime); - File.SetLastWriteTime(tempFile, lastWriteTime); - File.SetLastAccessTime(tempFile, lastAccessTime); - - FileAttributes attributes = FileAttributes.Hidden; - - File.SetAttributes(tempFile, attributes); - ZipEntryFactory factory = null; - ZipEntry entry; - int combinedAttributes = 0; - - try - { - factory = new ZipEntryFactory(); - - factory.Setting = ZipEntryFactory.TimeSetting.CreateTime; - factory.GetAttributes = ~((int)FileAttributes.ReadOnly); - factory.SetAttributes = (int)FileAttributes.ReadOnly; - combinedAttributes = (int)(FileAttributes.ReadOnly | FileAttributes.Hidden); - - entry = factory.MakeFileEntry(tempFile); - Assert.AreEqual(createTime, entry.DateTime, "Create time failure"); - Assert.AreEqual(entry.ExternalFileAttributes, combinedAttributes); - Assert.AreEqual(1, entry.Size); - - factory.Setting = ZipEntryFactory.TimeSetting.LastAccessTime; - entry = factory.MakeFileEntry(tempFile); - Assert.AreEqual(lastAccessTime, entry.DateTime, "Access time failure"); - Assert.AreEqual(1, entry.Size); - - factory.Setting = ZipEntryFactory.TimeSetting.LastWriteTime; - entry = factory.MakeFileEntry(tempFile); - Assert.AreEqual(lastWriteTime, entry.DateTime, "Write time failure"); - Assert.AreEqual(1, entry.Size); - } - finally - { - File.Delete(tempFile); - } - - // Do the same for directories - // Note the seconds returned will be even! - createTime = new DateTime(2090, 2, 27, 11, 7, 56); - lastWriteTime = new DateTime(2107, 12, 31, 23, 59, 58); - lastAccessTime = new DateTime(1980, 1, 1, 1, 0, 0); - - Directory.SetCreationTime(tempDir, createTime); - Directory.SetLastWriteTime(tempDir, lastWriteTime); - Directory.SetLastAccessTime(tempDir, lastAccessTime); - - factory.Setting = ZipEntryFactory.TimeSetting.CreateTime; - entry = factory.MakeDirectoryEntry(tempDir); - Assert.AreEqual(createTime, entry.DateTime, "Directory create time failure"); - Assert.IsTrue((entry.ExternalFileAttributes & (int)FileAttributes.Directory) == (int)FileAttributes.Directory); - - factory.Setting = ZipEntryFactory.TimeSetting.LastAccessTime; - entry = factory.MakeDirectoryEntry(tempDir); - Assert.AreEqual(lastAccessTime, entry.DateTime, "Directory access time failure"); - - factory.Setting = ZipEntryFactory.TimeSetting.LastWriteTime; - entry = factory.MakeDirectoryEntry(tempDir); - Assert.AreEqual(lastWriteTime, entry.DateTime, "Directory write time failure"); + factory = new ZipEntryFactory(); + + factory.GetAttributes = ~((int)FileAttributes.ReadOnly); + factory.SetAttributes = (int)FileAttributes.ReadOnly; + combinedAttributes = (int)(FileAttributes.ReadOnly | FileAttributes.Hidden); + + entry = factory.MakeFileEntry(tempFile); + Assert.AreEqual(entry.ExternalFileAttributes, combinedAttributes); + Assert.AreEqual(1, entry.Size); } finally { - Directory.Delete(tempDir, true); + File.Delete(tempFile); } } + finally + { + Directory.Delete(tempDir, true); + } + + } + + [Test] + [Category("Zip")] + [Category("CreatesTempFile")] + [TestCase(ZipEntryFactory.TimeSetting.CreateTime)] + [TestCase(ZipEntryFactory.TimeSetting.LastAccessTime)] + [TestCase(ZipEntryFactory.TimeSetting.LastWriteTime)] + public void CreatedFileEntriesUsesExpectedTime(ZipEntryFactory.TimeSetting timeSetting) + { + string tempDir = GetTempFilePath(); + if (tempDir == null) Assert.Inconclusive("No permission to execute this test?"); + + tempDir = Path.Combine(tempDir, "SharpZipTest"); + + // Note the seconds returned will be even! + var expectedTime = new DateTime(2100, 2, 27, 11, 07, 56); + + Directory.CreateDirectory(tempDir); + + try + { + + string tempFile = Path.Combine(tempDir, "SharpZipTest.Zip"); + + using (FileStream f = File.Create(tempFile, 1024)) + { + f.WriteByte(0); + } + + DateTime fileTime = DateTime.MinValue; + + if (timeSetting == ZipEntryFactory.TimeSetting.CreateTime) { + File.SetCreationTime(tempFile, expectedTime); + fileTime = File.GetCreationTime(tempFile); + } + + if (timeSetting == ZipEntryFactory.TimeSetting.LastAccessTime){ + File.SetLastAccessTime(tempFile, expectedTime); + fileTime = File.GetLastAccessTime(tempFile); + } + + if (timeSetting == ZipEntryFactory.TimeSetting.LastWriteTime) { + File.SetLastWriteTime(tempFile, expectedTime); + fileTime = File.GetLastWriteTime(tempFile); + } + + if(fileTime != expectedTime) { + Assert.Inconclusive("File time could not be altered"); + } + + var factory = new ZipEntryFactory(); + + factory.Setting = timeSetting; + + var entry = factory.MakeFileEntry(tempFile); + Assert.AreEqual(expectedTime, entry.DateTime); + Assert.AreEqual(1, entry.Size); + + } + finally + { + Directory.Delete(tempDir, true); + } + + } + + [Test] + [Category("Zip")] + [Category("CreatesTempFile")] + [TestCase(ZipEntryFactory.TimeSetting.CreateTime)] + [TestCase(ZipEntryFactory.TimeSetting.LastAccessTime)] + [TestCase(ZipEntryFactory.TimeSetting.LastWriteTime)] + public void CreatedDirectoryEntriesUsesExpectedTime(ZipEntryFactory.TimeSetting timeSetting) + { + string tempDir = GetTempFilePath(); + if (tempDir == null) Assert.Inconclusive("No permission to execute this test?"); + + tempDir = Path.Combine(tempDir, "SharpZipTest"); + + // Note the seconds returned will be even! + var expectedTime = new DateTime(2100, 2, 27, 11, 07, 56); + + Directory.CreateDirectory(tempDir); + + try + { + + string tempFile = Path.Combine(tempDir, "SharpZipTest.Zip"); + + using (FileStream f = File.Create(tempFile, 1024)) + { + f.WriteByte(0); + } + + DateTime dirTime = DateTime.MinValue; + + if (timeSetting == ZipEntryFactory.TimeSetting.CreateTime) { + Directory.SetCreationTime(tempFile, expectedTime); + dirTime = Directory.GetCreationTime(tempDir); + } + + if (timeSetting == ZipEntryFactory.TimeSetting.LastAccessTime){ + Directory.SetLastAccessTime(tempDir, expectedTime); + dirTime = Directory.GetLastAccessTime(tempDir); + } + + if (timeSetting == ZipEntryFactory.TimeSetting.LastWriteTime) { + Directory.SetLastWriteTime(tempDir, expectedTime); + dirTime = Directory.GetLastWriteTime(tempDir); + } + + if(dirTime != expectedTime) { + Assert.Inconclusive("Directory time could not be altered"); + } + + var factory = new ZipEntryFactory(); + + factory.Setting = timeSetting; + + var entry = factory.MakeDirectoryEntry(tempDir); + Assert.AreEqual(expectedTime, entry.DateTime); + } + finally + { + Directory.Delete(tempDir, true); + } + } } }