From 454e4b32820be59ae7f41cbf1f520421d4dafbed Mon Sep 17 00:00:00 2001 From: Daniel Kingery Date: Fri, 1 Nov 2024 20:38:15 -0600 Subject: [PATCH] update(ci) deploy to the staging distribution --- .github/workflows/ci.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 888ffadc1..e3ee14cdd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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