-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathpsake-common.ps1
More file actions
139 lines (109 loc) · 3.92 KB
/
psake-common.ps1
File metadata and controls
139 lines (109 loc) · 3.92 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
Properties {
### Directories
$base_dir = $root
$build_dir = "$base_dir\build"
$src_dir = "$base_dir\src"
$package_dir = "$src_dir\packages"
$nuspec_dir = "$base_dir\nuspecs"
$temp_dir = "$build_dir\Temp"
$framework_dir = $env:windir + "\Microsoft.Net\Framework\v4.0.30319"
### Tools
$nuget = "$src_dir\.nuget\nuget.exe"
$xunit = "$package_dir\xunit.runners*\tools\xunit.console.clr4.exe"
$7zip = "$package_dir\7-Zip.CommandLine.*\tools\7za.exe"
### AppVeyor-related
$appVeyorConfig = "$base_dir\appveyor.yml"
$appVeyor = $env:APPVEYOR
### Project information
$solution_path = "$src_dir\$solution"
$sharedAssemblyInfo = "$src_dir\SharedAssemblyInfo.cs"
$config = "Release"
$modern_projects = @(
"$src_dir\FlatFile.Core.Modern\FlatFile.Core.Modern.csproj",
"$src_dir\FlatFile.Core.Attributes.Modern\FlatFile.Core.Attributes.Modern.csproj",
"$src_dir\FlatFile.Delimited.Modern\FlatFile.Delimited.Modern.csproj",
"$src_dir\FlatFile.FixedLength.Modern\FlatFile.FixedLength.Modern.csproj",
"$src_dir\FlatFile.Delimited.Attributes.Modern\FlatFile.Delimited.Attributes.Modern.csproj",
"$src_dir\FlatFile.FixedLength.Attributes.Modern\FlatFile.FixedLength.Attributes.Modern.csproj"
)
### Files
$releaseNotes = "$base_dir\ChangeLog.md"
}
## Tasks
Task Restore -Description "Restore .NET packages for modern projects." {
foreach ($project in $modern_projects) {
"Restoring '$project'..."
Exec { dotnet restore $project }
}
}
Task Clean -Description "Clean up build and project folders." {
Clean-Directory $build_dir
foreach ($project in $modern_projects) {
"Cleaning '$project'..."
Exec { dotnet clean $project -c $config }
}
}
Task Compile -Depends Clean, Restore -Description "Compile all modern SDK-style projects." {
foreach ($project in $modern_projects) {
"Compiling '$project'..."
Exec { dotnet build $project -c $config --no-restore }
}
}
### Pack functions
function Create-Package($project, $version, $notes) {
Create-Directory $temp_dir
Copy-Files "$nuspec_dir\$project.nuspec" $temp_dir
Try {
Replace-Content "$nuspec_dir\$project.nuspec" '#releaseNotes#' $notes
Replace-Content "$nuspec_dir\$project.nuspec" '$version$' $version
Exec { .$nuget pack "$nuspec_dir\$project.nuspec" -OutputDirectory "$build_dir" -BasePath "$build_dir" -Version $version}
}
Finally {
Move-Files "$temp_dir\$project.nuspec" $nuspec_dir
}
}
function Get-ReleaseNotes {
$content = (Get-Content "$releaseNotes") -Join "`n"
return $content
}
### Version functions
function Get-BuildVersion {
$version = Get-SharedVersion
$buildVersion = $env:APPVEYOR_BUILD_VERSION
if ($buildVersion -ne $null) {
$version = $buildVersion
}
return $version
}
function Get-SharedVersion {
$line = Get-Content "$sharedAssemblyInfo" | where {$_.Contains("AssemblyVersion")}
$line.Split('"')[1]
}
function Update-AppveyorVersion($version) {
Check-Version($version)
$versionPattern = "version: [0-9]+(\.([0-9]+|\*)){1,3}"
$versionReplace = "version: $version"
if (Test-Path $appVeyorConfig) {
"Patching $appVeyorConfig..."
Replace-Content "$appVeyorConfig" $versionPattern $versionReplace
}
}
### Common functions
function Create-Directory($dir) {
New-Item -Path $dir -Type Directory -Force > $null
}
function Clean-Directory($dir) {
If (Test-Path $dir) {
"Cleaning up '$dir'..."
Remove-Item "$dir\*" -Recurse -Force
}
}
function Copy-Files($source, $destination) {
Copy-Item "$source" $destination -Force > $null
}
function Move-Files($source, $destination) {
Move-Item "$source" $destination -Force > $null
}
function Replace-Content($file, $pattern, $substring) {
(gc $file) -Replace $pattern, $substring | sc $file
}