Skip to content
Snippets Groups Projects
Verified Commit cf42e31e authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: new compile scripts

parent 1e625bde
Branches
Tags
No related merge requests found
#!/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
#!/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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment