version: 0.2

# This buildspec is intended to be run by CodePipeline builds.

phases:
  install:
    commands:

      # baked in our image.
      # this also takes care of launching the docker daemon.
      - /root/ecr-proxy/start.sh

      # Install yarn if it wasn't already present in the image
      - yarn --version || npm -g install yarn

      # Packing aws-cdk-lib can cause memory errors. Increasing this value
      # allows our build to more consistently succeed
      - /sbin/sysctl -w vm.max_map_count=2251954

      # install dependencies. align-version.sh depends on this.
      - yarn install --frozen-lockfile

  pre_build:
    commands:
      # Print our ulimits to find out if we might run into a resource limit
      - ulimit -a
      - /bin/bash ./scripts/cache-load.sh
  build:
    commands:
      - codebuild-breakpoint
      - 'if ${BUMP_CANDIDATE:-false}; then env NODE_OPTIONS="--max-old-space-size=8196 ${NODE_OPTIONS:-}" /bin/bash ./scripts/bump-candidate.sh; fi'
      - /bin/bash ./scripts/align-version.sh
      - /bin/bash ./build.sh --ci
  post_build:
    commands:
      # Short-circuit: Don't run pack if the above build failed.
      - '[ ${CODEBUILD_BUILD_SUCCEEDING:-0} -eq 1 ] || exit 1'
      - "[ -f .BUILD_COMPLETED ] && /bin/bash ./pack.sh"
      - /bin/bash ./scripts/cache-store.sh
artifacts:
  files:
    - "**/*"
  base-directory: dist
reports:
  jest-tests:
    files:
      - "**/junit.xml"
    file-format: JunitXml
