|
| 1 | +# Javascript Node CircleCI 2.0 configuration file |
| 2 | +# |
| 3 | +# Check https://circleci.com/docs/2.0/language-javascript/ for more details |
| 4 | +# |
| 5 | +version: 2 |
| 6 | + |
| 7 | +defaults: &defaults |
| 8 | + working_directory: ~/repo |
| 9 | + docker: |
| 10 | + - image: circleci/node:12-browsers |
| 11 | + |
| 12 | +set_env: &set_env |
| 13 | + name: Setup Environment Variables |
| 14 | + command: | |
| 15 | + if [[ $CIRCLE_PULL_REQUEST ]] |
| 16 | + then |
| 17 | + echo 'Fetching Base Commit from GitHub' |
| 18 | + echo 'export CIRCLE_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}"' >> $BASH_ENV |
| 19 | + source $BASH_ENV |
| 20 | + echo "export CIRCLE_PR_BASE_SHA=`curl -s https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER} | jq -r '.base.sha'`" >> $BASH_ENV |
| 21 | + echo 'export AFFECTED_ARGS="--base ${CIRCLE_PR_BASE_SHA}"' >> $BASH_ENV |
| 22 | + else |
| 23 | + echo 'Fetching Base Commit from Deploy Cache' |
| 24 | + if [[ ! -f dist/last-deploy.txt ]] |
| 25 | + then |
| 26 | + mkdir dist && git rev-parse HEAD~1 > dist/last-deploy.txt |
| 27 | + fi |
| 28 | + echo 'export AFFECTED_ARGS="--base $(cat dist/last-deploy.txt)"' >> $BASH_ENV |
| 29 | + fi |
| 30 | + source $BASH_ENV |
| 31 | + echo $AFFECTED_ARGS |
| 32 | +yarn_cache: &yarn_cache |
| 33 | + keys: |
| 34 | + - node-deps-node12-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }} |
| 35 | + # fallback to using the latest cache if no exact match is found |
| 36 | + - node-deps-node12- |
| 37 | + |
| 38 | +deploy_cache: &deploy_cache |
| 39 | + key: last-deploy-sha |
| 40 | + |
| 41 | +yarn_install: &yarn_install |
| 42 | + name: Install Dependencies |
| 43 | + command: yarn install --frozen-lockfile --non-interactive |
| 44 | + |
| 45 | +jobs: |
| 46 | + install: |
| 47 | + <<: *defaults |
| 48 | + steps: |
| 49 | + - checkout |
| 50 | + - restore_cache: |
| 51 | + <<: *yarn_cache |
| 52 | + - run: |
| 53 | + <<: *yarn_install |
| 54 | + - save_cache: |
| 55 | + key: node-deps-node12-{{ checksum "yarn.lock" }} |
| 56 | + paths: |
| 57 | + - ~/.cache |
| 58 | + - node_modules |
| 59 | + check-formatting: |
| 60 | + <<: *defaults |
| 61 | + steps: |
| 62 | + - checkout |
| 63 | + - restore_cache: |
| 64 | + <<: *deploy_cache |
| 65 | + - run: |
| 66 | + <<: *set_env |
| 67 | + - restore_cache: |
| 68 | + <<: *yarn_cache |
| 69 | + - run: yarn format:check ${AFFECTED_ARGS} |
| 70 | + lint: |
| 71 | + <<: *defaults |
| 72 | + steps: |
| 73 | + - checkout |
| 74 | + - restore_cache: |
| 75 | + <<: *deploy_cache |
| 76 | + - run: |
| 77 | + <<: *set_env |
| 78 | + - restore_cache: |
| 79 | + <<: *yarn_cache |
| 80 | + - run: ./node_modules/.bin/nx workspace-lint |
| 81 | + - run: yarn affected:lint ${AFFECTED_ARGS} --parallel |
| 82 | + build: |
| 83 | + <<: *defaults |
| 84 | + steps: |
| 85 | + - checkout |
| 86 | + - restore_cache: |
| 87 | + <<: *deploy_cache |
| 88 | + - run: |
| 89 | + <<: *set_env |
| 90 | + - restore_cache: |
| 91 | + <<: *yarn_cache |
| 92 | + # - run: yarn affected:build -- ${AFFECTED_ARGS} --parallel --configuration production |
| 93 | + - run: yarn affected:build -- ${AFFECTED_ARGS} --configuration production --maxWorkers=1 |
| 94 | + - save_cache: |
| 95 | + key: build-{{ .Environment.CIRCLE_WORKFLOW_ID }} |
| 96 | + paths: |
| 97 | + - dist |
| 98 | + - store_artifacts: |
| 99 | + path: dist |
| 100 | + test: |
| 101 | + <<: *defaults |
| 102 | + steps: |
| 103 | + - checkout |
| 104 | + - restore_cache: |
| 105 | + <<: *deploy_cache |
| 106 | + - run: |
| 107 | + <<: *set_env |
| 108 | + - restore_cache: |
| 109 | + <<: *yarn_cache |
| 110 | + # - run: yarn affected:test -- ${AFFECTED_ARGS} --parallel -- --ci --code-coverage --maxWorkers=1 |
| 111 | + - run: yarn affected:test -- ${AFFECTED_ARGS} -- --ci --code-coverage --maxWorkers=1 |
| 112 | + e2e: |
| 113 | + <<: *defaults |
| 114 | + steps: |
| 115 | + - checkout |
| 116 | + - restore_cache: |
| 117 | + <<: *deploy_cache |
| 118 | + - run: |
| 119 | + <<: *set_env |
| 120 | + - restore_cache: |
| 121 | + <<: *yarn_cache |
| 122 | + - run: yarn affected:e2e -- ${AFFECTED_ARGS} --configuration production -- --headless |
| 123 | + - store_artifacts: |
| 124 | + path: dist/cypress |
| 125 | + |
| 126 | + deploy: |
| 127 | + <<: *defaults |
| 128 | + steps: |
| 129 | + - checkout |
| 130 | + - restore_cache: |
| 131 | + <<: *deploy_cache |
| 132 | + - run: |
| 133 | + <<: *set_env |
| 134 | + - restore_cache: |
| 135 | + <<: *yarn_cache |
| 136 | + - restore_cache: |
| 137 | + key: build-{{ .Environment.CIRCLE_WORKFLOW_ID }} |
| 138 | + - run: echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list |
| 139 | + - run: curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - |
| 140 | + - run: sudo apt-get update && sudo apt-get install google-cloud-sdk |
| 141 | + - run: | |
| 142 | + echo $GCLOUD_SERVICE_KEY | gcloud auth activate-service-account --key-file=- |
| 143 | + gcloud --quiet config set project ${GOOGLE_PROJECT_ID} |
| 144 | + gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE} |
| 145 | + - run: yarn affected -- --target deploy ${AFFECTED_ARGS} |
| 146 | + - run: git rev-parse HEAD > dist/last-deploy.txt |
| 147 | + - save_cache: |
| 148 | + key: last-deploy-sha |
| 149 | + paths: |
| 150 | + - dist/last-deploy.txt |
| 151 | + |
| 152 | +workflows: |
| 153 | + version: 2 |
| 154 | + pr_check: |
| 155 | + jobs: |
| 156 | + - install: |
| 157 | + filters: |
| 158 | + branches: |
| 159 | + only: |
| 160 | + - master |
| 161 | + - check-formatting: |
| 162 | + filters: |
| 163 | + branches: |
| 164 | + only: |
| 165 | + - master |
| 166 | + requires: |
| 167 | + - install |
| 168 | + - lint: |
| 169 | + filters: |
| 170 | + branches: |
| 171 | + only: |
| 172 | + - master |
| 173 | + requires: |
| 174 | + - install |
| 175 | + - test: |
| 176 | + filters: |
| 177 | + branches: |
| 178 | + only: |
| 179 | + - master |
| 180 | + requires: |
| 181 | + - install |
| 182 | + - build: |
| 183 | + filters: |
| 184 | + branches: |
| 185 | + only: |
| 186 | + - master |
| 187 | + requires: |
| 188 | + - install |
| 189 | + - e2e: |
| 190 | + filters: |
| 191 | + branches: |
| 192 | + only: |
| 193 | + - master |
| 194 | + - deploy: |
| 195 | + filters: |
| 196 | + branches: |
| 197 | + only: |
| 198 | + - master |
| 199 | + requires: |
| 200 | + - check-formatting |
| 201 | + - lint |
| 202 | + - test |
| 203 | + - build |
| 204 | + - e2e |
0 commit comments