From 803ed4dac5cb0a2f8de14a601f6bbd5473461482 Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Wed, 10 Aug 2022 18:52:59 +0300 Subject: [PATCH 1/2] feat: add clear cache for publish action --- .github/workflows/publish.yml | 19 +++++++++++++++++++ package.json | 1 + scripts/clear-cache.sh | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 scripts/clear-cache.sh diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bcd5f3f26c..b5865b1d20 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -92,3 +92,22 @@ jobs: uses: actions/download-artifact@v3 - name: Publish to S3 run: npm run publish-cdn + + clearing-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: Clearing cache + run: npm run clear-cache + - name: Invalidate CloudFront + uses: chetan/invalidate-cloudfront-action@v2 + env: + PATHS: '/redoc/*' + AWS_REGION: 'us-east-1' + DISTRIBUTION: ${{ secrets.DISTRIBUTION }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/package.json b/package.json index 1ac82aa5a8..10aac209c6 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "compile:cli": "tsc custom.d.ts cli/index.ts --target es6 --module commonjs --types yargs", "build:demo": "webpack --mode=production --config demo/webpack.config.ts", "publish-cdn": "scripts/publish-cdn.sh", + "clear-cache": "scripts/clear-cache.sh", "deploy:demo": "aws s3 sync demo/dist s3://production-redoc-demo --acl=public-read", "license-check": "license-checker --production --onlyAllow 'MIT;ISC;Apache-2.0;BSD;BSD-2-Clause;BSD-3-Clause;CC-BY-4.0;Python-2.0' --summary", "docker:build": "docker build -f config/docker/Dockerfile -t redoc .", diff --git a/scripts/clear-cache.sh b/scripts/clear-cache.sh new file mode 100644 index 0000000000..5a9fc3c740 --- /dev/null +++ b/scripts/clear-cache.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -e # exit on error + +echo 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 Cache cleared successfully + +exit 0 \ No newline at end of file From 21e8d4c1d23dd78b8cf5a4e9dc35ac9c50769917 Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Thu, 11 Aug 2022 14:14:52 +0300 Subject: [PATCH 2/2] chore: fix acript after review --- .github/workflows/publish.yml | 19 ++++++++++--------- package.json | 1 - .../{clear-cache.sh => invalidate-cache.sh} | 6 +++++- 3 files changed, 15 insertions(+), 11 deletions(-) rename scripts/{clear-cache.sh => invalidate-cache.sh} (74%) mode change 100644 => 100755 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b5865b1d20..d5ce806bb9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -93,7 +93,7 @@ jobs: - name: Publish to S3 run: npm run publish-cdn - clearing-cache: + invalidate-cache: name: Clear cache runs-on: ubuntu-latest needs: [check-version, publish-npm, publish-cli-s3, publish-cdn] @@ -101,13 +101,14 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Clearing cache - run: npm run clear-cache - - name: Invalidate CloudFront - uses: chetan/invalidate-cloudfront-action@v2 + - 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: - PATHS: '/redoc/*' - AWS_REGION: 'us-east-1' DISTRIBUTION: ${{ secrets.DISTRIBUTION }} - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/package.json b/package.json index 10aac209c6..1ac82aa5a8 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,6 @@ "compile:cli": "tsc custom.d.ts cli/index.ts --target es6 --module commonjs --types yargs", "build:demo": "webpack --mode=production --config demo/webpack.config.ts", "publish-cdn": "scripts/publish-cdn.sh", - "clear-cache": "scripts/clear-cache.sh", "deploy:demo": "aws s3 sync demo/dist s3://production-redoc-demo --acl=public-read", "license-check": "license-checker --production --onlyAllow 'MIT;ISC;Apache-2.0;BSD;BSD-2-Clause;BSD-3-Clause;CC-BY-4.0;Python-2.0' --summary", "docker:build": "docker build -f config/docker/Dockerfile -t redoc .", diff --git a/scripts/clear-cache.sh b/scripts/invalidate-cache.sh old mode 100644 new mode 100755 similarity index 74% rename from scripts/clear-cache.sh rename to scripts/invalidate-cache.sh index 5a9fc3c740..94b72fa63c --- a/scripts/clear-cache.sh +++ b/scripts/invalidate-cache.sh @@ -2,7 +2,7 @@ set -e # exit on error -echo Clearing cache +echo jsdelivr clearing cache curl -i -X POST https://purge.jsdelivr.net/ \ -H 'cache-control: no-cache' \ -H 'content-type: application/json' \ @@ -15,6 +15,10 @@ curl -i -X POST https://purge.jsdelivr.net/ \ }' 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