From 8927a3fae2e99ca392ecc1f3c08ad69ee3e1fd0d Mon Sep 17 00:00:00 2001 From: Matteo Marsala Date: Fri, 23 Aug 2024 14:10:32 +0200 Subject: [PATCH 1/5] Purge cache action --- .github/workflows/deploy-production.yml | 25 +++++++------------ .github/workflows/deploy-staging.yml | 33 ++++++++++--------------- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index cae7749e33..4d924928b1 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -26,7 +26,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 1 + fetch-depth: 0 - uses: actions/setup-node@v4 with: node-version: 18 @@ -82,19 +82,12 @@ jobs: # Don't cache any HTML or JSON file: they should always be up-to-dates run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.pdf" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ - # - name: Sync PDF - # run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ + - name: Sync PDF + run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ - # - name: Purge cache on CloudFlare - # run: | - # curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache" \ - # -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_PURGE_API_TOKEN }}" \ - # -H "Content-Type: application/json" \ - # --data '{"prefixes":["${{ vars.DATASHEETS_BASE_URL }}"]}' - - - name: Sync all cacheable assets - run: aws s3 sync --cache-control "public, max-age=31536000, immutable" --include "*.css" --include="*.js" --include="*.gif" --include="*.png" --include="*.svg" --exclude "*.html" --exclude="sw.js" --exclude="*.json" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ - - - name: Sync all non-cacheable assets - # Don't cache any HTML or JSON file: they should always be up-to-dates - run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ + - name: Purge cache on CloudFlare + run: | + curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache" \ + -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_PURGE_API_TOKEN }}" \ + -H "Content-Type: application/json" \ + --data '{"prefixes":["${{ vars.DATASHEETS_BASE_URL }}"]}' diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 0c67404381..1dec4c1ae8 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -25,7 +25,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 1 + fetch-depth: 0 - uses: actions/setup-node@v4 with: node-version: 18 @@ -74,27 +74,20 @@ jobs: role-to-assume: ${{ secrets.STAGING_IAM_ROLE }} aws-region: us-east-1 - # - name: Sync all cacheable assets - # run: aws s3 sync --cache-control "public, max-age=31536000, immutable" --include "*.css" --include="*.js" --include="*.gif" --include="*.png" --include="*.svg" --exclude "*.html" --exclude="sw.js" --exclude="*.json" --exclude="*.pdf" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ - - # - name: Sync all non-cacheable assets - # # Don't cache any HTML or JSON file: they should always be up-to-dates - # run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.pdf" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ - - # - name: Sync PDF - # run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ - - # - name: Purge cache on CloudFlare - # run: | - # curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache" \ - # -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_PURGE_API_TOKEN }}" \ - # -H "Content-Type: application/json" \ - # --data '{"prefixes":["${{ vars.DATASHEETS_BASE_URL }}"]}' - - name: Sync all cacheable assets - run: aws s3 sync --cache-control "public, max-age=31536000, immutable" --include "*.css" --include="*.js" --include="*.gif" --include="*.png" --include="*.svg" --exclude "*.html" --exclude="sw.js" --exclude="*.json" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ + run: aws s3 sync --cache-control "public, max-age=31536000, immutable" --include "*.css" --include="*.js" --include="*.gif" --include="*.png" --include="*.svg" --exclude "*.html" --exclude="sw.js" --exclude="*.json" --exclude="*.pdf" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ - name: Sync all non-cacheable assets # Don't cache any HTML or JSON file: they should always be up-to-dates - run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ + run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.pdf" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ + + - name: Sync PDF + run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ + + - name: Purge cache on CloudFlare + run: | + curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache" \ + -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_PURGE_API_TOKEN }}" \ + -H "Content-Type: application/json" \ + --data '{"prefixes":["${{ vars.DATASHEETS_BASE_URL }}"]}' From 92bb5238d4f14b66aa7e4cfe0eba66257aef41a5 Mon Sep 17 00:00:00 2001 From: Matteo Marsala Date: Mon, 26 Aug 2024 08:41:24 +0200 Subject: [PATCH 2/5] use temp dir --- .github/workflows/deploy-production.yml | 2 +- .github/workflows/deploy-staging.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index 4d924928b1..b33e5d1f49 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -83,7 +83,7 @@ jobs: run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.pdf" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ - name: Sync PDF - run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ + run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ --temp-dir /tmp/aws-sync-temp - name: Purge cache on CloudFlare run: | diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 1dec4c1ae8..4958cfb621 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -82,7 +82,7 @@ jobs: run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.pdf" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ - name: Sync PDF - run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ + run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ --temp-dir /tmp/aws-sync-temp - name: Purge cache on CloudFlare run: | From a3146da1afba7938f3bb0f0c9bcce74daebc260b Mon Sep 17 00:00:00 2001 From: Matteo Marsala Date: Mon, 26 Aug 2024 09:35:33 +0200 Subject: [PATCH 3/5] delete temporary files --- .github/workflows/deploy-production.yml | 3 +++ .github/workflows/deploy-staging.yml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index b33e5d1f49..78d6371be8 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -85,6 +85,9 @@ jobs: - name: Sync PDF run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ --temp-dir /tmp/aws-sync-temp + - name: Cleanup temporary files + run: rm -rf /tmp/aws-sync-temp + - name: Purge cache on CloudFlare run: | curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache" \ diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 4958cfb621..8b9d72c3b1 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -84,6 +84,9 @@ jobs: - name: Sync PDF run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ --temp-dir /tmp/aws-sync-temp + - name: Cleanup temporary files + run: rm -rf /tmp/aws-sync-temp + - name: Purge cache on CloudFlare run: | curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache" \ From 025b8ef9462627358296fe795e6d9c832aa37efc Mon Sep 17 00:00:00 2001 From: Matteo Marsala Date: Mon, 26 Aug 2024 10:47:34 +0200 Subject: [PATCH 4/5] delete temporary files --- .github/workflows/deploy-production.yml | 8 +++++++- .github/workflows/deploy-staging.yml | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index 78d6371be8..fb61b4c4bc 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -82,8 +82,14 @@ jobs: # Don't cache any HTML or JSON file: they should always be up-to-dates run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.pdf" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ + - name: Create temporary directory + run: mkdir -p /tmp/aws-sync-temp + + - name: Copy files to temporary directory + run: cp -r public/*.pdf /tmp/aws-sync-temp/ + - name: Sync PDF - run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ --temp-dir /tmp/aws-sync-temp + run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" /tmp/aws-sync-temp/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ --exclude "*.js" --exclude "*.gif" --exclude "*.png" --exclude "*.svg" --exclude "*.css" --exclude "*.html" --exclude "*.json" --exclude "sw.json" --delete - name: Cleanup temporary files run: rm -rf /tmp/aws-sync-temp diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 8b9d72c3b1..bec18e04dd 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -81,8 +81,14 @@ jobs: # Don't cache any HTML or JSON file: they should always be up-to-dates run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.pdf" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ + - name: Create temporary directory + run: mkdir -p /tmp/aws-sync-temp + + - name: Copy files to temporary directory + run: cp -r public/*.pdf /tmp/aws-sync-temp/ + - name: Sync PDF - run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ --temp-dir /tmp/aws-sync-temp + run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" /tmp/aws-sync-temp/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ --exclude "*.js" --exclude "*.gif" --exclude "*.png" --exclude "*.svg" --exclude "*.css" --exclude "*.html" --exclude "*.json" --exclude "sw.json" --delete - name: Cleanup temporary files run: rm -rf /tmp/aws-sync-temp From 058110f44d6419700848b7cd84ae0e10f9c66017 Mon Sep 17 00:00:00 2001 From: Matteo Marsala Date: Wed, 4 Sep 2024 09:59:45 +0200 Subject: [PATCH 5/5] manual action for purge cache --- .github/workflows/deploy-production.yml | 30 +++++---- .github/workflows/deploy-staging.yml | 41 ++++++------ .github/workflows/purge-cache.yml | 83 +++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/purge-cache.yml diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index fb61b4c4bc..24b5439ec8 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -26,7 +26,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 1 - uses: actions/setup-node@v4 with: node-version: 18 @@ -82,21 +82,19 @@ jobs: # Don't cache any HTML or JSON file: they should always be up-to-dates run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.pdf" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ - - name: Create temporary directory - run: mkdir -p /tmp/aws-sync-temp + # - name: Sync PDF + # run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ - - name: Copy files to temporary directory - run: cp -r public/*.pdf /tmp/aws-sync-temp/ + # - name: Purge cache on CloudFlare + # run: | + # curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache" \ + # -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_PURGE_API_TOKEN }}" \ + # -H "Content-Type: application/json" \ + # --data '{"prefixes":["${{ vars.DATASHEETS_BASE_URL }}"]}' - - name: Sync PDF - run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" /tmp/aws-sync-temp/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ --exclude "*.js" --exclude "*.gif" --exclude "*.png" --exclude "*.svg" --exclude "*.css" --exclude "*.html" --exclude "*.json" --exclude "sw.json" --delete - - - name: Cleanup temporary files - run: rm -rf /tmp/aws-sync-temp + - name: Sync all cacheable assets + run: aws s3 sync --cache-control "public, max-age=31536000, immutable" --include "*.css" --include="*.js" --include="*.gif" --include="*.png" --include="*.svg" --exclude "*.html" --exclude="sw.js" --exclude="*.json" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ - - name: Purge cache on CloudFlare - run: | - curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache" \ - -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_PURGE_API_TOKEN }}" \ - -H "Content-Type: application/json" \ - --data '{"prefixes":["${{ vars.DATASHEETS_BASE_URL }}"]}' + - name: Sync all non-cacheable assets + # Don't cache any HTML or JSON file: they should always be up-to-dates + run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ \ No newline at end of file diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index bec18e04dd..ff6c524d61 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -25,7 +25,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 1 - uses: actions/setup-node@v4 with: node-version: 18 @@ -74,29 +74,26 @@ jobs: role-to-assume: ${{ secrets.STAGING_IAM_ROLE }} aws-region: us-east-1 - - name: Sync all cacheable assets - run: aws s3 sync --cache-control "public, max-age=31536000, immutable" --include "*.css" --include="*.js" --include="*.gif" --include="*.png" --include="*.svg" --exclude "*.html" --exclude="sw.js" --exclude="*.json" --exclude="*.pdf" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ - - - name: Sync all non-cacheable assets - # Don't cache any HTML or JSON file: they should always be up-to-dates - run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.pdf" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ - - - name: Create temporary directory - run: mkdir -p /tmp/aws-sync-temp + # - name: Sync all cacheable assets + # run: aws s3 sync --cache-control "public, max-age=31536000, immutable" --include "*.css" --include="*.js" --include="*.gif" --include="*.png" --include="*.svg" --exclude "*.html" --exclude="sw.js" --exclude="*.json" --exclude="*.pdf" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ - - name: Copy files to temporary directory - run: cp -r public/*.pdf /tmp/aws-sync-temp/ + # - name: Sync all non-cacheable assets + # # Don't cache any HTML or JSON file: they should always be up-to-dates + # run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.pdf" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ - - name: Sync PDF - run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" /tmp/aws-sync-temp/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ --exclude "*.js" --exclude "*.gif" --exclude "*.png" --exclude "*.svg" --exclude "*.css" --exclude "*.html" --exclude "*.json" --exclude "sw.json" --delete + # - name: Sync PDF + # run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ - - name: Cleanup temporary files - run: rm -rf /tmp/aws-sync-temp + # - name: Purge cache on CloudFlare + # run: | + # curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache" \ + # -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_PURGE_API_TOKEN }}" \ + # -H "Content-Type: application/json" \ + # --data '{"prefixes":["${{ vars.DATASHEETS_BASE_URL }}"]}' - - name: Purge cache on CloudFlare - run: | - curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache" \ - -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_PURGE_API_TOKEN }}" \ - -H "Content-Type: application/json" \ - --data '{"prefixes":["${{ vars.DATASHEETS_BASE_URL }}"]}' + - name: Sync all cacheable assets + run: aws s3 sync --cache-control "public, max-age=31536000, immutable" --include "*.css" --include="*.js" --include="*.gif" --include="*.png" --include="*.svg" --exclude "*.html" --exclude="sw.js" --exclude="*.json" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ + - name: Sync all non-cacheable assets + # Don't cache any HTML or JSON file: they should always be up-to-dates + run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/ \ No newline at end of file diff --git a/.github/workflows/purge-cache.yml b/.github/workflows/purge-cache.yml new file mode 100644 index 0000000000..8821b89ee3 --- /dev/null +++ b/.github/workflows/purge-cache.yml @@ -0,0 +1,83 @@ +name: Purge cache on CloudFlare + +on: + workflow_dispatch: + +permissions: + id-token: write + contents: read + +jobs: + purge: + if: "github.repository == 'arduino/docs-content'" + runs-on: ubuntu-latest + environment: production + env: + REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} + APP_ENV: prod + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-node@v4 + with: + node-version: 18 + cache: "npm" + cache-dependency-path: "**/package-lock.json" + + - name: Render Datasheets + run: cd ${GITHUB_WORKSPACE}/scripts/datasheet-rendering;./render-datasheets.sh + + - name: Copy Static Files + run: | + mkdir -p static/resources/datasheets static/resources/schematics static/resources/pinouts static/resources/models + find ./content/hardware -type f -name "*-schematics.pdf" -exec cp {} ./static/resources/schematics/ \; + find ./content/hardware -type f -name "*-datasheet.pdf" -exec cp {} ./static/resources/datasheets/ \; + find ./content/hardware -type f -name "*-full-pinout.pdf" -exec cp {} ./static/resources/pinouts/ \; + find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \; + find ./content/hardware -type f -name "*-step.zip" -exec cp {} ./static/resources/models/ \; + + - name: Gatsby main cache + uses: actions/cache@v4 + id: gatsby-cache-folder + with: + path: .cache + key: ${{ runner.os }}-cache-gatsby-${{ github.ref_name }} + restore-keys: | + ${{ runner.os }}-cache-gatsby-main + + - name: Gatsby Public Folder + uses: actions/cache@v4 + id: gatsby-public-folder + with: + path: public/ + key: ${{ runner.os }}-public-gatsby-${{ github.ref_name }} + restore-keys: | + ${{ runner.os }}-public-gatsby-main + + - run: npm install + - run: npm run build + + - name: Configure AWS credentials from Production account + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.PRODUCTION_IAM_ROLE }} + aws-region: us-east-1 + + - name: Sync all cacheable assets + run: aws s3 sync --cache-control "public, max-age=31536000, immutable" --include "*.css" --include="*.js" --include="*.gif" --include="*.png" --include="*.svg" --exclude "*.html" --exclude="sw.js" --exclude="*.json" --exclude="*.pdf" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ + + - name: Sync all non-cacheable assets + # Don't cache any HTML or JSON file: they should always be up-to-dates + run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.pdf" --delete public/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ + + - name: Sync PDF + run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" /tmp/aws-sync-temp/ s3://${{ secrets.PRODUCTION_BUCKET_NAME }}/ --exclude "*.js" --exclude "*.gif" --exclude "*.png" --exclude "*.svg" --exclude "*.css" --exclude "*.html" --exclude "*.json" --exclude "sw.json" --delete + + - name: Purge cache on CloudFlare + run: | + curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache" \ + -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_PURGE_API_TOKEN }}" \ + -H "Content-Type: application/json" \ + --data '{"prefixes":["${{ vars.DATASHEETS_BASE_URL }}"]}'