-
Notifications
You must be signed in to change notification settings - Fork 0
51 lines (42 loc) · 1.39 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
name: Deploy React App to S3
on:
push:
branches:
- main
paths:
- 'src/**' # Only trigger when files in src directory change
- 'package.json' # Only trigger when package.json changes
- 'package-lock.json' # Only trigger when package-lock.json changes
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ secrets.NODE_VERSION }}
- name: Install dependencies
run: npm install
- name: Build React app
run: |
cp .env.example .env
npm run build
env:
CI: false
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Deploy to S3
run: |
# Empty the S3 bucket
aws s3 rm s3://${{ secrets.S3_BUCKET }} --recursive
# Upload new build files
aws s3 sync build/ s3://${{ secrets.S3_BUCKET }} --delete
- name: Invalidate CloudFront
run: |
aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*"