Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ jobs:
exit 0
fi

echo -n "${{ needs.setup-environment.outputs.deploy_dir }}" | aws s3 cp - s3://${{ secrets.AWS_S3_BUCKET }}/latest_version --endpoint ${{ secrets.AWS_ENDPOINT }} --content-type "text/plain"
echo -n "${{ needs.setup-environment.outputs.deploy_dir }}" | aws s3 cp - s3://${{ secrets.AWS_S3_BUCKET }}/latest_version --endpoint ${{ secrets.AWS_ENDPOINT }} --content-type "text/plain" --cache-control "no-cache"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand All @@ -181,11 +181,32 @@ jobs:
- name: Purge Cloudflare cache
if: env.HAS_CLOUDFLARE_SECRETS == 'true'
run: |
latest_version_url=""
if [ "${{ github.ref_type }}" = "tag" ]; then
latest_version_url="${{ inputs.base_url }}/latest_version"
fi

purge_payload="$(
jq -cn \
--arg public_url "${{ needs.setup-environment.outputs.public_url }}" \
--arg html_renderer_url "${{ needs.setup-environment.outputs.html_renderer_url }}" \
--arg latest_version_url "$latest_version_url" \
'[($public_url + "/"), ($html_renderer_url + "/"), $latest_version_url]
| map(select(length > 0))
| map(sub("^https?://"; ""))
| map(gsub("/+"; "/"))
| unique
| {prefixes: .}'
)"

echo "Purging Cloudflare cache prefixes:"
jq -r '.prefixes[] | " - \(.)"' <<<"$purge_payload"

response="$(
curl -sS --fail-with-body -X POST "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE_ID}/purge_cache" \
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
-H "Content-Type: application/json" \
--data '{"files":["${{ needs.setup-environment.outputs.public_url }}/web-component.html", "${{ needs.setup-environment.outputs.public_url }}/web-component.js", "${{ needs.setup-environment.outputs.public_url }}/scratch.html", "${{ needs.setup-environment.outputs.public_url }}/scratch.js", "${{ inputs.base_url }}/latest_version", "${{ needs.setup-environment.outputs.html_renderer_url}}/html-renderer.html", "${{ needs.setup-environment.outputs.html_renderer_url}}/html-renderer.js"]}'
--data "$purge_payload"
Comment on lines +184 to +209
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do find this code harder to understand now because it is doing a lot now and the has all the actions interpolation within it. Do you think extracting it to a bash or Ruby script could make it easier to follow? Or is there any other way to simplify it?

)" || {
echo "Cloudflare purge request failed:"
echo "$response"
Expand Down
Loading