Skip to content
Snippets Groups Projects
Commit 60a323ec authored by Jono Wenger's avatar Jono Wenger
Browse files

Add .gitlab-ci.yml

parent 164713da
No related branches found
No related tags found
No related merge requests found
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/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment