Deploy React App and CloudFormation Stack #10
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: Deploy React App and CloudFormation Stack | |
on: | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '14' | |
- name: Install dependencies | |
working-directory: frontend | |
run: npm install | |
- name: Build the React app | |
working-directory: frontend | |
run: npm run build | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-1 | |
- name: Deploy CloudFormation stack | |
uses: aws-actions/aws-cloudformation-github-deploy@v1 | |
with: | |
name: ReactAppStack | |
template: cloudformation/s3-react.yml | |
- name: Sync files to S3 | |
run: | | |
BUCKET_NAME=$(aws cloudformation describe-stacks --stack-name ReactAppStack --query "Stacks[0].Outputs[?OutputKey=='ReactAppBucketName'].OutputValue" --output text) | |
aws s3 sync frontend/build s3://$BUCKET_NAME --delete | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |