nexxtway/react-rainbow

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
version: 2.1

orbs:
    browser-tools: circleci/browser-tools@1.3.0

references:
    defaults: &defaults
        working_directory: ~/repo
        docker:
            - image: cimg/node:14.15.0-browsers
        resource_class: medium+

    create_env_file: &create_env_file
        run:
            name: Create .env file
            command: |
                touch .env;
                echo REACT_APP_GA_ID=$REACT_APP_GA_ID >> .env;
                echo REACT_APP_GOOGLE_MAPS_APIKEY=$REACT_APP_GOOGLE_MAPS_APIKEY >> .env;
                echo REACT_APP_RECAPTCHA_APIKEY=$REACT_APP_RECAPTCHA_APIKEY >> .env;
                echo REACT_APP_CARBON_ADS_SRC=$REACT_APP_CARBON_ADS_SRC >> .env;
                echo REACT_APP_STRIPE_APIKEY=$REACT_APP_STRIPE_APIKEY >> .env;
                echo REACT_APP_ALGOLIA_APP_ID=$REACT_APP_ALGOLIA_APP_ID >> .env;
                echo REACT_APP_ALGOLIA_SEARCH_KEY=$REACT_APP_ALGOLIA_SEARCH_KEY >> .env;
                echo REACT_APP_ALGOLIA_SEARCH_COMPONENTS_INDEX=$REACT_APP_ALGOLIA_SEARCH_COMPONENTS_INDEX >> .env;
                echo REACT_APP_ALGOLIA_SEARCH_EXAMPLES_INDEX=$REACT_APP_ALGOLIA_SEARCH_EXAMPLES_INDEX >> .env;
                echo REACT_APP_ALGOLIA_SEARCH_MEDIUMS_INDEX=$REACT_APP_ALGOLIA_SEARCH_MEDIUMS_INDEX >> .env;
                echo REACT_APP_ALGOLIA_SEARCH_YOUTUBE_INDEX=$REACT_APP_ALGOLIA_SEARCH_YOUTUBE_INDEX >> .env;

jobs:
    build_and_test:
        <<: *defaults

        steps:
            - checkout

            - restore_cache:
                  keys:
                      - v2-dependencies-{{ checksum "yarn.lock" }}
                      - v2-dependencies-

            - run: yarn install

            - save_cache:
                  paths:
                      - node_modules
                  key: v2-dependencies-{{ checksum "yarn.lock" }}

            - run: yarn lint

            - run:
                  name: run test
                  command: yarn test --ci --maxWorkers=2 --coverage --coverageReporters=text-lcov
            - run:
                  name: Upload Coveralls
                  command: cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js || true
            - store_test_results:
                  path: test-results/jest-junit-results

            - store_artifacts:
                  path: test-results/jest-junit-results

    integration_tests:
        <<: *defaults

        steps:
            - checkout
            - restore_cache:
                  keys:
                      - v2-dependencies-{{ checksum "yarn.lock" }}
                      - v2-dependencies-

            - *create_env_file
            - run: yarn install

            - browser-tools/install-chrome:
                  chrome-version: 103.0.5060.53

            - run:
                  command: yarn start
                  background: true

            - run: yarn wait:on:local:server

            - run:
                  name: run integration test
                  command: |
                      yarn test:integration --headless
            - run:
                  name: generate report
                  command: |
                      yarn allure generate test-results/wdio-allure-results --clean --output test-results/allure-report
            - store_test_results:
                  path: test-results/wdio-junit-results

            - store_artifacts:
                  path: test-results/allure-report

    publish_canary:
        <<: *defaults

        steps:
            - checkout
            - restore_cache:
                  keys:
                      - v2-dependencies-{{ checksum "yarn.lock" }}
                      - v2-dependencies-
            - run: git config --global user.email "admin@nexxtway.com"
            - run: git config --global user.name "TheAdmin"
            - run: yarn install
            - run:
                  name: Auth with registry
                  command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/repo/.npmrc
            - run: yarn prepare:canary
            - run: yarn publish --tag next

    deploy_firebase:
        <<: *defaults

        steps:
            - checkout

            - restore_cache:
                  keys:
                      - v2-dependencies-{{ checksum "yarn.lock" }}
                      - v2-dependencies-

            - *create_env_file
            - run: yarn install
            - run: yarn deploy:library --token=$FIREBASE_TOKEN

workflows:
    version: 2
    build_and_test:
        jobs:
            - build_and_test
            - integration_tests:
                  requires:
                      - build_and_test
            - deploy_firebase:
                  requires:
                      - build_and_test
                      - integration_tests
                  filters:
                      branches:
                          only: master
            - publish_canary:
                  requires:
                      - build_and_test
                      - integration_tests
                  filters:
                      branches:
                          only: master