version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 12

  pre_build:
    commands:
      - buildspecs/create-test-db.sh
      - buildspecs/install-docker.sh
      - npm ci
      - docker login --username ${DOCKER_USERNAME} --password ${DOCKER_PASSWORD}
      - buildspecs/pull-image.sh

  build:
    commands:
      - buildspecs/cypress.sh

  post_build:
    commands:
      - buildspecs/delete-test-db.sh

    finally:
      - aws configure set aws_access_key_id ${AWS_ACCESS_KEY_ID}
      - aws configure set aws_secret_access_key ${AWS_SECRET_ACCESS_KEY}
      - aws s3 cp $CODEBUILD_SRC_DIR/cypress s3://astrobin-cypress-output/ --recursive

artifacts:
  base-directory: $CODEBUILD_SRC_DIR/cypress/
  files:
    - videos/*
    - screenshots/*
