From d8093e3e2086874242eac82ddd202f35d5b8d558 Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Thu, 18 Aug 2022 16:56:28 +0300 Subject: [PATCH] feat: add clear cache for publish action (#2129) --- .github/workflows/publish.yml | 20 ++++++++++++++++++++ scripts/invalidate-cache.sh | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 scripts/invalidate-cache.sh diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bcd5f3f2..d5ce806b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -92,3 +92,23 @@ jobs: uses: actions/download-artifact@v3 - name: Publish to S3 run: npm run publish-cdn + + invalidate-cache: + name: Clear cache + runs-on: ubuntu-latest + needs: [check-version, publish-npm, publish-cli-s3, publish-cdn] + if: needs.check-version.outputs.changed == 'true' + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Configure AWS + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + - name: Invalidate cache + run: ./scripts/invalidate-cache.sh + shell: bash + env: + DISTRIBUTION: ${{ secrets.DISTRIBUTION }} diff --git a/scripts/invalidate-cache.sh b/scripts/invalidate-cache.sh new file mode 100755 index 00000000..94b72fa6 --- /dev/null +++ b/scripts/invalidate-cache.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -e # exit on error + +echo jsdelivr clearing cache +curl -i -X POST https://purge.jsdelivr.net/ \ + -H 'cache-control: no-cache' \ + -H 'content-type: application/json' \ + -d '{ + "path": [ + "npm/redoc@latest/bundles/redoc.browser.lib.js", + "npm/redoc@latest/bundles/redoc.lib.js", + "npm/redoc@latest/bundles/redoc.standalone.js" + ] + }' + +echo +echo start invalidate cloudfront + +aws cloudfront create-invalidation --distribution-id $DISTRIBUTION --paths "/redoc/*" + +echo Cache cleared successfully + +exit 0 \ No newline at end of file