Skip to content

Instantly share code, notes, and snippets.

@ptflp
Last active October 13, 2022 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptflp/83d8bfe50351dbfcd499b760cf6b7138 to your computer and use it in GitHub Desktop.
Save ptflp/83d8bfe50351dbfcd499b760cf6b7138 to your computer and use it in GitHub Desktop.
Kata Golang gitalb CI/CD
# This file is a template, and might need editing before it works on your project.
image: golang:latest
variables:
# Please edit to your GitLab project
REPO_NAME: gitlab.com/ptflp/go-kata
GIT_DEPTH: 10
stages:
- lint
- test
- build
.go-cache:
before_script:
- mkdir -p $GOPATH/src/$(dirname $REPO_NAME)
- ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME
- cd $GOPATH/src/$REPO_NAME
- go mod download -json
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.49.0
- golangci-lint --version
cache:
key: "$CI_COMMIT_REF_SLUG"
paths:
- $GOPATH
lint:
stage: lint
extends: .go-cache
script:
- go fmt $(go list ./... | grep -v /vendor/)
- go vet $(go list ./... | grep -v /vendor/)
- golangci-lint run --skip-dirs docs
test:
stage: test
extends: .go-cache
script:
- go test -race $(go list ./... | grep -v /vendor/)
compile:
stage: build
extends: .go-cache
script:
- go build -race -ldflags "-extldflags '-static'" -o $CI_PROJECT_DIR/app
artifacts:
paths:
- app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment