Skip to content

[DEPLOY]Update github action yaml file for s3 & cloudfront #9

[DEPLOY]Update github action yaml file for s3 & cloudfront

[DEPLOY]Update github action yaml file for s3 & cloudfront #9

name: Deploy to Amazon EC2 & CloudFront
on:
push:
branches: ['main']
pull_request:
branches: ['main']
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache
uses: actions/[email protected]
with:
path: "**/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-
${{ runner.os }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm install
- name: Build
run: npm run build
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ secrets.AWS_S3_REGION }}
aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }}
- name: check route
run: ls
- name: check path
run: pwd
- name: Deploy to S3
run: aws s3 sync ./dist s3://${{ secrets.AWS_S3_BUCKET_NAME }}
- name: Invalidate CloudFront Cache
run: |
aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/*"