Skip to content

Commit

Permalink
update(ci) deploy to the staging distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
leinaD006 committed Nov 2, 2024
1 parent c3b8055 commit 454e4b3
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ jobs:
id-token: write
runs-on: ubuntu-latest
environment:
name: production
url: https://pizza.danielkingery.click
name: staging
url: https://stage-pizza.danielkingery.click
env:
version: ${{needs.build.outputs.version}}
steps:
Expand All @@ -88,6 +88,19 @@ jobs:
echo Deploying $version
aws s3 cp dist s3://${{ secrets.APP_BUCKET }}/$version --recursive
- name: Update staging version
run: |
# Get the current distribution and update it to use the new version
aws cloudfront get-distribution-config --id ${{ secrets.DISTRIBUTION_ID }} > original.json
etag=$(jq -r '.ETag' original.json)
jq '.DistributionConfig' original.json > request.json
jq --arg version "/$version" '.Origins.Items[0].OriginPath = $version' request.json > finalRequest.json
aws cloudfront update-distribution --id ${{ secrets.DISTRIBUTION_ID }} --if-match $etag --distribution-config file://finalRequest.json
# Wait for the distribution to deploy and then invalidate the cache
while [ "$(aws cloudfront get-distribution --id ${{ secrets.DISTRIBUTION_ID }} --query 'Distribution.Status' --output text)" != "Deployed" ]; do echo "Distribution is still updating..."; sleep 5; done
aws cloudfront create-invalidation --distribution-id ${{ secrets.DISTRIBUTION_ID }} --paths "/*"
release:
needs:
- build
Expand Down

0 comments on commit 454e4b3

Please sign in to comment.