From 8589c18c5bdb4bab82edd29f695fee5092bcb806 Mon Sep 17 00:00:00 2001 From: Viktar Dubiniuk Date: Tue, 14 Jun 2022 01:51:15 +0300 Subject: [PATCH] Add initial gitlab config --- .gitlab-ci.yml | 34 ++++++++++++++++++++++++++++++++++ .gitlab/build-all.sh | 18 ++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 .gitlab/build-all.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..c9b0277 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,34 @@ +image: golang:latest + +variables: + REPO_NAME: gitlab.com/***/*** + +before_script: + - go version + - echo $CI_BUILD_REF + - echo $CI_PROJECT_DIR + +stages: + - test + - build + +test-project: + stage: test + script: + - mkdir -p $GOPATH/src/$REPO_NAME + - mv $CI_PROJECT_DIR/* $GOPATH/src/$REPO_NAME + - cd $GOPATH/src/$REPO_NAME + - go test $(go list ./... | grep -v /vendor/) + +build-project: + stage: build + script: + - OUTPUT="ouput" + - mkdir -p $GOPATH/src/$REPO_NAME + - mv $CI_PROJECT_DIR/* $GOPATH/src/$REPO_NAME/ + - cd $GOPATH/src/$REPO_NAME + - bash .gitlab/build-all.sh $OUTPUT $CI_PROJECT_DIR + + artifacts: + paths: + - artifacts/ diff --git a/.gitlab/build-all.sh b/.gitlab/build-all.sh new file mode 100644 index 0000000..0b7c440 --- /dev/null +++ b/.gitlab/build-all.sh @@ -0,0 +1,18 @@ +BIN_FILE_NAME_PREFIX=$1 +PROJECT_DIR=$2 +PLATFORMS=$(go tool dist list) +for PLATFORM in $PLATFORMS; do + GOOS=${PLATFORM%/*} + GOARCH=${PLATFORM#*/} + FILEPATH="$PROJECT_DIR/artifacts/${GOOS}-${GOARCH}" + #echo $FILEPATH + mkdir -p $FILEPATH + BIN_FILE_NAME="$FILEPATH/${BIN_FILE_NAME_PREFIX}" + #echo $BIN_FILE_NAME + if [[ "${GOOS}" == "windows" ]]; then BIN_FILE_NAME="${BIN_FILE_NAME}.exe"; fi + CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build -o ${BIN_FILE_NAME}" + #echo $CMD + echo "${CMD}" + eval $CMD || FAILURES="${FAILURES} ${PLATFORM}" +done +