Skip to content

Add Smart Previews PR mechanism #1

Add Smart Previews PR mechanism

Add Smart Previews PR mechanism #1

# name: Create Preview Env using S3 and CloudFront
# on:
# pull_request:
# types:
# - opened
# - reopened
# - synchronize
# - closed
# branches:
# - master
# - v*.*
# env:
# PR_NUMBER: ${{ github.event.number }}
# jobs:
# deploy:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Install AWS CLI
# run: |
# sudo apt-get update
# sudo apt-get install awscli -y
# - name: Sync S3 bucket
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
# run: |
# aws s3 sync ./docs s3://your-bucket-name
# - name: Invalidate CloudFront cache
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
# run: |
# aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*"
# preview:
# runs-on: ubuntu-latest
# if: github.event_name == 'pull_request'
# steps:
# - name: Checkout code
# uses: actions/checkout@v2
# - name: Install AWS CLI
# run: |
# sudo apt-get update
# sudo apt-get install awscli -y
# - name: Sync S3 bucket for preview
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
# run: |
# aws s3 sync ./docs s3://your-bucket-name/${{ env.PR_NUMBER }}
# - name: Invalidate CloudFront cache
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
# run: |
# aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} --paths "/${{ env.PR_NUMBER }}/*"
# - name: Output preview URL
# run: |
# echo "Preview environment URL: https://your-cloudfront-domain/${{ env.PR_NUMBER }}/"
# - name: Comment on PR with preview URL
# uses: actions/github-script@v6
# with:
# script: |
# github.rest.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: `Preview environment URL: https://your-cloudfront-domain/${{ env.PR_NUMBER }}/`
# })
# cleanup:
# runs-on: ubuntu-latest
# if: github.event_name == 'pull_request' && github.event.action == 'closed'
# steps:
# - name: Install AWS CLI
# run: |
# sudo apt-get update
# sudo apt-get install awscli -y
# - name: Remove PR directory from S3 bucket
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
# run: |
# aws s3 rm s3://your-bucket-name/pr-${{ env.PR_NUMBER }} --recursive
# - name: Invalidate CloudFront cache
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
# run: |
# aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} --paths "/pr-${{ env.PR_NUMBER }}/*"