Deploy React App via CodeDeploy #5
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: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- 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 | |
- name: Upload Build to S3 | |
run: | | |
COMMIT_HASH=$(git rev-parse --short HEAD) | |
cd application | |
zip -r build.zip appspec.yml build/ scripts/ | |
aws s3 cp build.zip s3://${{ secrets.S3_BUCKET }}/builds/build-$COMMIT_HASH.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 | |
- name: Deploy to CodeDeploy | |
run: | | |
aws deploy create-deployment \ | |
--application-name CodeDeployAppNameWithASG \ | |
--deployment-group-name CodeDeployGroupName \ | |
--s3-location bucket=${{ secrets.S3_BUCKET }},key=builds/build-$COMMIT_HASH.zip,bundleType=zip |