Skip to content

Deploy React App via CodeDeploy #8

Deploy React App via CodeDeploy

Deploy React App via CodeDeploy #8

Workflow file for this run

name: Deploy React App via CodeDeploy
on:
# push:
# branches:
# - main
workflow_dispatch: {}
permissions:
id-token: write
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Get Commit Hash (GITHUB_SHA)
id: commit_hash
run: |
echo "COMMIT_HASH=$GITHUB_SHA" >> $GITHUB_ENV
- name: Install Dependencies
run: |
cd application
npm install
- name: Build React App
run: |
cd application
npm run build
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ secrets.IAMROLE_GITHUB }}
role-session-name: GitHub-Action-Role
aws-region: ap-south-1
audience: sts.amazonaws.com
- name: Upload Build to S3
run: |
cd application
zip -r build.zip appspec.yml dist/ scripts/
aws s3 cp build.zip s3://${{ secrets.S3_BUCKET }}/builds/build-$GITHUB_SHA.zip
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ secrets.IAMROLE_GITHUB }}
role-session-name: GitHub-Action-Role
aws-region: ap-south-1
audience: sts.amazonaws.com
- name: Deploy to CodeDeploy
run: |
echo "Using Commit Hash: $GITHUB_SHA"
aws deploy create-deployment \
--application-name CodeDeployAppNameWithASG \
--deployment-group-name CodeDeployGroupName \
--s3-location bucket=${{ secrets.S3_BUCKET }},key=builds/build-$GITHUB_SHA.zip,bundleType=zip