Build and Deploy React App #14
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: | |
- deploy | |
- not-deploy | |
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 | |
# run: | | |
# sudo apt-get update | |
# sudo apt-get install -y awscli | |
# AWS CLI is preinstalled in github workflow runners | |
- name: Deploy to S3 | |
if: ${{ github.event.inputs.deploy_option == 'deploy' }} | |
# Modify BUCKET_NAME with your s3://yourbucketname and you should mention the region | |
run: aws s3 sync ./build ${{ secrets.S3_FRONTEND_BUCKET }} --delete --region us-east-1 | |
working-directory: tts-frontend-react-code | |
- name: invalidate_cache CloudFront | |
if: ${{ github.event.inputs.deploy_option == 'deploy' }} | |
# you should mention the region in your command (source of the error:botocore.awsrequest.AWSRequest object at 0x7f6728351a10) | |
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*" --region us-east-1 |