diff --git a/development/script/go-compile.sh b/development/script/go-compile.sh new file mode 100755 index 0000000000000000000000000000000000000000..9ca022ad4740a92ba8ddbeafdd5dd744dc5b4318 --- /dev/null +++ b/development/script/go-compile.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +## +## $(QUIET) $(DEVELOPMENT_SCRIPTS_PATH)/go-compile.sh $(SOURCE_PATH) $(BUILD_PATH) $(COMPONENT_SLUG) $(GO_RELEASE_PACKAGE_NAME) $(PROJECT_VERSION) $(PROJECT_BUILD_DATE) + +SOURCE_PATH=$1 +BUILD_PATH=$2 +COMPONENT_SLUG=$3 +GO_RELEASE_PACKAGE_NAME=$4 +PROJECT_VERSION=$5 +PROJECT_BUILD_DATE=$6 +platforms=$(go tool dist list) + +included_os=("linux" "windows") + +# define a list of excluded architectures +included_arch=("amd64" "arm64") + +cd $SOURCE_PATH || exit 1 + +# Run and build loop through all platforms (except excluded ones) +for platform in $platforms; do + + # GOOS und GOARCH Variablen setzen + export GOOS=$(echo $platform | cut -d'/' -f1) + export GOARCH=$(echo $platform | cut -d'/' -f2) + + if [[ ! "${included_os[@]}" =~ "$GOOS" ]]; then + echo "Skipping excluded platform: $GOOS" + continue + fi + + if [[ ! "${included_arch[@]}" =~ "$GOARCH" ]]; then + echo "Skipping excluded architecture: $GOARCH" + continue + fi + + echo "============================================" + echo "Building for $GOOS/$GOARCH" + + output_name=$BUILD_PATH$COMPONENT_SLUG-$GOOS-$GOARCH + if [ $GOOS = "windows" ]; then + output_name+='.exe' + fi + + env GO111MODULE=on GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-X $GO_RELEASE_PACKAGE_NAME.version=$PROJECT_VERSION -X $GO_RELEASE_PACKAGE_NAME.build=$PROJECT_BUILD_DATE" -o $output_name + if [ $? -ne 0 ]; then + echo "An error has occurred! $output_name build failed." + echo "============================================" + fi +done + +cd - || exit 1 diff --git a/development/script/go-coverage.sh b/development/script/go-coverage.sh new file mode 100755 index 0000000000000000000000000000000000000000..405ffb6947f23991b925222f6477616c67c68423 --- /dev/null +++ b/development/script/go-coverage.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# Code coverage generation + +COVERAGE_DIR="${1}" +REPORT_DIR="${2}" +TYPE="${3}" + +cd "$COVERAGE_DIR" || exit 1 +PKG_LIST=$(go list ./... | grep -v /vendor/) + +# Create the coverage files directory +mkdir -p "$REPORT_DIR"; + +# Create a coverage file for each package +for package in ${PKG_LIST}; do + go test -covermode=count -coverprofile "${REPORT_DIR}/${package##*/}.cov" "$package" ; +done ; + +# Merge the coverage profile files +echo 'mode: count' > "${REPORT_DIR}"/coverage.cov ; +tail -q -n +2 "${REPORT_DIR}"/*.cov >> "${REPORT_DIR}"/coverage.cov ; + +# Display the global code coverage +go tool cover -func="${REPORT_DIR}"/coverage.cov ; + +# If needed, generate HTML report +if [ "$TYPE" == "html" ]; then + go tool cover -html="${REPORT_DIR}"/coverage.cov -o "${REPORT_DIR}/"coverage.html ; +fi + +rm -rf ${REPORT_DIR}"/"*.cov + +# Remove the coverage files directory +cd - || exit 1