| 1 |
# To contribute improvements to CI/CD templates, please follow the Development guide at: |
| 2 |
# https://docs.gitlab.com/ee/development/cicd/templates.html |
| 3 |
# This specific template is located at: |
| 4 |
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Go.gitlab-ci.yml |
| 5 |
|
| 6 |
image: golang:trixie |
| 7 |
|
| 8 |
|
| 9 |
variables: |
| 10 |
# Please edit to your GitLab project |
| 11 |
REPO_NAME: salsa.debian.org/mdosch/go-sendxmpp |
| 12 |
|
| 13 |
# The problem is that to be able to use go get, one needs to put |
| 14 |
# the repository in the $GOPATH. So for example if your gitlab domain |
| 15 |
# is gitlab.com, and that your repository is namespace/project, and |
| 16 |
# the default GOPATH being /go, then you'd need to have your |
| 17 |
# repository in /go/src/gitlab.com/namespace/project |
| 18 |
# Thus, making a symbolic link corrects this. |
| 19 |
before_script: |
| 20 |
- mkdir -p $GOPATH/src/$(dirname $REPO_NAME) |
| 21 |
- ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME |
| 22 |
- cd $GOPATH/src/$REPO_NAME |
| 23 |
|
| 24 |
stages: |
| 25 |
- test |
| 26 |
- build |
| 27 |
- release |
| 28 |
|
| 29 |
format_and_static_test: |
| 30 |
# image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine |
| 31 |
stage: test |
| 32 |
before_script: |
| 33 |
- DEB_RELEASE=$(env -i bash -c '. /etc/os-release; echo $VERSION_CODENAME') |
| 34 |
- echo "deb https://deb.debian.org/debian/ $DEB_RELEASE-backports main" >> /etc/apt/sources.list |
| 35 |
- apt -qq update; apt -qq install -y codespell |
| 36 |
- go install mvdan.cc/gofumpt@latest |
| 37 |
- go install github.com/securego/gosec/v2/cmd/gosec@latest |
| 38 |
script: |
| 39 |
- go fmt $(go list ./... | grep -v /vendor/) |
| 40 |
- go vet $(go list ./... | grep -v /vendor/) |
| 41 |
- go test -race $(go list ./... | grep -v /vendor/) |
| 42 |
- codespell *.go *.md man/*.ronn |
| 43 |
- gofumpt -d . |
| 44 |
- gosec ./... |
| 45 |
- sh -c "! grep -r println *.go" |
| 46 |
# Taken from https://gitlab.com/gitlab-org/gitlab/-/merge_requests/20404/diffs#diff-content-8071267ea32ba69f24a8bd50bcbddf972c295ce3 |
| 47 |
# Use default .golangci.yml file from the image if one is not present in the project root. |
| 48 |
#- '[ -e .golangci.yml ] || cp /golangci/.golangci.yml .' |
| 49 |
#- golangci-lint run |
| 50 |
#allow_failure: true |
| 51 |
artifacts: |
| 52 |
expire_in: 1 year |
| 53 |
|
| 54 |
compile: |
| 55 |
stage: build |
| 56 |
only: |
| 57 |
- tags |
| 58 |
before_script: |
| 59 |
- DEB_RELEASE=$(env -i bash -c '. /etc/os-release; echo $VERSION_CODENAME') |
| 60 |
- echo "deb https://deb.debian.org/debian/ $DEB_RELEASE-backports main" >> /etc/apt/sources.list |
| 61 |
- apt -qq update; apt -qq install -y upx-ucl || true |
| 62 |
script: |
| 63 |
- echo "${CI_JOB_ID}" > CI_JOB_ID.txt |
| 64 |
- env GOOS=linux GOARCH=amd64 go build -buildmode=pie -ldflags "-s -w -extldflags '-static'" -o $CI_PROJECT_DIR/linux-amd64/go-sendxmpp |
| 65 |
- upx $CI_PROJECT_DIR/linux-amd64/go-sendxmpp || true |
| 66 |
- env GOOS=linux GOARCH=arm64 go build -buildmode=pie -ldflags "-s -w -extldflags '-static'" -o $CI_PROJECT_DIR/linux-arm64/go-sendxmpp |
| 67 |
- upx $CI_PROJECT_DIR/linux-arm64/go-sendxmpp || true |
| 68 |
- env GOOS=windows GOARCH=amd64 go build -buildmode=pie -ldflags "-s -w -extldflags '-static'" -o $CI_PROJECT_DIR/win64/go-sendxmpp.exe |
| 69 |
- upx $CI_PROJECT_DIR/win64/go-sendxmpp.exe || true |
| 70 |
artifacts: |
| 71 |
paths: |
| 72 |
- linux-amd64/go-sendxmpp |
| 73 |
- linux-arm64/go-sendxmpp |
| 74 |
- win64/go-sendxmpp.exe |
| 75 |
- CI_JOB_ID.txt |
| 76 |
expire_in: 2 years |
| 77 |
|
| 78 |
release: |
| 79 |
stage: release |
| 80 |
image: registry.gitlab.com/gitlab-org/release-cli:latest |
| 81 |
only: |
| 82 |
- tags |
| 83 |
script: |
| 84 |
- | |
| 85 |
release-cli create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG --description="`head -n $(expr "$(grep -nm2 "^## " CHANGELOG.md|awk '(NR>1) {print $1}'|cut -f1 -d:) - 2"|bc) CHANGELOG.md`" \ |
| 86 |
--assets-link "{\"name\":\"Linux amd64\",\"url\":\"https://salsa.debian.org/mdosch/go-sendxmpp/-/jobs/`cat CI_JOB_ID.txt`/artifacts/file/linux-amd64/go-sendxmpp\"}" \ |
| 87 |
--assets-link "{\"name\":\"Linux arm64\",\"url\":\"https://salsa.debian.org/mdosch/go-sendxmpp/-/jobs/`cat CI_JOB_ID.txt`/artifacts/file/linux-arm64/go-sendxmpp\"}" \ |
| 88 |
--assets-link "{\"name\":\"Windows amd64\",\"url\":\"https://salsa.debian.org/mdosch/go-sendxmpp/-/jobs/`cat CI_JOB_ID.txt`/artifacts/file/win64/go-sendxmpp.exe\"}" |
| 89 |
artifacts: |
| 90 |
expire_in: 2 years |