-
Notifications
You must be signed in to change notification settings - Fork 59
/
make.ps1
157 lines (141 loc) · 4.1 KB
/
make.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
param(
[switch]$build_darwin,
[switch]$build_linux_arm,
[switch]$build_linux_x64,
[switch]$build,
[switch]$bump_version,
[switch]$start,
[switch]$test,
[switch]$test_integration,
[switch]$clean,
[switch]$help,
[switch]$vet,
[switch]$fmt,
[switch]$lint,
[switch]$tools
)
function showHelp{
Write-Host "Usage:
.\make.ps1 -build_darwin build an executable for MacOS
.\make.ps1 -build_linux_arm build an executable for linux on arm platform
.\make.ps1 -build_linux_x64 build an executable for linux on x64 platform
.\make.ps1 -build build the windows executable
.\make.ps1 -bump_version bump the app version
.\make.ps1 -start start the ergo proxy
.\make.ps1 -fmt run gofmt on the source code
.\make.ps1 -vet run go vet on the source code
.\make.ps1 -lint run golint on the source code
.\make.ps1 -tools obtain the tools needed to run different make targets
.\make.ps1 -test run the tests
.\make.ps1 -test-integration run the integration tests
.\make.ps1 -clean remove all the created executables
"
}
function fmt() {
Write-Host "Running fmt ..." -ForegroundColor Green
$rez = $(gofmt -l .)
if($rez.Length -eq 0){
return
}
$noOfLines = $(Measure-Object $rez | Select-Object -ExpandProperty Count)
if($noOfLines -ne 0){
Write-Warning -Message "The following files are not correctly formated:"
foreach($r in $rez){
Write-Host $r -ForegroundColor Red
}
exit $noOfLines
}
}
function vet(){
Write-Host "Running vet ..." -ForegroundColor Green
go vet ./...
if($LASTEXITCODE -ne 0){
exit $LASTEXITCODE
}
}
function tools(){
go get -u github.com/golang/lint/golint
}
function lint(){
tools
Write-Host "Running lint ..." -ForegroundColor Green
$Env:Path+=";"+"$Env:GOPATH\bin"
$rez = $(golint ./...)
if($rez.Length -eq 0){
return
}
$noOfLines = $(Measure-Object $rez | Select-Object -ExpandProperty Count)
if($noOfLines -ne 0){
Write-Warning -Message "Lint says the following files are not ok:"
foreach($r in $rez){
Write-Host $r -ForegroundColor Red
}
exit $noOfLines
}
}
function bumpVersion {
git tag --sort=committerdate | Select-Object -Last 1 > .version
Get-Content .version
}
function build(){
bumpVersion
go build -ldflags "-w -s -X main.VERSION=$(git describe --tag --always)" -o bin/ergo.exe
}
if($build_darwin_arm) {
Write-Host "Building darwin executable ..." -ForegroundColor Green
&{$CGO_ENABLED=0;$GOOS="darwin";$GOARCH="amd64"; go build -o bin/darwin/ergo}
}
if($build_linux_arm) {
Write-Host "Building linux executable for the arm platform ..." -ForegroundColor Green
&{$CGO_ENABLED=0;$GOOS="linux";$GOARCH="arm64"; go build -o bin/darwin/ergo}
}
if($build_linux_x64) {
Write-Host "Building linux executable for the 64 bit platform ..." -ForegroundColor Green
&{$CGO_ENABLED=0;$GOOS="linux";$GOARCH="amd64"; go build -o bin/ergo}
}
if($build){
Write-Host "Building windows executable ..." -ForegroundColor Green
build
}
if($clean){
Write-Host "Cleaning ..." -ForegroundColor Green
Remove-Item -Recurse -Force .\bin\*
}
if($test){
fmt
vet
lint
Write-Host "Running tests ..." -ForegroundColor Green
go test -v ./...
}
if($test_integration) {
Write-Host "Running integration tests ..." -ForegroundColor Green
build
go test -tags=integration -v ./...
}
if($bump_version){
bumpVersion
}
if($help){
showHelp
}
if($fmt){
fmt
}
if($vet){
vet
}
if($lint){
lint
}
if($tools){
tools
}
if(!$build -and !$build_darwin -and
!$build_linux_arm -and !$build_linux_x64 -and
!$bump_version -and !$start -and
!$test -and !$clean -and
!$test_integration -and !$help -and
!$vet -and !$fmt -and !$lint){
showHelp
}