|
1 |
| -# JavaScript Node CircleCI 2.0 configuration file |
2 |
| -# |
3 |
| -# Check https://circleci.com/docs/2.0/language-javascript/ for more details |
4 |
| -# |
5 | 1 | version: 2
|
6 | 2 | jobs:
|
7 | 3 | build:
|
8 | 4 | docker:
|
9 |
| - - image: circleci/node:14-browsers |
10 |
| - |
11 |
| - working_directory: ~/repo |
12 |
| - |
| 5 | + - image: cimg/node:14.17.0 |
13 | 6 | environment:
|
14 | 7 | AWS_PAGER: ''
|
15 |
| - |
16 | 8 | steps:
|
17 | 9 | - checkout
|
18 |
| - |
19 |
| - # Download and cache dependencies |
20 |
| - - restore_cache: |
21 |
| - keys: |
22 |
| - - node14-dependencies-v2-{{ checksum "yarn.lock" }} |
23 |
| - # Fallback to using the latest cache if no exact match is found |
24 |
| - - node14-dependencies-v2- |
25 |
| - |
26 | 10 | - run:
|
27 |
| - name: Set up apt |
| 11 | + name: Install AWS CLI v2 |
28 | 12 | command: |
|
29 |
| - sudo apt-get -qq update |
30 |
| - sudo apt-get -y -qq install apt-transport-https |
31 |
| -
|
| 13 | + curl -sSL https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip |
| 14 | + unzip awscliv2.zip |
| 15 | + rm awscliv2.zip |
| 16 | + sudo aws/install |
| 17 | + - restore_cache: |
| 18 | + keys: |
| 19 | + - node14-dependencies-v2-{{ checksum "yarn.lock" }} |
| 20 | + - node14-dependencies-v2- |
32 | 21 | - run:
|
33 | 22 | name: Install Yarn
|
34 | 23 | command: |
|
| 24 | + # Remove preinstalled Yarn to avoid conflicts |
35 | 25 | sudo rm -f /usr/local/bin/yarn
|
36 |
| - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - |
37 |
| - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list |
38 |
| - sudo apt-get -qq update |
39 |
| - # transform the '>=x.y.z' version constraint in package.json to the 'x.y.z-1' version format of apt-get |
40 |
| - YARN_VERSION=$( jq -r '(.engines.yarn | gsub("[^0-9.]";"")) + "-1"' < package.json ) |
41 |
| - sudo apt-get -qq install --no-install-recommends yarn=$YARN_VERSION |
42 |
| -
|
| 26 | + # Get Yarn version from package.json and remove >= prefix |
| 27 | + YARN_VERSION=$( jq -r '(.engines.yarn | gsub("[^0-9.]";""))' < package.json ) |
| 28 | + # Download and install |
| 29 | + curl -sSL "https://github.com/yarnpkg/yarn/releases/download/v$YARN_VERSION/yarn_${YARN_VERSION}_all.deb" -o yarn.deb |
| 30 | + sudo dpkg -i yarn.deb |
| 31 | + rm yarn.deb |
43 | 32 | - run:
|
44 | 33 | name: Install dependencies
|
45 | 34 | command: yarn --frozen-lockfile
|
46 |
| - |
47 | 35 | - save_cache:
|
48 | 36 | paths:
|
49 | 37 | - ~/.cache/yarn
|
50 | 38 | - node_modules
|
51 | 39 | key: node14-dependencies-v2-{{ checksum "yarn.lock" }}
|
52 |
| - |
53 |
| - # Build |
54 | 40 | - run:
|
55 | 41 | name: Build
|
56 | 42 | command: |
|
57 | 43 | export REACT_APP_VERSION=${CIRCLE_SHA1:0:7}
|
58 | 44 | export REACT_APP_BRANCH=$CIRCLE_BRANCH
|
59 | 45 | export REACT_APP_BUILD_DATE=$(TZ=GMT date +'%b %_d, %Y, %_I:%M %p %Z')
|
60 |
| - yarn build |
61 |
| -
|
62 |
| - # Run tests |
| 46 | + yarn run build |
63 | 47 | - run:
|
64 | 48 | name: Test
|
65 |
| - command: yarn test |
66 |
| - |
| 49 | + command: yarn run test |
67 | 50 | - deploy:
|
| 51 | + name: Deploy if allowed |
68 | 52 | command: |
|
69 |
| - sudo apt-get -y -qq install awscli |
70 |
| - aws s3 sync build/ s3://vasttester-origin-$CIRCLE_BRANCH.iabtechlab.com/ --delete --cache-control max-age=300 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers |
| 53 | + BRANCHES='master candidate release' |
| 54 | + if [[ " $BRANCHES " = *" $CIRCLE_BRANCH "* ]]; then |
| 55 | + BUCKET=vasttester-origin-$CIRCLE_BRANCH.iabtechlab.com |
| 56 | + echo Installing |
| 57 | + echo Deploying to $BUCKET... |
| 58 | + aws s3 sync \ |
| 59 | + build/ \ |
| 60 | + s3://$BUCKET/ \ |
| 61 | + --delete \ |
| 62 | + --cache-control max-age=300 \ |
| 63 | + --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers |
| 64 | + else |
| 65 | + echo Not deploying $CIRCLE_BRANCH branch |
| 66 | + fi |
0 commit comments