github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/.circleci/config.yml (about) 1 version: 2.1 2 3 orbs: 4 slack: circleci/slack@3.4.2 5 6 references: 7 images: 8 middleman: &MIDDLEMAN_IMAGE docker.mirror.hashicorp.services/hashicorp/middleman-hashicorp:0.3.44 9 10 executors: 11 go: 12 docker: 13 - image: docker.mirror.hashicorp.services/cimg/go:1.17.2 14 environment: 15 CONSUL_VERSION: 1.7.2 16 GOMAXPROCS: 4 17 GO111MODULE: "on" 18 GOPROXY: https://proxy.golang.org/ 19 TEST_RESULTS_DIR: &TEST_RESULTS_DIR /tmp/test-results 20 ARTIFACTS_DIR: &ARTIFACTS_DIR /tmp/artifacts 21 22 jobs: 23 go-checks: 24 executor: 25 name: go 26 steps: 27 - checkout 28 - run: go mod verify 29 - run: go install honnef.co/go/tools/cmd/staticcheck 30 - run: go install github.com/nishanths/exhaustive/... 31 - run: make fmtcheck generate staticcheck exhaustive 32 - run: 33 name: verify no code was generated 34 command: | 35 if [[ -z $(git status --porcelain) ]]; then 36 echo "Git directory is clean." 37 else 38 echo "Git is dirty. Run `make fmtcheck` and `make generate` locally and commit any formatting fixes or generated code." 39 git status --porcelain 40 exit 1 41 fi 42 - run: 43 name: verify go.mod and go.sum are correct 44 command: | 45 go mod tidy 46 git diff --quiet && exit 0 47 echo "please run 'go mod tidy' to ensure go.mod and go.sum are up to date" 48 exit 1 49 - run: 50 name: verify that our protobuf stubs are up-to-date 51 command: | 52 make protobuf 53 git diff --quiet && exit 0 54 echo "Run 'make protobuf' to ensure that the protobuf stubs are up-to-date." 55 exit 1 56 57 go-test: 58 executor: 59 name: go 60 environment: 61 TF_CONSUL_TEST: 1 62 parallelism: 4 63 steps: 64 - checkout 65 - attach_workspace: 66 at: . 67 - run: 68 name: install consul 69 command: | 70 curl -sLo consul.zip https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip 71 unzip consul.zip 72 mkdir -p ~/bin 73 mv consul ~/bin 74 echo 'export PATH="~/bin:$PATH"' 75 - run: mkdir -p $TEST_RESULTS_DIR 76 - run: 77 name: Run Go Tests 78 command: | 79 PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname) 80 echo "Running $(echo $PACKAGE_NAMES | wc -w) packages" 81 echo $PACKAGE_NAMES 82 gotestsum --format=short-verbose --junitfile $TEST_RESULTS_DIR/gotestsum-report.xml -- -p 2 -cover -coverprofile=cov_$CIRCLE_NODE_INDEX.part $PACKAGE_NAMES 83 84 # save coverage report parts 85 - persist_to_workspace: 86 root: . 87 paths: 88 - cov_*.part 89 90 - store_test_results: 91 path: *TEST_RESULTS_DIR 92 - store_artifacts: 93 path: *TEST_RESULTS_DIR 94 95 - slack/status: 96 fail_only: true 97 only_for_branches: main 98 99 go-test-e2e: 100 executor: 101 name: go 102 environment: 103 TF_ACC: 1 104 steps: 105 - checkout 106 - attach_workspace: 107 at: . 108 - run: mkdir -p $TEST_RESULTS_DIR 109 - run: 110 name: Run Go E2E Tests 111 command: | 112 gotestsum --format=short-verbose --junitfile $TEST_RESULTS_DIR/gotestsum-report.xml -- -p 2 -cover -coverprofile=cov_e2e.part ./internal/command/e2etest 113 114 # save coverage report parts 115 - persist_to_workspace: 116 root: . 117 paths: 118 - cov_*.part 119 120 - store_test_results: 121 path: *TEST_RESULTS_DIR 122 - store_artifacts: 123 path: *TEST_RESULTS_DIR 124 125 - slack/status: 126 fail_only: true 127 only_for_branches: main 128 129 # build all distros 130 build-distros: &build-distros 131 executor: go 132 environment: &build-env 133 TF_RELEASE: 1 134 steps: 135 - run: go get -u github.com/mitchellh/gox # go get gox before detecting go mod 136 - checkout 137 - run: ./scripts/build.sh 138 - run: mkdir -p $ARTIFACTS_DIR 139 - run: cp pkg/*.zip /tmp/artifacts 140 # save dev build to CircleCI 141 - store_artifacts: 142 path: *ARTIFACTS_DIR 143 144 # build all amd64 architecture supported OS binaries 145 build-amd64: 146 <<: *build-distros 147 environment: 148 <<: *build-env 149 XC_OS: "darwin linux windows" 150 XC_ARCH: "amd64" 151 152 # build all arm architecture supported OS binaries 153 build-arm: 154 <<: *build-distros 155 environment: 156 <<: *build-env 157 XC_OS: "linux" 158 XC_ARCH: "arm" 159 160 # build all arm64 architecture supported OS binaries 161 build-arm64: 162 <<: *build-distros 163 environment: 164 <<: *build-env 165 XC_OS: "darwin" 166 XC_ARCH: "arm64" 167 168 test-docker-full: 169 executor: 170 name: go 171 steps: 172 - checkout 173 - setup_remote_docker 174 - run: 175 name: test docker build for 'full' image 176 command: docker build -t test-docker-full . 177 178 # Based on a similar job in terraform-website repo. 179 website-link-check: 180 docker: 181 - image: *MIDDLEMAN_IMAGE 182 steps: 183 - checkout: 184 path: terraform 185 186 - run: 187 name: Determine changed website files, if any 188 working_directory: terraform 189 command: | 190 # Figure out what the current branch forked from. Compare against 191 # main and the set of "vX.Y" branches, and choose whichever branch 192 # we're the *fewest* commits ahead of. 193 # The point here isn't to perfectly predict where this will be 194 # merged; all we really care about is determining which commits are 195 # *unique to this PR,* so we don't accidentally complain about 196 # problems you had nothing to do with. 197 PARENT_BRANCH=$( 198 for br in $(git branch -rl --format='%(refname:short)' | grep -E '^origin/(main|v\d+\.\d+)$'); do 199 new_commits=$(git rev-list --first-parent ^${br} HEAD | wc -l); 200 echo "${br} ${new_commits}"; 201 done \ 202 | sort -n -k2 \ 203 | head -n1 \ 204 | awk '{print $1}'; 205 ) 206 echo "Checking current branch against: ${PARENT_BRANCH}" 207 MERGE_BASE=$(git merge-base HEAD ${PARENT_BRANCH}) 208 git diff --name-only -z --diff-filter=AMRCT ${MERGE_BASE}..HEAD -- ./website/ > /tmp/changed-website-files.txt 209 # --name-only: Return a list of affected files but don't show the changes. 210 # -z: Make that a null-separated list (instead of newline-separated), and 211 # DON'T mangle non-ASCII characters. 212 # --diff-filter=AMRCT: Only list files that were added, modified, renamed, 213 # copied, or had their type changed (file, symlink, etc.). In 214 # particular, we don't want to check deleted files. 215 # ${MERGE_BASE}..HEAD: Only consider files that have 216 # changed since this branch diverged from its parent branch. 217 # -- ./website/: Only consider files in the website directory. 218 echo "Changed website files:" 219 cat /tmp/changed-website-files.txt | tr '\0' '\n' 220 # Need to use "tr" for display because it's a null-separated list. 221 222 - run: 223 name: Exit early if there's nothing to check 224 command: | 225 if [ ! -s /tmp/changed-website-files.txt ]; then 226 circleci-agent step halt 227 fi 228 229 - run: 230 name: Check out terraform-website repo 231 command: git clone git@github.com:hashicorp/terraform-website.git 232 233 - run: 234 name: Use local checkout for terraform submodule, instead of cloning again 235 working_directory: terraform-website 236 command: | 237 # Set submodule's URL to our existing checkout. 238 # (Using `pwd` because git's behavior with strictly relative paths is unreliable.) 239 git config --file=.gitmodules submodule.ext/terraform.url $(pwd)/../terraform/.git 240 # Make it so `make sync` will grab our current branch instead of stable-website. 241 git config --file=.gitmodules submodule.ext/terraform.branch HEAD 242 243 - run: 244 name: Init/update terraform-website submodules 245 working_directory: terraform-website 246 command: make sync 247 248 - run: 249 name: Set up terraform-website dependencies 250 working_directory: terraform-website/content 251 # If this does anything interesting, then the container needs an update. 252 command: bundle check || bundle install --path vendor/bundle --retry=3 253 254 - run: 255 name: Run middleman in background 256 working_directory: terraform-website/content 257 background: true 258 command: bundle exec middleman server 259 260 - run: 261 name: Wait for server to start 262 command: until curl -sS http://localhost:4567/ > /dev/null; do sleep 1; done 263 264 - run: 265 name: Check links in changed pages 266 working_directory: terraform-website/content 267 command: cat /tmp/changed-website-files.txt | bundle exec ./scripts/check-pr-links.rb 268 269 workflows: 270 version: 2 271 test: 272 jobs: 273 - go-checks 274 - go-test: 275 requires: 276 - go-checks 277 - go-test-e2e: 278 requires: 279 - go-checks 280 - test-docker-full: 281 filters: 282 branches: 283 only: 284 - main 285 - /^v\d+\.\d+$/ # v0.11, v0.12, etc. 286 287 build-distros: 288 jobs: 289 - build-amd64 290 - build-arm 291 - build-arm64 292 293 website-test: 294 jobs: 295 - website-link-check