Improve CI/CD setup

This commit is contained in:
Maurizio Porrato 2021-05-15 20:23:00 +01:00
parent c1049eb48e
commit 6df602fa6b
Signed by: guru
GPG Key ID: C622977DF024AC24
1 changed files with 32 additions and 8 deletions

View File

@ -2,28 +2,52 @@ image: golang:latest
variables:
REPO_NAME: gitlab.com/mporrato/uBrowserSync
CMDS: "ubsserver"
PLATFORMS: "linux/amd64 linux/arm64 linux/armv6"
before_script:
- mkdir -p $GOPATH/src/$(dirname $REPO_NAME)
- ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME
- mkdir -p $CI_PROJECT_DIR/bin
- cd $GOPATH/src/$REPO_NAME
- go version
stages:
- lint
- test
- build
format:
go-vet:
stage: lint
script:
- go vet $(go list ./... | grep -v /vendor/)
go-test:
stage: test
script:
- go fmt $(go list ./... | grep -v /vendor/)
- go vet $(go list ./... | grep -v /vendor/)
- go test -race $(go list ./... | grep -v /vendor/)
compile:
go-build:
stage: build
script:
- mkdir -p $CI_PROJECT_DIR/bin
- go build -o $CI_PROJECT_DIR/bin/ubsserver -v -ldflags="-s -w" -trimpath ./cmd/ubsserver
script: |
for platform in $PLATFORMS ; do
echo "BUILDING $platform"
IFS="/" read GOOS GOARCH <<< "$platform"
case $GOARCH in
armv*)
GOARM=$(tr -cd "0-9" <<< $GOARCH)
GOARCH=arm
SUFFIX="$GOOS-${GOARCH}v$GOARM"
;;
*)
SUFFIX="$GOOS-$GOARCH"
;;
esac
export GOOS GOARCH
for bin in $CMDS ; do
go build -ldflags="-s -w" -trimpath -o bin/$bin-$SUFFIX ./cmd/$bin
done
done
artifacts:
paths:
- bin/ubsserver
- bin/