orbs:
  hugo: circleci/hugo@0
  node: circleci/node@1.1
version: 2.1

jobs:
  test:
    executor:
      name: node/default
      tag: '13.6.0'
    steps:
      - checkout
      - node/with-cache:
          steps:
            - run: yarn
      - run: yarn build
  build:
    docker:
      - image: cibuilds/hugo:latest
    working_directory: ~/hugo-theme-chunky-poster
    steps:
      - checkout
      - hugo/hugo-build:
          source: exampleSite
          extra-flags: '--themesDir ../.. -t "hugo-theme-chunky-poster" --baseURL "https://hugo-theme-chunky-poster.netlify.com"'
      - persist_to_workspace:
          root: .
          paths:
            - exampleSite/public
            - netlify.toml
  deploy:
    executor:
      name: node/default
      tag: '13.1.0'
    working_directory: ~/site
    steps:
      - attach_workspace:
          at: ~/site
      - run: npm i netlify-cli
      - run: ./node_modules/.bin/netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --prod --message "Deploy via Circle CI."

workflows:
  main:
    jobs:
      - test
      - build
      - deploy:
          filters:
            branches:
              only: master
          requires:
            - build
