forked from deweizhu/bookget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
70 lines (54 loc) · 1.55 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
# 获取日期格式化的版本号
$ver = $( Get-Date -Format "yy.MMdd" )
function setVersion
{
$filePath = "config/init.go"
$tempFilePath = "$filePath.tmp"
# 读取文件内容
$fileContent = Get-Content -Path $filePath -Raw
# 使用正则表达式替换版本号
$pattern = 'const version = "[^"]*"'
$replacement = "const version = `"$ver`""
$updatedContent = [regex]::Replace($fileContent, $pattern, $replacement)
# 将更新后的内容写入临时文件
$updatedContent | Set-Content -Path $tempFilePath
# 覆盖原文件
Move-Item -Path $tempFilePath -Destination $filePath -Force
Write-Output "版本号已替换为: $ver"
}
setVersion $ver
# 配置 GOPROXY 环境变量
$env:GOPROXY = "https://goproxy.cn,direct"
go mod tidy
go mod download
function BuildAndPackageWin
{
$ENV:CGO_ENABLED = 0
$ENV:GOOS = "windows"
$ENV:GOARCH = "amd64"
$target = "target/bookget-$ver.$ENV:GOOS-$ENV:GOARCH"
mkdir -Force $target
go build -o "$target/bookget.exe" .
}
function BuildAndPackageLinux
{
$ENV:CGO_ENABLED = 0
$ENV:GOOS = "linux"
$ENV:GOARCH = "amd64"
$target = "target/bookget-$ver.$ENV:GOOS-$ENV:GOARCH"
mkdir -Force $target
go build -o "$target/bookget" .
}
function BuildAndPackageDarwin
{
$ENV:CGO_ENABLED = 0
$ENV:GOOS = "darwin"
$ENV:GOARCH = "arm64"
$target = "target/bookget-$ver.$ENV:GOOS-$ENV:GOARCH"
mkdir -Force $target
go build -o "$target/bookget" .
}
# 调用函数
BuildAndPackageWin
BuildAndPackageLinux
BuildAndPackageDarwin