From 60a323eccb4e6258b82314b5f9bc07fcd59432c5 Mon Sep 17 00:00:00 2001 From: Jono Wenger <jono@elixxir.io> Date: Mon, 19 Sep 2022 10:30:42 -0700 Subject: [PATCH] Add .gitlab-ci.yml --- .gitlab-ci.yml | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..526aeab --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,63 @@ +before_script: + - go version || echo "Go executable not found." + - echo $CI_BUILD_REF + - echo $CI_PROJECT_DIR + - echo $PWD + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - ssh-keyscan -t rsa $GITLAB_SERVER > ~/.ssh/known_hosts + - rm -rf ~/.gitconfig + - git config --global url."git@$GITLAB_SERVER:".insteadOf "https://gitlab.com/" + - git config --global url."git@$GITLAB_SERVER:".insteadOf "https://git.xx.network/" --add + - export PATH=$HOME/go/bin:$PATH + +stages: + - test + - build + +test: + stage: test + image: $DOCKER_IMAGE + except: + - tags + script: + - git clean -ffdx + - go mod vendor -v + - go build ./... + - go mod tidy + - mkdir -p testdata + + # Test coverage + - go-acc --covermode atomic --output testdata/coverage.out ./... -- -v + # Exclude some specific packages and files + - cat testdata/coverage.out | grep -v cmd | grep -v mockserver | grep -v pb[.]go | grep -v main.go > testdata/coverage-real.out + - go tool cover -func=testdata/coverage-real.out + - go tool cover -html=testdata/coverage-real.out -o testdata/coverage.html + + # Test Coverage Check + - go tool cover -func=testdata/coverage-real.out | grep "total:" | awk '{print $3}' | sed 's/\%//g' > testdata/coverage-percentage.txt + - export CODE_CHECK=$(echo "$(cat testdata/coverage-percentage.txt) >= $MIN_CODE_COVERAGE" | bc -l) + - (if [ "$CODE_CHECK" == "1" ]; then echo "Minimum coverage of $MIN_CODE_COVERAGE succeeded"; else echo "Minimum coverage of $MIN_CODE_COVERAGE failed"; exit 1; fi); + artifacts: + paths: + - vendor/ + - testdata/ + +build: + stage: build + image: $DOCKER_IMAGE + except: + - tags + script: + - go mod vendor -v + - make version + - mkdir -p release + - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/cli-client.linux64 main.go + - GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/cli-client.win64 main.go + - GOOS=windows GOARCH=386 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/cli-client.win32 main.go + - GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/cli-client.darwin64 main.go + artifacts: + paths: + - release/ -- GitLab