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 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 |