This repository was archived by the owner on Mar 27, 2025. It is now read-only.
Rename CertificateStack and update references for Beejho frontend cer… #67
This file contains hidden or 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 to S3 and CloudFront | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - stage | |
| - '*' # Matches all other branches (dev branches) | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 9 | |
| run_install: false | |
| - name: Install Dependencies | |
| run: pnpm install | |
| - name: Build Project | |
| run: pnpm build | |
| - name: Upload Build Artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-artifact | |
| path: dist | |
| deploy_cdk: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 9 | |
| run_install: false | |
| - name: Install CDK Dependencies | |
| working-directory: infra | |
| run: pnpm install | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ap-south-1 | |
| - name: Install AWS CDK | |
| run: npm install -g aws-cdk | |
| - name: Determine Environment Name | |
| run: | | |
| if [[ $GITHUB_REF == refs/heads/main ]]; then | |
| ENV_NAME="production" | |
| elif [[ $GITHUB_REF == refs/heads/stage ]]; then | |
| ENV_NAME="stg" | |
| else | |
| ENV_NAME="dev" | |
| fi | |
| echo "ENV_NAME=$ENV_NAME" >> $GITHUB_ENV | |
| - name: Deploy CDK Stack | |
| working-directory: infra | |
| run: cdk deploy --all -c env=${{ env.ENV_NAME }} --require-approval never | |
| sync_to_s3: | |
| runs-on: ubuntu-latest | |
| needs: [build, deploy_cdk] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ap-south-1 | |
| - name: Download Build Artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: build-artifact | |
| path: dist | |
| - name: Determine Environment Name | |
| run: | | |
| if [[ $GITHUB_REF == refs/heads/main ]]; then | |
| ENV_NAME="production" | |
| elif [[ $GITHUB_REF == refs/heads/stage ]]; then | |
| ENV_NAME="stg" | |
| else | |
| ENV_NAME="dev" | |
| fi | |
| echo "ENV_NAME=$ENV_NAME" >> $GITHUB_ENV | |
| - name: Sync Files to S3 | |
| run: aws s3 sync dist s3://beejho-frontend-${{ env.ENV_NAME }} --delete | |
| invalidate_cloudfront: | |
| runs-on: ubuntu-latest | |
| needs: sync_to_s3 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| 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: Determine Environment Name | |
| run: | | |
| if [[ $GITHUB_REF == refs/heads/main ]]; then | |
| ENV_NAME="production" | |
| elif [[ $GITHUB_REF == refs/heads/stage ]]; then | |
| ENV_NAME="stg" | |
| else | |
| ENV_NAME="dev" | |
| fi | |
| echo "ENV_NAME=$ENV_NAME" >> $GITHUB_ENV | |
| - name: Get CloudFront Distribution ID | |
| id: get_distribution_id | |
| run: | | |
| STACK_NAME="BeejhoFrontendStack-${{ env.ENV_NAME }}" | |
| DISTRIBUTION_ID=$(aws cloudformation describe-stacks \ | |
| --stack-name $STACK_NAME \ | |
| --query "Stacks[0].Outputs[?OutputKey=='BeejhoCloudFrontDistributionId'].OutputValue" \ | |
| --output text) | |
| echo "DISTRIBUTION_ID=${DISTRIBUTION_ID}" >> $GITHUB_ENV | |
| - name: Invalidate CloudFront Cache | |
| run: aws cloudfront create-invalidation --distribution-id ${{ env.DISTRIBUTION_ID }} --paths "/*" |