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