csmcallister/fed-a11y-scan

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
version: 2.1

executors:
  default:
    docker:
      - image: cimg/python:3.8.12-node

jobs:

  test:
    executor: default
      
    steps:
      - checkout

      - run:
          name: setup-test-reporter
          command: |
            curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
            chmod +x ./cc-test-reporter
      
      - run:
          name: install-deps
          command: |
            pip install -r requirements.txt
      
      - run:
          name: flake8
          command: |
            flake8

      - run:
          name: create-empty-aws-creds
          command: |
            mkdir ~/.aws && touch ~/.aws/credentials
      
      - run:
          name: test
          command: |
            ./cc-test-reporter before-build
            coverage run -m pytest
            coverage xml
            ./cc-test-reporter after-build --debug -t "coverage.py" --exit-code $?

      - store_artifacts:
          path: coverage.xml
          destination: coverage.xml

  build:
    executor: default

    steps:
      - checkout

      - run:
          name: 'install-cdk'
          command: |
            sudo npm install -g aws-cdk@2.28.1

      - run:
          name: 'build-lambdas'
          command: |
            make build_a11y_scan;
            sudo apt update && sudo apt install -y rsync && make build_results_joiner;
      
      - run:
          name: install-deps
          command: |
            pip install -r requirements.txt

      - run:
          name: 'cdk-diff'
          command: |
            if [ "$CIRCLE_BRANCH" == "master" ]; then
              cdk deploy --require-approval never;
            else
              pr_number=${CIRCLE_PULL_REQUEST##*/}
              echo $pr_number
              block='```'
              diff=$(echo -e "cdk diff \n${block}\n$(cdk diff --no-color 2>&1 | sed -e 's/\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g' || true)\n${block}")
              data=$(jq -n --arg body "$diff" '{ body: $body }')
              curl -X POST -H 'Content-Type:application/json' \
                -H 'Accept: application/vnd.github.v3+json' \
                -H "Authorization: token ${GITHUB_TOKEN}" \
                -d "$data" \
                "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/issues/${pr_number}/comments"
            fi


workflows:
  version: 2
  test-and-build: 
    jobs:
      - test
      - build:
          requires:
            - test