|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
| 3 | +using System.Formats.Tar; |
3 | 4 | using System.IO;
|
| 5 | +using System.IO.Compression; |
4 | 6 | using System.Linq;
|
5 | 7 | using System.Runtime.InteropServices;
|
6 | 8 | using System.Text;
|
@@ -110,6 +112,97 @@ public async Task TestBuild()
|
110 | 112 | File.Delete(_configurationFile);
|
111 | 113 | }
|
112 | 114 |
|
| 115 | + [Test] |
| 116 | + public async Task TestMacOSTarZipAreExecutable() |
| 117 | + { |
| 118 | + EnsureTestsFolder(); |
| 119 | + |
| 120 | + File.Delete(_configurationFile); |
| 121 | + |
| 122 | + await CreateConfiguration(); |
| 123 | + |
| 124 | + var config = await File.ReadAllTextAsync(_configurationFile); |
| 125 | + |
| 126 | + if (Directory.Exists(_artifactsFolder)) |
| 127 | + { |
| 128 | + Directory.Delete(_artifactsFolder, true); |
| 129 | + } |
| 130 | + |
| 131 | + config = "profile = \"custom\"" + Environment.NewLine + config; |
| 132 | + config += @" |
| 133 | + [msbuild.properties] |
| 134 | +SelfContained = false |
| 135 | +PublishSingleFile = false |
| 136 | +PublishTrimmed = false |
| 137 | + [[pack]] |
| 138 | +rid = ""osx-x64"" |
| 139 | +kinds = [""tar"", ""zip""] |
| 140 | +[nuget] |
| 141 | +publish = false |
| 142 | +"; |
| 143 | + config = config.Replace("\r\n", "\n").Replace("\n", Environment.NewLine); |
| 144 | + await File.WriteAllTextAsync(_configurationFile, config); |
| 145 | + |
| 146 | + var resultBuild = await CliWrap.Cli.Wrap(_releaserExe) |
| 147 | + .WithArguments("build --force dotnet-releaser.toml") |
| 148 | + .WithStandardOutputPipe(PipeTarget.ToDelegate(x => Console.Out.WriteLine(x))) |
| 149 | + .WithStandardErrorPipe(PipeTarget.ToDelegate(x => Console.Error.WriteLine(x))) |
| 150 | + .WithWorkingDirectory(_helloWorldFolder).ExecuteAsync(); |
| 151 | + |
| 152 | + Assert.True(Directory.Exists(_artifactsFolder)); |
| 153 | + |
| 154 | + var files = Directory.GetFiles(_artifactsFolder).Select(Path.GetFileName).OrderBy(x => x).ToList(); |
| 155 | + |
| 156 | + var expectedFiles = new List<string>() |
| 157 | + { |
| 158 | + "HelloWorld.0.1.0.osx-x64.tar.gz", |
| 159 | + "HelloWorld.0.1.0.osx-x64.zip", |
| 160 | + }.OrderBy(x => x).ToList(); |
| 161 | + |
| 162 | + foreach (var file in files) |
| 163 | + { |
| 164 | + Console.WriteLine($"-> {file}"); |
| 165 | + } |
| 166 | + |
| 167 | + Assert.AreEqual(expectedFiles, files); |
| 168 | + |
| 169 | + if (!OperatingSystem.IsWindows()) |
| 170 | + { |
| 171 | + // ensure files are executable |
| 172 | + var tar = Path.Combine(_artifactsFolder, "HelloWorld.0.1.0.osx-x64.tar.gz"); |
| 173 | + using FileStream fs = new(tar, FileMode.Open, FileAccess.Read); |
| 174 | + using var gzip = new GZipStream(fs, CompressionMode.Decompress); |
| 175 | + using var unzippedStream = new MemoryStream(); |
| 176 | + { |
| 177 | + await gzip.CopyToAsync(unzippedStream); |
| 178 | + unzippedStream.Seek(0, SeekOrigin.Begin); |
| 179 | + |
| 180 | + using var reader = new TarReader(unzippedStream); |
| 181 | + |
| 182 | + while (reader.GetNextEntry() is TarEntry entry) |
| 183 | + { |
| 184 | + if (entry.Name == "./HelloWorld") |
| 185 | + { |
| 186 | + Assert.IsTrue(entry.Mode.HasFlag(UnixFileMode.GroupExecute)); |
| 187 | + Assert.IsTrue(entry.Mode.HasFlag(UnixFileMode.OtherExecute)); |
| 188 | + Assert.IsTrue(entry.Mode.HasFlag(UnixFileMode.UserExecute)); |
| 189 | + break; |
| 190 | + } |
| 191 | + } |
| 192 | + } |
| 193 | + // extract zip files and check executable |
| 194 | + var zippath = Path.Combine(_artifactsFolder, "HelloWorld.0.1.0.osx-x64.zip"); |
| 195 | + ZipFile.ExtractToDirectory(zippath, _artifactsFolder); |
| 196 | + var fileMode = File.GetUnixFileMode(Path.Combine(_artifactsFolder, "HelloWorld")); |
| 197 | + Assert.IsTrue(fileMode.HasFlag(UnixFileMode.GroupExecute)); |
| 198 | + Assert.IsTrue(fileMode.HasFlag(UnixFileMode.OtherExecute)); |
| 199 | + Assert.IsTrue(fileMode.HasFlag(UnixFileMode.UserExecute)); |
| 200 | + } |
| 201 | + |
| 202 | + Directory.Delete(_artifactsFolder, true); |
| 203 | + File.Delete(_configurationFile); |
| 204 | + } |
| 205 | + |
113 | 206 | [Test]
|
114 | 207 | public async Task TestBuildService()
|
115 | 208 | {
|
|
0 commit comments