-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
175 lines (152 loc) · 5.53 KB
/
build.ps1
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
function build-version() {
$gitVersion = $(git tag) | ? { $_ -match "v([0-9]+\.[0-9]+)" } | % {
$m = [regex]::Match($_, "v([0-9]+)\.([0-9]+)")
$i = [int]($m.Groups[1].Value)
$j = [int]($m.Groups[2].Value)
return $i * 1000 + $j
} | Sort -Descending | Select -First 1
$verMajor = [int]([math]::Round($gitVersion / 1000))
$verMinor = $gitVersion % 1000
$buildNumber = 0
if ($env:APPVEYOR) {
$buildNumber = $env:APPVEYOR_BUILD_NUMBER
write-host "APPVEYOR_BUILD_NUMBER: $env:APPVEYOR_BUILD_NUMBER"
}
if ($env:APPVEYOR) {
if ($env:APPVEYOR_PULL_REQUEST_NUMBER) {
$branch = "pullrequest-" + $env:APPVEYOR_PULL_REQUEST_NUMBER
}
else {
$branch = $env:APPVEYOR_REPO_BRANCH
write-host "APPVEYOR_REPO_BRANCH: $env:APPVEYOR_REPO_BRANCH"
}
}
else {
$branch = $(git rev-parse --abbrev-ref HEAD)
}
$branch = $branch.Replace("/", "").Replace("-", "").Replace("\\", "")
$VERSION = "$($verMajor).$($verMinor).$($buildNumber)"
if ($branch -ne "master") {
$VERSION += "-$branch"
}
if ($env:APPVEYOR) {
& appveyor UpdateBuild -Version $VERSION
}
Write-Host "Version: $VERSION"
$env:MARKDOCS_BUILD_VERSION = $VERSION
}
function build-clean() {
$SOLUTION_DIR = Resolve-Path "."
$ARTIFACTS = Join-Path $SOLUTION_DIR "artifacts"
if (-not (Test-Path $ARTIFACTS)) {
New-Item -Path $ARTIFACTS -ItemType Directory | Out-Null
}
if (-not (Test-Path "$ARTIFACTS/nuget")) {
New-Item -Path "$ARTIFACTS/nuget" -ItemType Directory | Out-Null
}
if (-not (Test-Path "$ARTIFACTS/choco")) {
New-Item -Path "$ARTIFACTS/choco" -ItemType Directory | Out-Null
}
Get-ChildItem -Path $ARTIFACTS | Remove-Item -Force -Recurse
Get-ChildItem -Filter "bin" -Directory -Recurse -ErrorAction "SilentlyContinue" | Remove-Item -Force -Recurse -ErrorAction "SilentlyContinue"
Get-ChildItem -Filter "obj" -Directory -Recurse -ErrorAction "SilentlyContinue" | Remove-Item -Force -Recurse -ErrorAction "SilentlyContinue"
}
function build-restore() {
$VERSION = $env:MARKDOCS_BUILD_VERSION
if (!$VERSION) {
$VERSION = "0.0.0-dev"
}
& dotnet restore /v:q /nologo /p:Version=$VERSION
if ($LASTEXITCODE -ne 0) {
Write-Host "'dotnet restore' exited with $LASTEXITCODE"
exit 1
}
}
function build-packages() {
$SOLUTION_DIR = Resolve-Path "."
$ARTIFACTS = Join-Path $SOLUTION_DIR "artifacts/nuget"
$CONFIGURATION = "Release"
$VERSION = $env:MARKDOCS_BUILD_VERSION
if (!$VERSION) {
$VERSION = "0.0.0-dev"
}
Get-ChildItem -Filter *.csproj -Path "./src" -Recurse -File | % {
& dotnet pack --output $ARTIFACTS --no-restore -v q /nologo /p:Version=$VERSION /p:Configuration=$CONFIGURATION $_.FullName
if ($LASTEXITCODE -ne 0) {
Write-Host "'dotnet pack' exited with $LASTEXITCODE"
exit 1
}
Write-Host "Compiled project $($_.Name)"
}
Write-Host "Generated NuGet packages:"
Get-ChildItem -Path $ARTIFACTS -Filter *.nupkg -File | %{ Write-Host " $($_.Name)" }
}
function build-tools() {
$SOLUTION_DIR = Resolve-Path "."
$ARTIFACTS = Join-Path $SOLUTION_DIR "artifacts/choco"
$CONFIGURATION = "Release"
$VERSION = $env:MARKDOCS_BUILD_VERSION
if (!$VERSION) {
$VERSION = "0.0.0-dev"
}
dotnet publish --runtime win7-x64 --configuration $CONFIGURATION -v q `
--output $ARTIFACTS/markdocs-win7-x64 `
./src/markdocs/markdocs.csproj /nologo /p:Version=$VERSION /p:PackAsTool=false
if ($LASTEXITCODE -ne 0) {
Write-Host "'dotnet publish' exited with $LASTEXITCODE"
exit 1
}
copy ./tools $ARTIFACTS/markdocs-win7-x64 -rec -force
copy ./markdocs.nuspec $ARTIFACTS/markdocs-win7-x64 -force
pushd $ARTIFACTS/markdocs-win7-x64
choco pack --version=$VERSION --outputdirectory="$ARTIFACTS"
popd
if ($LASTEXITCODE -ne 0) {
Write-Host "'choco pack' exited with $LASTEXITCODE"
exit 1
}
Write-Host "Compiled markdocs cli tool"
Write-Host "Generated Chocolatey packages:"
Get-ChildItem -Path $ARTIFACTS -Filter *.nupkg -File | %{ Write-Host " $($_.Name)" }
}
function build-usage() {
write-host "USAGE:"
write-host " ./build.ps1 [<command>]"
write-host "COMMANDS:"
write-host " version - generate version number"
write-host " clean - clean build output"
write-host " restore - restore extenal dependencies"
write-host " packages - build NuGet packages"
write-host " tools - build CLI tools"
write-host " all - build everything"
write-host " -?|-h|--help|help"
}
if ($args.Length -gt 0) {
switch ($args[0]) {
"version" { build-version }
"clean" { build-clean }
"restore" { build-restore }
"packages" { build-packages }
"tools" { build-tools }
"all" {
build-version
build-clean
build-restore
build-packages
build-tools
}
"-?" { build-usage }
"-h" { build-usage }
"--help" { build-usage }
"help" { build-usage }
Default {
write-host "Invalid arguments: `"$args`"" -f red
write-host "Type `"./build.ps1 --help`" to get help"
exit 1
}
}
}
else {
write-host "Type `"./build.ps1 --help`" to get help"
exit 1
}