version: 2

jobs:
  build_js:
    docker:
      - image: circleci/node:8-browsers
    steps:
      - checkout
      - restore_cache:
          key: node-modules-{{ checksum "yarn.lock" }}
      - run:
          name: Install dependencies
          command: yarn install
      - save_cache:
          key: node-modules-{{ checksum "yarn.lock" }}
          paths:
            - node_modules
      - run:
          name: Run build
          command: yarn run build:parcel
      - persist_to_workspace:
          root: .
          paths:
            - assets

  build_hugo:
    docker:
      - image: cibuilds/hugo:latest
    steps:
      - checkout
      - run:
          name: Build
          command: hugo
      - persist_to_workspace:
          root: .
          paths:
            - assets

  deploy_static:
    docker:
      - image: circleci/node:8-browsers
    steps:
      - checkout
      - attach_workspace:
          at: .
      - run:
          name: Install netlify cli
          command:
            wget -qO- 'https://cli.netlify.com/download/latest/linux' | tar xz
      - run:
          name: Deploy to netlify
          command: ./netlifyctl -A $NETLIFY_AUTH_TOKEN -b build deploy

workflows:
  version: 2
  main:
    jobs:
      - build_js
      - build_hugo:
          requires:
            - build_js
      - deploy_static:
          requires:
            - build_js
            - build_hugo
          filters:
            branches:
              only: master

version: 2

jobs:
  build_js:
    docker:
      - image: circleci/node:8-browsers
    steps:
      - checkout
      - restore_cache:
          key: node-modules-{{ checksum "yarn.lock" }}
      - run:
          name: Install dependencies
          command: yarn install
      - save_cache:
          key: node-modules-{{ checksum "yarn.lock" }}
          paths:
            - node_modules
      - run:
          name: Run build
          command: yarn run build:parcel
      - persist_to_workspace:
          root: .
          paths:
            - assets

  build_hugo:
    docker:
      - image: cibuilds/hugo:latest
    steps:
      - checkout
      - attach_workspace:
          at: .
      - run:
          name: Build
          command: hugo
      - persist_to_workspace:
          root: .
          paths:
            - assets

  deploy_static:
    docker:
      - image: circleci/node:8-browsers
    steps:
      - checkout
      - attach_workspace:
          at: .
      - run:
          name: Install netlify cli
          command:
            wget -qO- 'https://cli.netlify.com/download/latest/linux' | tar xz
      - run:
          name: Deploy to netlify
          command: ./netlifyctl -A $NETLIFY_AUTH_TOKEN -b build deploy

workflows:
  version: 2
  main:
    jobs:
      - build_js
      - build_hugo:
          requires:
            - build_js
      - deploy_static:
          requires:
            - build_js
            - build_hugo
          filters:
            branches:
              only: master

Attach workspace during hugo build
Attach workspace during hugo build
