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