mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-09-10 10:31:46 +00:00
feat: build scripts auto get app version & commit from git
This commit is contained in:
15
build.ps1
15
build.ps1
@@ -10,13 +10,28 @@ if (!(Get-Command go -ErrorAction SilentlyContinue)) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
if (!(Get-Command git -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "Error: git is not installed." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
if (!(git rev-parse --is-inside-work-tree 2>$null)) {
|
||||
Write-Host "Error: not in a git repository." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
$ldflags = "-s -w -X 'main.appDate=$(Get-Date -Format "yyyy-MM-dd HH:mm:ss")'"
|
||||
if ($env:HY_APP_VERSION) {
|
||||
$ldflags += " -X 'main.appVersion=$($env:HY_APP_VERSION)'"
|
||||
}
|
||||
else {
|
||||
$ldflags += " -X 'main.appVersion=$(git describe --tags --always)'"
|
||||
}
|
||||
if ($env:HY_APP_COMMIT) {
|
||||
$ldflags += " -X 'main.appCommit=$($env:HY_APP_COMMIT)'"
|
||||
}
|
||||
else {
|
||||
$ldflags += " -X 'main.appCommit=$(git rev-parse HEAD)'"
|
||||
}
|
||||
|
||||
if ($env:HY_APP_PLATFORMS) {
|
||||
$platforms = $env:HY_APP_PLATFORMS.Split(",")
|
||||
|
13
build.sh
13
build.sh
@@ -11,12 +11,25 @@ if ! [ -x "$(command -v go)" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! [ -x "$(command -v git)" ]; then
|
||||
echo 'Error: git is not installed.' >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
echo 'Error: not in a git repository.' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ldflags="-s -w -X 'main.appDate=$(date -u '+%F %T')'"
|
||||
if [ -n "$HY_APP_VERSION" ]; then
|
||||
ldflags="$ldflags -X 'main.appVersion=$HY_APP_VERSION'"
|
||||
else
|
||||
ldflags="$ldflags -X 'main.appVersion=$(git describe --tags --always)'"
|
||||
fi
|
||||
if [ -n "$HY_APP_COMMIT" ]; then
|
||||
ldflags="$ldflags -X 'main.appCommit=$HY_APP_COMMIT'"
|
||||
else
|
||||
ldflags="$ldflags -X 'main.appCommit=$(git rev-parse HEAD)'"
|
||||
fi
|
||||
|
||||
if [ -z "$HY_APP_PLATFORMS" ]; then
|
||||
|
Reference in New Issue
Block a user