Add build helpers and improve configuration example.
This commit is contained in:
30
scripts/build.sh
Executable file
30
scripts/build.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script is using for building release binaries.
|
||||
|
||||
OSES=("darwin" "linux" "windows")
|
||||
ARCHES=("amd64" "arm64")
|
||||
|
||||
GO=$(which go)
|
||||
if [ "${GO}" == "" ]; then
|
||||
echo "Golang is not installed, cannot continue"
|
||||
fi
|
||||
|
||||
if [ ! -d "release" ]; then
|
||||
mkdir -p release
|
||||
fi
|
||||
|
||||
for OS in "${OSES[@]}"; do
|
||||
for ARCH in "${ARCHES[@]}"; do
|
||||
echo "Building for ${OS} ${ARCH}..."
|
||||
CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH} go build -o release/periodicator-${OS}-${ARCH} .
|
||||
done
|
||||
done
|
||||
|
||||
for file in release/*windows*; do
|
||||
mv ${file} ${file}.exe
|
||||
done
|
||||
|
||||
for file in release/*; do
|
||||
zip -m ${file}.zip ${file}
|
||||
done
|
45
scripts/get_version.sh
Executable file
45
scripts/get_version.sh
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This is a branch helper script that can be used to determine what we're using
|
||||
# or deploying.
|
||||
# Defaulting to version 0.1.0 if we can't get version in any other way.
|
||||
|
||||
# We might already have version file (e.g. this script was launched with "generate"
|
||||
# parameter when building a Docker image). In that case - just output it.
|
||||
if [ -f "version" ]; then
|
||||
cat version
|
||||
exit 0
|
||||
fi
|
||||
|
||||
DELIMITER=" "
|
||||
VERSION="0.1.0"
|
||||
|
||||
# Try to get last available version tag. This tag will replace version if found.
|
||||
TAG=$(git tag | tail -n 1)
|
||||
if [ "${TAG}" != "" ]; then
|
||||
VERSION="${TAG}"
|
||||
fi
|
||||
|
||||
# We should figure out should we add branch or not. For that we should take
|
||||
# last commit hash and last tag hash for comparison. We should add branch
|
||||
# name only if hashes aren't same.
|
||||
LAST_COMMIT_HASH=$(git log --format="%h" 2>/dev/null | head -n 1)
|
||||
LAST_TAG_COMMIT_HASH=$(git log "${TAG}" --format="%h" 2>/dev/null | head -n 1)
|
||||
if [ "${LAST_COMMIT_HASH}" != "${LAST_TAG_COMMIT_HASH}" ]; then
|
||||
VERSION+="${DELIMITER}$(git branch | grep "*" | awk {' print $2 '})"
|
||||
fi
|
||||
|
||||
# Add commit hash.
|
||||
VERSION+="${DELIMITER}${LAST_COMMIT_HASH}"
|
||||
|
||||
# Add build date.
|
||||
VERSION+="${DELIMITER}$(date +'%Y%m%d-%H%M')"
|
||||
|
||||
case $1 in
|
||||
generate)
|
||||
echo "${VERSION}" > version
|
||||
;;
|
||||
*)
|
||||
echo "${VERSION}"
|
||||
;;
|
||||
esac
|
Reference in New Issue
Block a user