version: 0.2
env:
  secrets-manager:
    GITHUB_OAUTH: GitHub:OAuth

phases:
  install:
    commands:
      # Dependencies
      - npm ci
  pre_build:
    commands:
      - echo "Running Unit Tests"
      - npm test
  build:
    commands:
      # Build
      - echo $STAGE
      - mkdir dist
      - npm run build
      # Deploy
      - touch ./dist/revision.json
      - echo "{\"timestamp\":\"$(date)\",\"commit\":\"$CODEBUILD_RESOLVED_SOURCE_VERSION\",\"stage\":\""$STAGE\""}" > ./dist/revision.json
      - aws s3 sync ./dist s3://$BUCKET/anonymous-student/dist --cache-control max-age=31536000,public
      # Invalidate cache
      - node ./scripts/cloud-front-invalidation.js
