mirror of
https://github.com/AthanorLabs/atomic-swap.git
synced 2026-01-07 21:34:05 -05:00
multi-arch build script and version fixes (#435)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@
|
||||
|
||||
# Generated binaries
|
||||
/bin/
|
||||
/release-bin/
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
@@ -99,8 +99,8 @@ func GetVersion() string {
|
||||
return "unknown-version"
|
||||
}
|
||||
|
||||
commitHash := "???????"
|
||||
dirty := ""
|
||||
commitHash := ""
|
||||
sourcesModified := false
|
||||
|
||||
for _, setting := range info.Settings {
|
||||
switch setting.Key {
|
||||
@@ -108,17 +108,33 @@ func GetVersion() string {
|
||||
commitHash = setting.Value
|
||||
case "vcs.modified":
|
||||
if setting.Value == "true" {
|
||||
dirty = "-dirty"
|
||||
sourcesModified = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s %.7s%s-%s",
|
||||
info.Main.Version, // " (devel)" unless passing a git tagged version to `go install`
|
||||
commitHash, // 7 bytes is what "git rev-parse --short HEAD" returns
|
||||
dirty, // add "-dirty" to commit hash if repo was not clean
|
||||
info.GoVersion,
|
||||
)
|
||||
var version strings.Builder
|
||||
|
||||
// The first part a go.mod style version if using "go install" directly with
|
||||
// github. If installing from locally checked out source, the string will be
|
||||
// "(devel)".
|
||||
version.WriteString(info.Main.Version)
|
||||
version.WriteByte(' ')
|
||||
|
||||
// The commit hash will be present if installing from locally checked out
|
||||
// sources, or empty if installing directly from the repo's github URL.
|
||||
if commitHash != "" {
|
||||
// 7 bytes is what "git rev-parse --short HEAD" returns
|
||||
version.WriteString(fmt.Sprintf("%.7s", commitHash))
|
||||
if sourcesModified {
|
||||
version.WriteString("-dirty")
|
||||
}
|
||||
}
|
||||
|
||||
version.WriteByte('-')
|
||||
version.WriteString(info.GoVersion)
|
||||
|
||||
return version.String()
|
||||
}
|
||||
|
||||
// ReadUnsignedDecimalFlag reads a string flag and parses it into an *apd.Decimal.
|
||||
|
||||
60
scripts/release-build.sh
Executable file
60
scripts/release-build.sh
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Fail script on any error (do not change)
|
||||
set -e
|
||||
|
||||
PROJECT_ROOT="$(dirname "$(dirname "$(realpath "$0")")")"
|
||||
cd "${PROJECT_ROOT}"
|
||||
|
||||
# Make sure no one is sourcing the script, as we export variables
|
||||
if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
|
||||
echo "Execute ${BASH_SOURCE[0]} instead of souring it"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
version="HEAD" # use "latest" for most recent tagged release
|
||||
install_targets=(
|
||||
"github.com/athanorlabs/atomic-swap/cmd/swapd@${version}"
|
||||
"github.com/athanorlabs/atomic-swap/cmd/swapcli@${version}"
|
||||
"github.com/athanorlabs/atomic-swap/cmd/bootnode@${version}"
|
||||
)
|
||||
|
||||
# turn on echo
|
||||
set -x
|
||||
|
||||
dest_dir=release-bin
|
||||
rm -rf "${dest_dir}"
|
||||
mkdir "${dest_dir}"
|
||||
|
||||
# Note: We don't bother with static builds (larger binaries) as swapd depends on
|
||||
# a local monero-wallet-rpc binary and all releases of monero-wallet-rpc depend
|
||||
# on glibc.
|
||||
unset CGO_ENABLED
|
||||
|
||||
# Unfortunately, GOBIN can't be set when doing cross platform builds and
|
||||
# go install doesn't take an -o flag:
|
||||
# https://github.com/golang/go/issues/57485
|
||||
# We are inside a go module project right now and we'll confuse tooling
|
||||
# if we put the GOPATH inside of the project. We are using "go install",
|
||||
# so nothing will go wrong even if a go.mod exists at the top of /tmp.
|
||||
build_dir="$(mktemp -d /tmp/release-build-XXXXXXXXXX)"
|
||||
|
||||
for os in linux darwin; do
|
||||
for arch in amd64 arm64; do
|
||||
GOPATH="${build_dir}" GOOS="${os}" GOARCH="${arch}" \
|
||||
go install -tags=prod "${install_targets[@]}"
|
||||
from_dir="${build_dir}/bin/${os}_${arch}"
|
||||
to_dir="${dest_dir}/${os/darwin/macos}-${arch/amd64/x64}"
|
||||
if [[ -d "${from_dir}" ]]; then
|
||||
# non-native binaries
|
||||
mv "${from_dir}" "${to_dir}"
|
||||
else
|
||||
# native binaries
|
||||
mkdir "${to_dir}"
|
||||
mv "${build_dir}/bin/"* "${to_dir}"
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
chmod -R u+w "${build_dir}"
|
||||
rm -rf "${build_dir}"
|
||||
Reference in New Issue
Block a user