File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 2121 },
2222 "media" : {
2323 "region" : " eu-west-2" ,
24+ "cloudfront-comment" : " The CloudFront ID is used to invalidate the cache after deployment." ,
25+ "cloudfront-id-staging" : " E7XZICS0M3W1S" ,
26+ "cloudfront-id-live" : " E2KTTVJ1I6I7D8" ,
2427 "syncs" : [
2528 {
2629 "bucket-comment" : " The bucket name is suffixed with -live or -staging depending on the branch." ,
Original file line number Diff line number Diff line change @@ -262,6 +262,22 @@ jobs:
262262 aws s3 sync "$source/" "s3://$bucket/$dest/" "${options_array[@]}"
263263 done
264264
265+ - name : Invalidate CloudFront cache
266+ run : |
267+ CONFIG='${{ needs.pre-check-media.outputs.config }}'
268+ CURRENT_BRANCH="${{ github.ref_name }}"
269+ if [ "$CURRENT_BRANCH" = "live" ]; then
270+ CLOUDFRONT_ID=$(echo "$CONFIG" | jq -r '.media["cloudfront-id-live"]')
271+ else
272+ CLOUDFRONT_ID=$(echo "$CONFIG" | jq -r '.media["cloudfront-id-staging"]')
273+ fi
274+ if [ -n "$CLOUDFRONT_ID" ] && [ "$CLOUDFRONT_ID" != "null" ]; then
275+ echo "Invalidating CloudFront cache for distribution $CLOUDFRONT_ID"
276+ aws cloudfront create-invalidation --distribution-id "$CLOUDFRONT_ID" --paths '/*'
277+ else
278+ echo "No CloudFront distribution ID found for branch $CURRENT_BRANCH. Skipping invalidation."
279+ fi
280+
265281 pre-check-vercel :
266282 needs : [deploy-to-book-server]
267283 if : always()
You can’t perform that action at this time.
0 commit comments