.gitlab-ci.yml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. ###################### Begin Defaults
  2. stages:
  3. - all
  4. variables:
  5. GIT_DEPTH: 0
  6. GIT_STRATEGY: clone
  7. default:
  8. before_script:
  9. - |
  10. # before_script
  11. echo "Starting before_script actions."
  12. echo "Finished before_script actions."
  13. after_script:
  14. - |
  15. # after_script
  16. echo "Starting after_script actions."
  17. echo "Finished after_script actions."
  18. ###################### End Defaults
  19. ###################### Begin Common Blocks
  20. .scriptCommon: &scriptCommon |
  21. # scriptCommon
  22. echo "Project Name : $CI_PROJECT_TITLE"
  23. echo "Project Git Commit : $CI_COMMIT_SHA"
  24. echo "Project Git Branch : $CI_COMMIT_BRANCH"
  25. echo "GitLab CI User Details : $GITLAB_USER_LOGIN - $GITLAB_USER_NAME ($GITLAB_USER_ID) $GITLAB_USER_EMAIL"
  26. echo "GitLab CI Job Name : $CI_JOB_NAME"
  27. echo "GitLab CI Job ID : $CI_JOB_ID"
  28. echo "GitLab CI Job Stage : $CI_JOB_STAGE"
  29. echo "GitLab CI Runner Details : $CI_RUNNER_VERSION ($CI_RUNNER_REVISION)"
  30. .scriptGoVersion: &scriptGoVersion |
  31. # scriptGoVersion
  32. echo "Go Compiler Version:"
  33. go version
  34. echo "Go Default Environment:"
  35. go env
  36. echo "Go Current Environment:"
  37. go tool dist env -p
  38. .scriptGitPre: &scriptGitPre |
  39. # scriptGitPre
  40. git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
  41. git --no-pager fetch --tags
  42. git --no-pager fetch --all --recurse-submodules=yes
  43. git --no-pager update-index -q --refresh --really-refresh
  44. git --no-pager for-each-ref --count=1
  45. git --no-pager reset --hard
  46. git --no-pager diff --full-index --exit-code
  47. ###################### End Common Blocks
  48. ###################### Begin Windows Build + Test
  49. windows job:
  50. tags:
  51. - Windows-x86_64
  52. stage: all
  53. script:
  54. - *scriptCommon
  55. - $env:Path += ";C:\Program Files\Git\cmd;C:\Go\bin"
  56. - $env:GO111MODULE="on"
  57. - $env:GOPROXY="https://gocenter.io,https://proxy.golang.org,direct"
  58. - $env:CGO_ENABLED="0"
  59. - *scriptGoVersion
  60. - go clean -modcache -cache -r
  61. - *scriptGitPre
  62. - go build -v -a -trimpath .\...
  63. - |
  64. # status
  65. echo "Build completed successfully - running tests; coverage and race detector enabled"
  66. echo "TODO: Port of 'cov_report.sh' to PowerShell"
  67. - $env:CGO_ENABLED="1"
  68. - go test -v -cover -covermode="atomic" -race -tags="leaktest" -count="1" -cpu="1" -bench="." -parallel="1" .\...
  69. ###################### End Windows Build + Test
  70. ###################### Begin Linux
  71. linux job:
  72. tags:
  73. - Linux-x86_64
  74. stage: all
  75. script:
  76. - *scriptCommon
  77. - |
  78. # upgrade system, install development tools
  79. - yum install dnf -y
  80. - yum clean all -y
  81. - dnf upgrade --refresh -y
  82. - dnf groupinstall "Development Tools" -y
  83. - dnf install epel-release centos-release-scl centos-release-scl-rh -y
  84. - dnf install ccache pv valgrind graphviz clang zsh scl-utils devtoolset-9 -y
  85. - dnf groupupdate base -y
  86. - source /opt/rh/devtoolset-9/enable
  87. - dnf clean all -y
  88. - |
  89. # gimme go stable (latest release)
  90. bash --norc --noprofile --posix -o pipefail -c "set -e && mkdir -p /tools/bin && curl -fsSL -o /tools/bin/gimme https://raw.githubusercontent.com/travis-ci/gimme/master/gimme && chmod a+x /tools/bin/gimme"
  91. bash --norc --noprofile --posix -o pipefail -c "set -e && mkdir -p /tools/gimme && GIMME_SILENT_ENV=1 GIMME_ENV_PREFIX=/tools/gimme/env GIMME_VERSION_PREFIX=/tools/gimme/ver GIMME_GO_VERSION=stable GIMME_CGO_ENABLED=1 /tools/bin/gimme" > /tools/genv && source /tools/genv
  92. - source /tools/genv
  93. - go env -w GO111MODULE=on && export GO111MODULE=on
  94. - export GOPROXY="https://proxy.golang.org,direct" && go env -w GOPROXY="${GOPROXY:?}"
  95. - *scriptGoVersion
  96. - go clean -modcache -cache -r -x
  97. - *scriptGitPre
  98. - CGO_ENABLED=0 go build -v -a -trimpath $(go list ./... | grep -v test | sort | uniq)
  99. - |
  100. # status
  101. echo "Build completed successfully - running tests; coverage and race detector enabled"
  102. echo "TODO: Use 'cov_report.sh'"
  103. - CGO_ENABLED=1 go test -v -a -cover -covermode=atomic -race -tags="leaktest" -count=1 -cpu=1 -bench=. -parallel=1 $(go list ./... | grep -v test | sort | uniq)
  104. ###################### End Linux Build + Test
  105. ###################### Begin macOS Build + Test
  106. macos job:
  107. tags:
  108. - macOS_X-x86_64
  109. stage: all
  110. script:
  111. - |
  112. # update tools
  113. bash --norc --noprofile --posix -c "brew update || true" || true
  114. bash --norc --noprofile --posix -c "brew upgrade || true" || true
  115. - *scriptCommon
  116. - if type brew >/dev/null 2>&1; then export HOMEBREW_PREFIX=$(brew --prefix 2>/dev/null); for dir in ${HOMEBREW_PREFIX:?}/opt/*/libexec/gnubin; do export PATH="${dir:?}:${PATH:?}"; done; fi
  117. - export PATH="/usr/local/opt/gcc/bin:${PATH:?}"
  118. - go env -w GO111MODULE=on && export GO111MODULE=on
  119. - export GOPROXY="https://proxy.golang.org,direct" && go env -w GOPROXY="${GOPROXY:?}"
  120. - export PRIVPATH=$(mktemp -d "${HOME:?}/.XXXXXXXXXXXXXXXX")
  121. - export NEW_GOPATH=$(mktemp -d "${PRIVPATH:?}/XXXXXXXXXXXXXXXX")
  122. - export NEW_GOCACHE=$(mktemp -d "${PRIVPATH:?}/XXXXXXXXXXXXXXXX")
  123. - export NEW_GOMODCACHE=$(mktemp -d "${PRIVPATH:?}/XXXXXXXXXXXXXXXX")
  124. - export GOPATH="${NEW_GOPATH:?}" && go env -w GOPATH="${NEW_GOPATH:?}"
  125. - export GOCACHE="${NEW_GOCACHE:?}" && go env -w GOCACHE="${NEW_GOCACHE:?}"
  126. - export GOMODCACHE="${NEW_GOMODCACHE:?}" && go env -w GOMODCACHE="${NEW_GOMODCACHE:?}"
  127. - *scriptGoVersion
  128. - go clean -testcache -modcache -cache -r -x
  129. - *scriptGitPre
  130. - CGO_ENABLED=0 go build -v -a -trimpath $(go list ./... | grep -v test | sort | uniq)
  131. - |
  132. # status
  133. echo "Build completed successfully - running tests; coverage and race detector enabled"
  134. echo "TODO: Use 'cov_report.sh'"
  135. - CGO_ENABLED=1 go test -v -a -cover -covermode=atomic -race -tags="leaktest" -count=1 -cpu=1 -bench=. -parallel=1 $(go list ./... | grep -v test | sort | uniq)
  136. - |
  137. # cleanup
  138. - chmod -R u+rwx "${GOPATH:?}"/* 2>/dev/null && rm -rf -- "${GOPATH:?}"/* 2>/dev/null || true :;
  139. - chmod -R u+rwx "${GOCACHE:?}"/* 2>/dev/null && rm -rf -- "${GOCACHE:?}"/* 2>/dev/null || true :;
  140. - chmod -R u+rwx "${GOMODCACHE:?}"/* 2>/dev/null && rm -rf -- "${GOMODCACHE:?}"/* 2>/dev/null || true :;
  141. ###################### End macOS Build + Test