---
steps:
  - name: ':docker: Build'
    agents:
      queue: builder
    plugins:
      docker-compose:
        build: athenaeum
        image-repository: us.gcr.io/pg-shared-v1/athenaeum
        image-name: $BUILDKITE_BUILD_NUMBER

  - wait

  - name: "Run Snyk Scan"
    command: "bin/snyk.sh"
    timeout_in_minutes: 5
    agents:
      queue: runner
    plugins:
      docker-compose#v3.2.0:
        run: athenaeum-snyk
        config: docker-compose-snyk.yml
    soft_fail: true

  - name: ':scsslint:'
    command: yarn lint
    agents:
      queue: runner
    plugins:
      docker-compose:
        run: athenaeum

  - name: ':jest:'
    command: yarn test --coverage
    agents:
      queue: runner
    plugins:
      docker-compose:
        run: athenaeum
    artifact_paths:
      - "coverage/lcov.info"

  - wait

  - name: ':sonarcloud:'
    branches: 'main'
    command: bin/sonar
    agents:
      queue: runner
    plugins:
      docker-compose:
        run: athenaeum-sonar
    soft_fail:
      - exit_status: 1

  - name: ':sonarcloud: Automated Code Review'
    branches: "!main !hotfix/*"
    command: bin/scan-pullrequest
    agents:
      queue: runner
    plugins:
      docker-compose:
        run: athenaeum-sonar
    soft_fail:
      - exit_status: 1

  - wait

  - block: 'Trigger deploy/publish'
    branches: 'main'
    prompt: 'Choose a version bump'
    fields:
    - select: 'Increment'
      key: 'bump-size'
      hint: "MAJOR: incompatible API changes // MINOR: add backwards-compatible functionality // PATCH: backwards-compatible bug fixes"
      required: true
      options:
        - label: 'Major -- Please avoid major bumps'
          value: 'major'
        - label: 'Minor'
          value: 'minor'
        - label: 'Patch'
          value: 'patch'

  - block: "Trigger custom deploy for current version"
    branches: '!main'

  - name: ':npm:'
    command: bin/build
    agents:
      queue: builder
    plugins:
      docker-compose:
        run: athenaeum
    artifact_paths:
      - styleguide/**/*

  - wait

  - name: ':rocket: :gcloud:'
    command: bin/deploy
    agents:
      queue: sandbox

  - wait

  - name: ':rocket: :octocat:'
    command: bin/commit-tag
    branches: main
    agents:
      queue: builder
