config.yml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. version: 2.1
  2. orbs:
  3. win: circleci/windows@2.2.0
  4. references:
  5. environment: &ENVIRONMENT
  6. GOMAXPROCS: 4
  7. GO111MODULE: "on"
  8. GOPROXY: https://proxy.golang.org/
  9. TEST_RESULTS_DIR: &TEST_RESULTS_DIR /tmp/test-results
  10. WIN_TEST_RESULTS: &WIN_TEST_RESULTS c:\Users\circleci\AppData\Local\Temp\test-results
  11. commands:
  12. git-verify:
  13. steps:
  14. - run:
  15. name: "Verify no code was generated"
  16. command: |
  17. if [[ -z $(git status --porcelain) ]]; then
  18. echo "Git directory is clean."
  19. else
  20. echo "Git is dirty. Run `make fmt` and `make generate` locally and commit any formatting fixes or generated code."
  21. git status --porcelain
  22. exit 1
  23. fi
  24. run-gotests:
  25. parameters:
  26. cmd:
  27. type: string
  28. platform:
  29. type: string
  30. steps:
  31. - run:
  32. name: "Run go tests"
  33. command: |
  34. PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname)
  35. echo "Running $(echo $PACKAGE_NAMES | wc -w) packages"
  36. echo $PACKAGE_NAMES
  37. << parameters.cmd >> --format=short-verbose --junitfile $TEST_RESULTS_DIR/hcl2/gotestsum-report.xml -- -p 2 -cover -coverprofile=<< parameters.platform >>_cov_$CIRCLE_NODE_INDEX.part $PACKAGE_NAMES
  38. jobs:
  39. go-checks:
  40. docker:
  41. - image: circleci/golang:<< parameters.go-version >>
  42. environment:
  43. <<: *ENVIRONMENT
  44. parameters:
  45. go-version:
  46. type: string
  47. steps:
  48. - checkout
  49. - run: go mod verify
  50. - run: make fmt
  51. - git-verify
  52. linux-tests:
  53. docker:
  54. - image: circleci/golang:<< parameters.go-version >>
  55. environment:
  56. <<: *ENVIRONMENT
  57. parameters:
  58. go-version:
  59. type: string
  60. parallelism: 4
  61. steps:
  62. - checkout
  63. - attach_workspace:
  64. at: .
  65. - run: mkdir -p $TEST_RESULTS_DIR/hcl2
  66. - run-gotests:
  67. cmd: "gotestsum"
  68. platform: "linux"
  69. # save coverage report parts
  70. - persist_to_workspace:
  71. root: .
  72. paths:
  73. - linux_cov_*.part
  74. - store_test_results:
  75. path: *TEST_RESULTS_DIR
  76. - store_artifacts:
  77. path: *TEST_RESULTS_DIR
  78. win-tests:
  79. executor:
  80. name: win/default
  81. shell: bash --login -eo pipefail
  82. environment:
  83. <<: *ENVIRONMENT
  84. working_directory: c:\gopath\src\github.com\hashicorp\hcl
  85. parameters:
  86. go-version:
  87. type: string
  88. gotestsum-version:
  89. type: string
  90. steps:
  91. - add_ssh_keys:
  92. fingerprints:
  93. - "3f:fc:7c:7b:7f:45:55:70:d0:7a:6b:26:7f:0d:50:e9"
  94. - run: git config --global core.autocrlf false
  95. - checkout
  96. - attach_workspace:
  97. at: .
  98. # - git-verify
  99. - run:
  100. name: Setup (remove pre-installed golang version)
  101. command: |
  102. rm -rf "c:\Go"
  103. mkdir -p $TEST_RESULTS_DIR/hcl2
  104. - restore_cache:
  105. keys:
  106. - win-golang-<< parameters.go-version >>-cache-v1
  107. - win-gomod-cache-{{ checksum "go.mod" }}-v1
  108. - run:
  109. name: Install go version << parameters.go-version >>
  110. command: |
  111. if [ ! -d "c:\go" ]; then
  112. echo "Cache not found, installing new version of go"
  113. curl --fail --location https://dl.google.com/go/go<< parameters.go-version >>.windows-amd64.zip --output go.zip
  114. unzip go.zip -d "/c"
  115. fi
  116. - run:
  117. name: Go mod download
  118. command: |
  119. go mod verify
  120. go mod download
  121. - save_cache:
  122. key: win-golang-<< parameters.go-version >>-cache-v1
  123. paths:
  124. - /go
  125. - save_cache:
  126. key: win-gomod-cache-{{ checksum "go.mod" }}-v1
  127. paths:
  128. - c:\Windows\system32\config\systemprofile\go\pkg\mod
  129. - run:
  130. name: Install gotestsum
  131. command: |
  132. curl --fail --location https://github.com/gotestyourself/gotestsum/releases/download/v<< parameters.gotestsum-version >>/gotestsum_<< parameters.gotestsum-version >>_windows_amd64.tar.gz --output gotestsum.tar.gz
  133. tar -xvzf gotestsum.tar.gz
  134. - run-gotests:
  135. cmd: "./gotestsum.exe"
  136. platform: "win"
  137. # save coverage report parts
  138. - persist_to_workspace:
  139. root: .
  140. paths:
  141. - win_cov_*.part
  142. - store_test_results:
  143. path: *WIN_TEST_RESULTS
  144. - store_artifacts:
  145. path: *WIN_TEST_RESULTS
  146. workflows:
  147. hcl2:
  148. jobs:
  149. # - go-checks:
  150. # matrix:
  151. # parameters:
  152. # go-version: ["1.14"]
  153. # name: go-checks-<< matrix.go-version >>
  154. - linux-tests:
  155. matrix:
  156. parameters:
  157. go-version: ["1.14"]
  158. name: linux-test-go-<< matrix.go-version >>
  159. - win-tests:
  160. matrix:
  161. parameters:
  162. go-version: ["1.12"]
  163. gotestsum-version: ["0.4.1"]
  164. name: win-test-go-<< matrix.go-version >>