.gitlab-ci.yml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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://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"
  66. - $env:CGO_ENABLED="1"
  67. - go test -v -cover -covermode="atomic" -race -count="1" -cpu="2" -bench="." -parallel="2" .\...
  68. ###################### End Windows Build + Test
  69. ###################### Begin Linux
  70. linux job:
  71. tags:
  72. - Linux-x86_64
  73. stage: all
  74. script:
  75. - *scriptCommon
  76. - |
  77. # upgrade system, install development tools
  78. - yum install dnf -y
  79. - yum clean all -y
  80. - dnf upgrade --refresh -y
  81. - dnf groupinstall "Development Tools" -y
  82. - dnf install epel-release centos-release-scl centos-release-scl-rh -y
  83. - dnf install ccache pv valgrind graphviz clang zsh scl-utils devtoolset-9 -y
  84. - dnf groupupdate base -y
  85. - source /opt/rh/devtoolset-9/enable
  86. - dnf clean all -y
  87. - |
  88. # gimme go stable (latest release)
  89. 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"
  90. 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
  91. - source /tools/genv
  92. - go env -w GO111MODULE=on && export GO111MODULE=on
  93. - export GOPROXY="https://proxy.golang.org,direct" && go env -w GOPROXY="${GOPROXY:?}"
  94. - *scriptGoVersion
  95. - go clean -modcache -cache -r
  96. - *scriptGitPre
  97. - CGO_ENABLED=0 go build -v -a -trimpath $(go list ./... | grep -v test | sort | uniq)
  98. - |
  99. # status
  100. echo "Build completed successfully - running tests."
  101. - CGO_ENABLED=1 go test -v -a -cover -covermode=atomic -race -count=1 -cpu=2 -bench=. -parallel=2 $(go list ./... | grep -v test | sort | uniq)
  102. ###################### End Linux Build + Test
  103. ###################### Begin macOS Build + Test
  104. macos job:
  105. tags:
  106. - macOS_X-x86_64
  107. stage: all
  108. script:
  109. - |
  110. # update tools
  111. bash --norc --noprofile --posix -c "brew update || true" || true
  112. bash --norc --noprofile --posix -c "brew upgrade || true" || true
  113. - *scriptCommon
  114. - 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
  115. - export PATH="/usr/local/opt/gcc/bin:${PATH:?}"
  116. - go env -w GO111MODULE=on && export GO111MODULE=on
  117. - export GOPROXY="https://proxy.golang.org,direct" && go env -w GOPROXY="${GOPROXY:?}"
  118. - export PRIVPATH=$(mktemp -d "${HOME:?}/.XXXXXXXXXXXXXXXX")
  119. - export NEW_GOPATH=$(mktemp -d "${PRIVPATH:?}/XXXXXXXXXXXXXXXX")
  120. - export NEW_GOCACHE=$(mktemp -d "${PRIVPATH:?}/XXXXXXXXXXXXXXXX")
  121. - export NEW_GOMODCACHE=$(mktemp -d "${PRIVPATH:?}/XXXXXXXXXXXXXXXX")
  122. - export GOPATH="${NEW_GOPATH:?}" && go env -w GOPATH="${NEW_GOPATH:?}"
  123. - export GOCACHE="${NEW_GOCACHE:?}" && go env -w GOCACHE="${NEW_GOCACHE:?}"
  124. - export GOMODCACHE="${NEW_GOMODCACHE:?}" && go env -w GOMODCACHE="${NEW_GOMODCACHE:?}"
  125. - *scriptGoVersion
  126. - go clean -testcache -modcache -cache -r
  127. - *scriptGitPre
  128. - CGO_ENABLED=0 go build -v -a -trimpath $(go list ./... | grep -v test | sort | uniq)
  129. - |
  130. # status
  131. echo "Build completed successfully - running tests"
  132. - CGO_ENABLED=1 go test -v -a -cover -covermode=atomic -race -count=1 -cpu=2 -bench=. -parallel=2 $(go list ./... | grep -v test | sort | uniq)
  133. - |
  134. # cleaning up
  135. - chmod -R u+rwx "${GOPATH:?}"/* 2>/dev/null && rm -rf -- "${GOPATH:?}"/* 2>/dev/null || true :;
  136. - chmod -R u+rwx "${GOCACHE:?}"/* 2>/dev/null && rm -rf -- "${GOCACHE:?}"/* 2>/dev/null || true :;
  137. - chmod -R u+rwx "${GOMODCACHE:?}"/* 2>/dev/null && rm -rf -- "${GOMODCACHE:?}"/* 2>/dev/null || true :;
  138. ###################### End macOS Build + Test