text: aliases:
    - &filter-only-master
      branches:
        only:
          - master
  
    - &restore-cache
      restore_cache:
        keys:
        - dependencies-{{ .Branch }}-{{ checksum "website/yarn.lock" }}
        # fallback to using the latest cache if no exact match is found
        - dependencies-{{ .Branch }}-
  
  
  version: 2
  jobs:
    build-website:
      docker:
        - image: circleci/node:9.11
  
      working_directory: ~/profilo
  
      steps:
        - checkout
        - *restore-cache
  
        # Download and cache dependencies
  
        - run:
            name: Install Docusaurus
            command: |
              cd website
              yarn --non-interactive --cache-folder ~/.cache/yarn
  
        - save_cache:
            paths:
              - website/node_modules
              - ~/.cache/yarn
            key: dependencies-{{ .Branch }}-{{ checksum "website/yarn.lock" }}
  
        - run:
            name: Build website
            command: |
              cd website
              yarn --non-interactive --cache-folder ~/.cache/yarn build
  
        - persist_to_workspace:
            root: website
            paths:
              - "*/*"
  
    deploy-website:
      docker:
        - image: circleci/node:9.11
  
      working_directory: ~/profilo
  
      steps:
        - checkout
        - *restore-cache
        
        - attach_workspace:
            at: website
  
        - run:
            name: Configure GitHub Bot
            command: |
              git config --global user.email "docusaurus-bot@users.noreply.github.com"
              git config --global user.name "Website Deployment Script"
              echo "machine github.com login docusaurus-bot password $GITHUB_TOKEN" > ~/.netrc
  
        - deploy:
            name: Deploy Website
            command: |
              echo "Deploying website..."
              cd website 
              GIT_USER=docusaurus-bot USE_SSH= yarn run deploy
  
  workflows:
    version: 2
    website_workflow:
      jobs:
        - build-website
        - deploy-website:
            filters: *filter-only-master
            requires:
              - build-website
  