name: Deploy Release to AWS Production
on:
  push:
    tags:
      - v*
jobs:
  deploy:
    name: Deploy to AWS
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@v2

      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '14.x'

      - name: Build application
        run:
          yarn deploy-production
        env:
          CI: false

      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-2

      - name: Upload dist folder to S3
        run:
          aws s3 sync --delete dist s3://app.rocketplantech.com --acl public-read

      - name: Invalidate Cloudfront Distribution
        run:
          aws cloudfront create-invalidation --distribution-id=E16H1FFD3URB32 --paths /*

      - name: Upload artifacts
        uses: actions/upload-artifact@v2
        if: failure()
        with:
          name: Logs
          path: ./storage/logs
