Files
redis-For-Windows/msvs/ReleasePackagingTool/Program.cs
T
Enrico Giordani fc5eebd1b8 [Setup] Nuget/Chocolatey packages update.
[Change] Updated the ReleasePackagingTool to include all .pdb files.
[Change] Updated the nuget/chocolatey templates to conform with the guidelines:
         - Replaced the Redis logo with the Redis icon.
         - Changed the package title.
         - Changed the package description.
         - Removed the package summary to use a short version of the decription
           instead.
 [Change] Updated license.txt to 2015.
2015-07-22 13:33:35 +02:00

155 lines
5.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.IO.Compression;
using System.Xml;
using System.Reflection;
using System.Diagnostics;
namespace ReleasePackagingTool
{
class Program
{
static string rootPath;
static string versionReplacementText = "CurrentRedisVersion";
static void Main(string[] args)
{
try
{
Program p = new Program();
string assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
rootPath = Path.GetFullPath(Path.Combine(assemblyDirectory, @"..\..\..\..\..\"));
string version;
version = p.GetRedisVersion();
p.UpdateNuSpecFiles(version);
p.BuildReleasePackage(version);
Console.Write("Release packaging complete.");
Environment.ExitCode = 0;
}
catch(Exception ex)
{
Console.WriteLine("Error. Failed to finish release packaging.\n" + ex.ToString());
Environment.ExitCode = -1;
}
}
string GetRedisVersion()
{
TextReader tr = File.OpenText(Path.Combine(rootPath, @"src\version.h"));
string line = tr.ReadLine();
int start = line.IndexOf('\"');
int last = line.LastIndexOf('\"');
return line.Substring(start + 1, last - start - 1);
}
void ForceFileErase(string file)
{
if (File.Exists(file))
{
File.Delete(file);
}
}
void CreateTextFileFromTemplate(string templatePath, string documentPath, string toReplace, string replaceWith )
{
string replacedText;
using (TextReader trTemplate = File.OpenText(templatePath) )
{
string templateText = trTemplate.ReadToEnd();
replacedText = templateText.Replace(toReplace, replaceWith);
}
ForceFileErase(documentPath);
using (TextWriter twDoc = File.CreateText(documentPath))
{
twDoc.Write(replacedText);
twDoc.Close();
}
}
void UpdateNuSpecFiles(string redisVersion)
{
string chocTemplate = Path.Combine(rootPath, @"msvs\setups\chocolatey\template\redis.nuspec.template");
string chocDocument = Path.Combine(rootPath, @"msvs\setups\chocolatey\redis.nuspec");
CreateTextFileFromTemplate(chocTemplate, chocDocument, versionReplacementText, redisVersion);
string nugetTemplate = Path.Combine(rootPath, @"msvs\setups\nuget\template\redis.nuspec.template");
string nugetDocument = Path.Combine(rootPath, @"msvs\setups\nuget\redis.nuspec");
CreateTextFileFromTemplate(nugetTemplate, nugetDocument, versionReplacementText, redisVersion);
}
void BuildReleasePackage(string version)
{
string releasePackageDir = Path.Combine(rootPath, @"bin\Release\");
if (Directory.Exists(releasePackageDir) == false)
{
Directory.CreateDirectory(releasePackageDir);
}
string releasePackagePath = Path.Combine(rootPath, @"bin\Release\Redis-x64-" + version + ".zip");
ForceFileErase(releasePackagePath);
string executablesRoot = Path.Combine(rootPath, @"msvs\x64\Release");
List<string> executableNames = new List<string>()
{
"redis-benchmark.exe",
"redis-check-aof.exe",
"redis-check-dump.exe",
"redis-cli.exe",
"redis-server.exe"
};
List<string> symbolNames = new List<string>()
{
"redis-benchmark.pdb",
"redis-check-aof.pdb",
"redis-check-dump.pdb",
"redis-cli.pdb",
"redis-server.pdb"
};
List<string> dependencyNames = new List<string>()
{
"EventLog.dll"
};
string documentsRoot = Path.Combine(rootPath, @"msvs\setups\documentation");
List<string> docuementNames = new List<string>()
{
"Redis on Windows.docx",
"Redis on Windows Release Notes.docx",
"Windows Service Documentation.docx",
"redis.windows.conf",
"redis.windows-service.conf"
};
using (ZipArchive archive = ZipFile.Open(releasePackagePath, ZipArchiveMode.Create))
{
foreach (string executableName in executableNames)
{
archive.CreateEntryFromFile(Path.Combine(executablesRoot, executableName), executableName);
}
foreach (string symbolName in symbolNames)
{
archive.CreateEntryFromFile(Path.Combine(executablesRoot, symbolName), symbolName);
}
foreach (string dependencyName in dependencyNames)
{
archive.CreateEntryFromFile(Path.Combine(executablesRoot, dependencyName), dependencyName);
}
foreach (string documentName in docuementNames)
{
archive.CreateEntryFromFile(Path.Combine(documentsRoot, documentName), documentName);
}
}
}
}
}