image: viewdo/devops-cli
options:
  docker: true

clone:
  depth: full
  lfs: true

pipelines:
  branches:
    develop:
      - step: &build
          name: Build
          caches:
            - node
          script:
            - &get-vars pipe get-vars && source ~/.bashrc
            - npm install
            - npm run build
          artifacts:
            - version.json
            - stories/**
            - organizations/**
      - step:
          name: Deploy to Develop
          caches:
            - node
          deployment: develop
          script:
            - pipe gcp-auth
            - *get-vars
            - npm run push
            - pipe slack "$BITBUCKET_REPO_SLUG version $VERSION was deployed to the develop namespace."
    main:
      - step:
          <<: *build
      - step:
          name: Validate & Record Changes (stage)
          caches:
            - node
          script:
            - &get-vars-stage pipe get-vars -n stage && source ~/.bashrc
            - npm run validate -- -n stage
            - npm run check -- -n stage >> changes.txt
          artifacts:
            - changes.txt
      - step:
          name: Deploy to Stage
          deployment: stage
          caches:
            - node
          script:
            - pipe gcp-auth
            - *get-vars-stage
            - npm run push -- -n stage
            - pipe slack "$BITBUCKET_REPO_SLUG version $VERSION was deployed to stage."
      - step:
          name: Validate & Check Changes
          trigger: manual
          caches:
            - node
          script:
            - *get-vars
            - npm run storyctl validate -- -s $AUTH0_CLIENT_SECRET_PROD -n archer
            - npm run storyctl check -- -s $AUTH0_CLIENT_SECRET_PROD -n archer
            - pipe slack "$BITBUCKET_REPO_SLUG version $VERSION is ready for deployment to main."
      - step:
          name: Deploy to Archer
          deployment: production
          trigger: manual
          caches:
            - node
          script:
            - pipe gcp-auth
            - *get-vars
            - npm run storyctl push -- -s $AUTH0_CLIENT_SECRET_PROD -n archer
            - pipe git-tag
            - pipe slack "$BITBUCKET_REPO_SLUG version $VERSION was deployed to Archer."
