version: 2.1

executors:
  docs:
    docker:
      - image: tendermintdev/docker-website-deployment
    environment:
      AWS_REGION: us-east-1

commands:
  make:
    parameters:
      description:
        type: string
      target:
        type: string
    steps:
      - attach_workspace:
          at: /tmp/workspace
      - restore_cache:
          name: "Restore source code cache"
          keys:
            - go-src-v1-{{ .Revision }}
      - checkout
      - restore_cache:
          name: "Restore go modules cache"
          keys:
            - go-mod-v2-{{ checksum "go.sum" }}
      - run:
          name: << parameters.description >>
          command: |
            make << parameters.target >>

jobs:
  build-docs:
    executor: docs
    steps:
      - checkout
      - run:
          name: "Build docs"
          command: make build-docs LEDGER_ENABLED=false
      - run:
          name: "Upload docs to S3"
          command: make sync-docs LEDGER_ENABLED=false

workflows:
  version: 2
  test-suite:
    jobs:
      - build-docs:
          context: docs-deployment-master
          filters:
            branches:
              only:
                - docs-staging
      - build-docs:
          context: docs-deployment-release
          filters:
            branches:
              only:
                - master
            tags:
              only:
                - /v.*/
