Skip to content

Commit

Permalink
invalidate cloudfront
Browse files Browse the repository at this point in the history
  • Loading branch information
kamicut committed Jun 7, 2024
1 parent e6a7fe8 commit be86934
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/deploy-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ jobs:
- name: Deploy to S3
working-directory: ${{ env.WORKING_DIRECTORY }}
run: aws s3 sync ./dist s3://gradient.osmcha.org --delete

- name: Invalidate CloudFront Cache
working-directory: ${{ env.WORKING_DIRECTORY }}
run: |
aws cloudfront create-invalidation --distribution-id E3I6NYCQVXFMCK --paths "/*"
50 changes: 38 additions & 12 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
name: Surge PR Preview
name: Preview Deployment

on: [pull_request]
on:
pull_request:
types: [opened, synchronize, reopened, closed]

env:
NODE: 18
WORKING_DIRECTORY: packages/web

jobs:
preview:
build:
runs-on: ubuntu-latest
permissions:
pull-requests: write # allow surge-preview to create/update PR comments
id-token: write
contents: read

steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout
uses: actions/checkout@v3

Expand All @@ -30,12 +39,29 @@ jobs:
run: yarn lint
working-directory: ${{ env.WORKING_DIRECTORY }}

- uses: afc163/surge-preview@v1
id: preview_step
- name: Configure AWS credentials using OIDC
uses: aws-actions/configure-aws-credentials@v2
with:
surge_token: ${{ secrets.SURGE_TOKEN }}
dist: dist
build: |
vite build
- name: Get the preview_url
run: echo "url => ${{ steps.preview_step.outputs.preview_url }}"
role-to-assume: arn:aws:iam::003081160852:role/osm-gradient-deploy-s3-role
aws-region: us-east-1

- name: Build
run: npx vite build
working-directory: ${{ env.WORKING_DIRECTORY }}

- name: Deploy to S3 (Preview)
if: github.event.action != 'closed'
run: |
PR_NUMBER=${{ github.event.number }}
BUCKET_NAME="osm-gradient-pr-${PR_NUMBER}"
aws s3 mb s3://$BUCKET_NAME
aws s3 sync ./dist s3://$BUCKET_NAME --delete
aws s3 website s3://$BUCKET_NAME --index-document index.html --error-document index.html
working-directory: ${{ env.WORKING_DIRECTORY }}

- name: Cleanup S3 Bucket
if: github.event.action == 'closed'
run: |
PR_NUMBER=${{ github.event.number }}
BUCKET_NAME="osm-gradient-pr-${PR_NUMBER}"
aws s3 rb s3://$BUCKET_NAME --force

0 comments on commit be86934

Please sign in to comment.