-
Notifications
You must be signed in to change notification settings - Fork 15
/
deploy_local.csx
90 lines (77 loc) · 2.48 KB
/
deploy_local.csx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Linq;
var cd = Environment.CurrentDirectory;
var projectName = "Migrator.EF6.Tools";
var userName = Environment.UserName;
var userProfileDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var deploymentFolder = Environment.GetEnvironmentVariable("MIGRATOR_EF6_LOCAL_PACKAGES_FEED_PATH") ?? $@"C:\dev\LocalPackages";
Directory.CreateDirectory(deploymentFolder);
var nugetDirectory = Path.Combine(userProfileDirectory, ".nuget/packages");
var nugetToolsDirectory = Path.Combine(nugetDirectory, ".tools");
var nugetProjectDirectory = Path.Combine(nugetDirectory, projectName);
var nugetToolsProjectDirectory = Path.Combine(nugetToolsDirectory, projectName);
var regexFolder = new Regex(@"(.\..\..)-(.+)");
var regexFile = new Regex($@"{projectName}\.(.\..\..)-(.+).nupkg");
if (!Pack())
{
Console.WriteLine("A problem occurred while packing.");
return;
}
RemoveDevPackageFilesIn(deploymentFolder);
RemoveDevPackagesIn(nugetProjectDirectory);
RemoveDevPackagesIn(nugetToolsProjectDirectory);
var package = GetPackagePath();
if (package == null)
{
Console.WriteLine("Package file not found. A problem might have occurred with the build script.");
return;
}
var packageFileName = Path.GetFileName(package);
var deployedPackagePath = Path.Combine(deploymentFolder, packageFileName);
File.Copy(package, deployedPackagePath);
Console.WriteLine($"{packageFileName} -> {deployedPackagePath}");
//------------------------------------------------------------------------------
void RemoveDevPackagesIn(string directory)
{
var folders = Directory.EnumerateDirectories(directory);
foreach (var folder in folders)
{
var name = Path.GetFileName(folder);
if (regexFolder.IsMatch(name))
{
Directory.Delete(folder, true);
}
}
}
void RemoveDevPackageFilesIn(string directory)
{
var files = Directory.EnumerateFiles(directory);
foreach (var file in files)
{
var name = Path.GetFileName(file);
if (regexFile.IsMatch(name))
{
File.Delete(file);
}
}
}
bool Pack()
{
var process = Process.Start("powershell", "./build.ps1");
process.WaitForExit();
var exitCode = process.ExitCode;
return exitCode == 0;
}
string GetPackagePath()
{
var packagesDirectory = Path.Combine(cd, "artifacts/packages");
if (!Directory.Exists(packagesDirectory))
{
return null;
}
var files = Directory.EnumerateFiles(packagesDirectory);
return files.OrderBy(f => f.Length).FirstOrDefault();
}