Revision e61492ee9e90f2652df4c505ce35bcad5676129e authored by Thomas Guillet on 21 May 2021, 05:33:56 UTC, committed by Thomas Guillet on 21 May 2021, 05:33:56 UTC
1 parent 6eaac84
Raw File
config.yml
# @see https://github.com/circleci/frontend/blob/master/.circleci/config.yml
# @see https://github.com/CircleCI-Public/circleci-demo-workflows/blob/workspace-forwarding/.circleci/config.yml

# https://circleci.com/blog/circleci-hacks-reuse-yaml-in-your-circleci-config-with-yaml/
defaults: &defaults
  working_directory: ~/mes-aides-ui
  docker:
    # https://circleci.com/docs/2.0/circleci-images/#language-image-variants
    - image: betagouv/mes-aides-docker:node14-python3.7-cy
    # FIXME
    # mongo 2.4.9 is not available on Docker Hub
    # https://stackoverflow.com/questions/48233357/install-older-version-of-mongodb-with-docker
    - image: mongo:3.2.18
  environment:
    SAUCE_USERNAME: mes-aides-bot
    OPENFISCA_BIND_HOST: 127.0.0.1:2000
    LC_ALL: C.UTF-8
    LANG: C.UTF-8
    PUPPETEER_ARGS: '{"args":["--no-sandbox","--disable-dev-shm-usage"]}'

install_virtualenv: &install_virtualenv
  run:
    name: Install VirtualEnv
    command: |
      curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
      python3 get-pip.py
      pip3 install virtualenv

start_mes_aides: &start_mes_aides
  run:
    name: Start Mes Aides
    command: |
      cp backend/config/continuous_integration.js backend/config/production.js
      npm start
    background: true

wait_for_mes_aides: &wait_for_mes_aides
  run:
    name: Wait for Mes Aides
    command: wget --retry-connrefused --no-check-certificate -T 30 http://localhost:8080

version: 2
jobs:
  install:
    <<: *defaults
    steps:
      - checkout
      - restore_cache:
          name: Restoring node_modules
          keys:
            - v12.1.4-dependencies-{{ .Branch }}-{{ checksum "package-lock.json" }}
      - run:
          name: Check tool versions
          command: npm --version && node --version
      - run:
          name: Install packages from package-lock.json
          command: npm ci
      - save_cache:
          name: Saving node_modules
          key: v12.1.4-dependencies-{{ .Branch }}-{{ checksum "package-lock.json" }}
          paths:
            - node_modules
            - ~/.cache
      - persist_to_workspace:
          root: .
          paths:
            - node_modules
  install_openfisca:
    <<: *defaults
    steps:
      - checkout
      - *install_virtualenv
      - run:
          name: Create Virtual Env
          command: virtualenv .venv
      - run:
          name: Install OpenFisca
          command: |
            source .venv/bin/activate
            pip3 install -r openfisca/requirements.txt 2> ci-err.log
            test -n ci-err.log && grep incompatible ci-err.log && cat ci-err.log && exit 1
            rm ci-err.log
            deactivate
      - persist_to_workspace:
          root: .
          paths:
            - ".venv"
  lint:
    <<: *defaults
    steps:
      - checkout
      - attach_workspace:
          at: ~/mes-aides-ui
      - run:
          name: Run ESLint
          command: npm run lint
      - run:
          name: Run Prettier
          command: npm run prettier:check
  build:
    <<: *defaults
    steps:
      - checkout
      - attach_workspace:
          at: ~/mes-aides-ui
      - run:
          name: Build assets
          command: |
            cp backend/config/continuous_integration.js backend/config/production.js
            npm run build
      - persist_to_workspace:
          root: .
          paths:
            - dist
  test_jest:
    <<: *defaults
    steps:
      - checkout
      - attach_workspace:
          at: ~/mes-aides-ui
      - run:
          name: Jest
          command: npm run test
  test_e2e:
    <<: *defaults
    steps:
      - checkout
      - attach_workspace:
          at: ~/mes-aides-ui
      - *install_virtualenv
      - run:
          name: Start OpenFisca
          command: |
            source .venv/bin/activate
            gunicorn api --chdir openfisca/ --config openfisca/config.py --preload --log-level debug --log-file=-
            deactivate
          background: true
      - run:
          name: Wait for OpenFisca
          command: wget --retry-connrefused --waitretry=2 --output-document=/dev/null http://localhost:2000/variable/parisien
      - *start_mes_aides
      - *wait_for_mes_aides
      - restore_cache:
          name: Restoring node_modules
          keys:
            - v12.1.4-dependencies-{{ .Branch }}-{{ checksum "package-lock.json" }}
      - run:
          name: Start Xvfb
          command: |
            Xvfb :99
          background: true
      - run:
          name: Test un scenario simple
          command: 'npm run cypress -- --spec "cypress/integration/base.spec.js"'
      - run:
          name: Test un scenario d'une personne en situation de handicap
          command: 'npm run cypress -- --spec "cypress/integration/handicap.spec.js"'
      - run:
          name: Test un scenario familial
          command: 'npm run cypress -- --spec "cypress/integration/family.spec.js"'
      - store_artifacts:
          path: cypress/videos
      - run:
          name: Stop Xvfb
          command: |
            pkill Xvfb
  test_openfisca_test_generation:
    <<: *defaults
    steps:
      - checkout
      - attach_workspace:
          at: ~/mes-aides-ui
      - *install_virtualenv
      - run:
          name: Check OpenFisca test generation
          command: |
            source .venv/bin/activate
            npm run test:openfisca
  deploy:
    machine:
      enabled: true
    steps:
      - run:
          name: Deploy on production
          command: |
            ssh root@solstice.mes-aides.1jeune1solution.beta.gouv.fr

workflows:
  version: 2
  test:
    jobs:
      - install_openfisca
      - install
      - lint:
          requires:
            - install
      - test_jest:
          requires:
            - install
      - build:
          requires:
            - lint
      - test_e2e:
          requires:
            - build
            - install_openfisca
  deploy:
    jobs:
      - deploy:
          filters:
            branches:
              only: master
back to top