name: Deploy to AWS S3 and Invalidate CloudFront

on:
  push:
    branches:
      - master  # Adjust this to your repository's default branch

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      
      - name: Sync to S3
        uses: jakejarvis/s3-sync-action@master
        with:
          args: >
           --follow-symlinks 
           --delete
           --exclude '.git/*'
           --exclude '.github/*'
        env:
          AWS_S3_BUCKET: www.xbazzi.com
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          AWS_REGION: 'us-east-1'  # e.g., us-east-1
          SOURCE_DIR: './'  # The root of your repository; adjust if your files are in a subdirectory

      - name: Invalidate CloudFront Distribution
        uses: chetan/invalidate-cloudfront-action@v1
        env:
          DISTRIBUTION: E3VV7PXHG95EM0
          PATHS: '/*'
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          AWS_REGION: 'us-east-1'
