Build and Deploy React App #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy React App | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
"tts-frontend-react-code/**" | |
# Configure Manual Trigger | |
workflow_dispatch: | |
inputs: | |
deploy_option: | |
type: choice | |
description: Select deploy to S3 | |
options: | |
- yes | |
- no | |
required: true | |
jobs: | |
build-deploy-invalidate: | |
runs-on: ubuntu-latest | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 14.x | |
- name: Install dependencies | |
run: npm install | |
working-directory: tts-frontend-react-code | |
- name: Build React app | |
run: npm run build | |
working-directory: tts-frontend-react-code | |
- name: Install AWS CLI | |
if: ${{ github.event.inputs.deploy_option == 'yes' }} | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y awscli | |
- name: Deploy to S3 | |
if: ${{ github.event.inputs.deploy_option == 'yes' }} | |
run: aws s3 sync ./build s3://${{ secrets.S3_FRONTEND_BUCKET }} --delete # Modify BUCKET_NAME with your bucket name | |
working-directory: tts-frontend-react-code | |
- name: invalidate_cache CloudFront | |
if: ${{ github.event.inputs.deploy_option == 'yes' }} | |
run: | | |
aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*" | |