-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
executable file
·29 lines (21 loc) · 1.07 KB
/
Copy pathbuild.ps1
File metadata and controls
executable file
·29 lines (21 loc) · 1.07 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
#! /usr/bin/env pwsh
$MyPath = Split-Path $MyInvocation.MyCommand.Definition
$BinDir = if (!$env:BINARY_OUTDIR) { "bin" } else { $env:BINARY_OUTDIR }
$MyProject = if (!$env:CI_REPOSITORY_NAME_SLUG) { $(Get-Item $MyPath).BaseName } else { $env:CI_REPOSITORY_NAME_SLUG }
$BuildArch = if (!$env:BUILD_ARCH) { ((& go tool dist list) -match '^(darwin|linux|windows)/(arm|arm64|386|amd64)$') -join ',' } else { $env:BUILD_ARCH }
if (!(Test-Path $MyPath/$BinDir)) { New-Item -Path $MyPath/$BinDir -ItemType Directory | Out-Null }
if (!$env:SRC_DIR) { Push-Location $MyPath } else { Push-Location $MyPath/$env:SRC_DIR }
& go get .
foreach ($g in $BuildArch.Split(',')) {
$env:GOOS = $g.split('/')[0]
$env:GOARCH = $g.split('/')[1]
if ($env:GOOS -eq "windows") { $Ext = ".exe" } else { $Ext = $null }
try {
Write-Host "Building: ${env:GOOS} (${env:GOARCH})"
& go build -ldflags="-s -w" -o "${MyPath}/${BinDir}/${MyProject}-${env:GOOS}-${env:GOARCH}${Ext}"
}
catch {
Write-Warning ("Build Failed:`r`n" + $_.Exception.Message)
}
}
Pop-Location