-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.ps1
More file actions
executable file
·186 lines (154 loc) · 5.27 KB
/
build.ps1
File metadata and controls
executable file
·186 lines (154 loc) · 5.27 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
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
176
177
178
179
180
181
182
183
184
185
186
<#
.SYNOPSIS
PowerShell script for testing, building, and deploying the experiment.
#>
$PROJECT = "dataset"
$GIT_GROUP = "caltechlibrary"
$RELEASE_DATE = Get-Date -Format "yyyy-MM-dd"
$RELEASE_HASH = git log --pretty=format:'%h' -n 1
$BRANCH = git rev-parse --abbrev-ref HEAD
# Determine the version from codemeta.json
$VERSION = jq -r '.version' codemeta.json
$MAN_PAGES = @("dataset.1", "datasetd.1", "dsquery.1", "dsimporter.1")
$MAN_PAGES_MISC = @("datasetd_yaml.5", "datasetd_service.5", "datasetd_api.5")
$PROGRAMS = @("dataset", "datasetd", "dsquery", "dsimporter")
$PREFIX = $HOME
$EXT = if ($IsWindows) { ".exe" } else { "" }
$EXT_WEB = ".wasm"
$DIST_FOLDERS = "bin/*", "man/*"
function Invoke-Build {
# Build version.go
cmt codemeta.json version.go
git add version.go
# Build programs
foreach ($program in $PROGRAMS) {
New-Item -ItemType Directory -Path "bin" -Force | Out-Null
go build -o "bin/$program$EXT" "cmd/$program/$program.go"
& "./bin/$program" "-help" | Out-File "$program.1.md"
}
# Build man pages
foreach ($manPage in $MAN_PAGES) {
New-Item -ItemType Directory -Path "man/man1" -Force | Out-Null
pandoc "$manPage.md" --from markdown --to man -s | Out-File "man/man1/$manPage"
}
foreach ($manPageMisc in $MAN_PAGES_MISC) {
New-Item -ItemType Directory -Path "man/man5" -Force | Out-Null
pandoc "$manPageMisc.md" --from markdown --to man -s | Out-File "man/man5/$manPageMisc"
}
# Build CITATION.cff and about.md
cmt codemeta.json CITATION.cff
cmt codemeta.json about.md
# Build installer scripts
cmt codemeta.json installer.sh
#chmod 775 installer.sh
git add -f installer.sh
cmt codemeta.json installer.ps1
#chmod 775 installer.ps1
git add -f installer.ps1
}
function Invoke-Install {
if (-not (Test-Path "$PREFIX/bin")) {
New-Item -ItemType Directory -Path "$PREFIX/bin" -Force | Out-Null
}
Write-Output "Installing programs in $PREFIX/bin"
foreach ($program in $PROGRAMS) {
if (Test-Path "./bin/$program") {
Move-Item -Path "./bin/$program" -Destination "$PREFIX/bin/$program" -Force -Verbose
}
}
Write-Output "Make sure $PREFIX/bin is in your PATH"
foreach ($manPage in $MAN_PAGES) {
if (Test-Path "./man/man1/$manPage") {
Copy-Item -Path "./man/man1/$manPage" -Destination "$PREFIX/man/man1/$manPage" -Force -Verbose
}
}
Write-Output "Make sure $PREFIX/man is in your MANPATH"
}
function Invoke-Uninstall {
Write-Output "Removing programs in $PREFIX/bin"
foreach ($program in $PROGRAMS) {
if (Test-Path "$PREFIX/bin/$program") {
Remove-Item -Path "$PREFIX/bin/$program" -Force -Verbose
}
}
Write-Output "Removing manpages in $PREFIX/man"
foreach ($manPage in $MAN_PAGES) {
if (Test-Path "$PREFIX/man/man1/$manPage") {
Remove-Item -Path "$PREFIX/man/man1/$manPage" -Force -Verbose
}
}
}
function Invoke-Check {
go vet *.go
Get-ChildItem -Directory | ForEach-Object {
if (Test-Path "$_/*.go") {
Push-Location $_
go vet *.go
Pop-Location
}
}
}
function Invoke-Test {
go test
}
function Invoke-Clean {
go clean
Remove-Item -Path "bin" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "dist" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "testout" -Recurse -Force -ErrorAction SilentlyContinue
Get-ChildItem -Directory | ForEach-Object {
Remove-Item -Path "$_/testout" -Recurse -Force -ErrorAction SilentlyContinue
}
go clean -r
}
function Invoke-Dist {
param($os, $arch, $suffix)
$distPath = "dist/bin"
New-Item -ItemType Directory -Path $distPath -Force | Out-Null
foreach ($program in $PROGRAMS) {
$env:GOOS = $os
$env:GOARCH = $arch
go build -o "$distPath/$program$EXT" "cmd/$program/*.go"
}
Push-Location dist
zip -r "${PROJECT}-v${VERSION}-${suffix}.zip" LICENSE codemeta.json CITATION.cff *.md $DIST_FOLDERS
Pop-Location
Remove-Item -Path $distPath -Recurse -Force
}
function Invoke-DistributeDocs {
Remove-Item -Path "dist" -Recurse -Force -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Path "dist" -Force | Out-Null
Copy-Item -Path "codemeta.json", "CITATION.cff", "README.md", "LICENSE", "INSTALL.md", "installer.sh", "installer.ps1" -Destination "dist" -Verbose
Copy-Item -Path "man" -Destination "dist" -Recurse -Verbose
}
function Invoke-Release {
Invoke-Clean
Invoke-Build
Invoke-Dist "linux" "amd64" "Linux-x86_64"
Invoke-Dist "linux" "arm64" "Linux-aarch64"
Invoke-Dist "linux" "arm" "Linux-armv7l"
Invoke-Dist "windows" "amd64" "Windows-x86_64"
Invoke-Dist "windows" "arm64" "Windows-arm64"
Invoke-Dist "darwin" "amd64" "macOS-x86_64"
Invoke-Dist "darwin" "arm64" "macOS-arm64"
.\release.ps1
}
function Invoke-Status {
git status
}
function Invoke-Save {
param([string]$msg = "Quick Save")
git commit -am $msg
git push origin $BRANCH
}
function Invoke-Publish {
.\publish.ps1
}
function Invoke-LogHash {
git log --pretty=format:'%h' -n 1
}
# Example usage:
# Invoke-Build
# Invoke-Install
# Invoke-Test
Invoke-Build