|
| 1 | +using Nuke.Common; |
| 2 | +using Nuke.Common.IO; |
| 3 | +using Nuke.Common.Tooling; |
| 4 | +using Nuke.Common.Tools.InnoSetup; |
| 5 | +using Nuke.Common.Utilities.Collections; |
| 6 | +using ricaun.Nuke.Components; |
| 7 | +using ricaun.Nuke.Extensions; |
| 8 | +using System; |
| 9 | +using System.IO; |
| 10 | +using System.Linq; |
| 11 | + |
| 12 | +interface IBuildInstall : IRelease, ISign, IHazMainProject |
| 13 | +{ |
| 14 | + Target BuildInstall => _ => _ |
| 15 | + .TriggeredBy(Sign) |
| 16 | + .Before(Release) |
| 17 | + .Executes(() => |
| 18 | + { |
| 19 | + var project = MainProject; |
| 20 | + var projectName = project.Name; |
| 21 | + var projectVersion = project.GetInformationalVersion(); |
| 22 | + var solutionDirectory = Solution.Directory; |
| 23 | + var folderOutput = "Install"; |
| 24 | + |
| 25 | + Serilog.Log.Information($"{projectName} {projectVersion}"); |
| 26 | + |
| 27 | + // Deploy File |
| 28 | + var outputInno = project.Directory / "bin" / folderOutput; |
| 29 | + var issFiles = Globbing.GlobFiles(solutionDirectory, $"**/*{projectName}.iss"); |
| 30 | + |
| 31 | + if (issFiles.IsEmpty()) |
| 32 | + Serilog.Log.Error($"Not found any .iss file in {solutionDirectory}"); |
| 33 | + |
| 34 | + issFiles.ForEach(file => |
| 35 | + { |
| 36 | + var tempFile = CreateTemporaryFile(file, projectVersion); |
| 37 | + try |
| 38 | + { |
| 39 | + InnoSetupTasks.InnoSetup(config => config |
| 40 | + .SetProcessToolPath(NuGetToolPathResolver.GetPackageExecutable("Tools.InnoSetup", "ISCC.exe")) |
| 41 | + .SetScriptFile(tempFile) |
| 42 | + .SetOutputDir(outputInno)); |
| 43 | + } |
| 44 | + finally |
| 45 | + { |
| 46 | + tempFile.DeleteFile(); |
| 47 | + } |
| 48 | + }); |
| 49 | + |
| 50 | + // Sign outputInno |
| 51 | + SignFolder(outputInno); |
| 52 | + |
| 53 | + // Zip exe Files |
| 54 | + var exeFiles = Globbing.GlobFiles(outputInno, "**/*.exe"); |
| 55 | + exeFiles.ForEach(file => ZipExtension.ZipFileCompact(file, projectName)); |
| 56 | + |
| 57 | + if (exeFiles.IsEmpty()) |
| 58 | + Serilog.Log.Error($"Not found any .exe file in {outputInno}"); |
| 59 | + |
| 60 | + var message = string.Join(" | ", exeFiles.Select(e => e.Name)); |
| 61 | + ReportSummary(_ => _.AddPair("File", message)); |
| 62 | + |
| 63 | + if (outputInno != ReleaseDirectory) |
| 64 | + { |
| 65 | + Globbing.GlobFiles(outputInno, "**/*.zip") |
| 66 | + .ForEach(file => FileSystemTasks.CopyFileToDirectory(file, ReleaseDirectory)); |
| 67 | + } |
| 68 | + |
| 69 | + }); |
| 70 | + |
| 71 | + AbsolutePath CreateTemporaryFile(AbsolutePath file, string projectVersion) |
| 72 | + { |
| 73 | + var folder = file.Parent; |
| 74 | + var tempFileName = $"{Path.GetFileNameWithoutExtension(file)}_{DateTime.Now.Ticks}{Path.GetExtension(file)}"; |
| 75 | + |
| 76 | + var tempFile = Path.Combine(folder, tempFileName); |
| 77 | + |
| 78 | + FileSystemTasks.CopyFile(file, tempFile, FileExistsPolicy.Overwrite); |
| 79 | + |
| 80 | + var content = File.ReadAllText(tempFile); |
| 81 | + |
| 82 | + content = content.Replace("1.0.0", projectVersion); |
| 83 | + |
| 84 | + File.WriteAllText(tempFile, content); |
| 85 | + |
| 86 | + return tempFile; |
| 87 | + } |
| 88 | +} |
0 commit comments