From 3073cf79ce3776e3bb341807aa581f699ae5612e Mon Sep 17 00:00:00 2001 From: Scott van Looy Date: Tue, 29 Jun 2021 06:59:22 +0200 Subject: [PATCH] update action to set configurable cache headers --- action.yml | 5 +++-- entrypoint.sh | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 907b751..f8f707e 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,9 @@ inputs: bucket_name: description: 'Bucket name' required: true + html_ttl: + description: "How long will the HTML files be allowed to be cached for?" + required: true project: description: 'Name of the project that contains the storage bucket.' required: true @@ -26,5 +29,3 @@ inputs: runs: using: 'docker' image: 'Dockerfile' - - diff --git a/entrypoint.sh b/entrypoint.sh index c624530..aa2befb 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -14,5 +14,11 @@ gsutil -m setmeta -h "Cache-Control:public, max-age=31536000" gs://"$INPUT_BUCKE gsutil -m setmeta -h "Cache-Control:public, max-age=31536000" gs://"$INPUT_BUCKET_NAME"/**/*.woff gsutil -m setmeta -h "Cache-Control:public, max-age=31536000" gs://"$INPUT_BUCKET_NAME"/**/*.woff2 gsutil -m setmeta -h "Cache-Control:public, max-age=31536000" gs://"$INPUT_BUCKET_NAME"/static/**/* -gsutil -m setmeta -h "Cache-Control:public, max-age=20" gs://"$INPUT_BUCKET_NAME"/**/*.json -gsutil -m setmeta -h "Cache-Control:public, max-age=20" gs://"$INPUT_BUCKET_NAME"/**/*.html +if [ "$INPUT_HTML_TTL" -eq "0" ] +then + gsutil -m setmeta -h "Cache-Control:no-cache,no-store,must-revalidate" gs://"$INPUT_BUCKET_NAME"/**/*.json + gsutil -m setmeta -h "Cache-Control:no-cache,no-store,must-revalidate" gs://"$INPUT_BUCKET_NAME"/**/*.html +else + gsutil -m setmeta -h "Cache-Control:public, max-age="$INPUT_HTML_TTL gs://"$INPUT_BUCKET_NAME"/**/*.json + gsutil -m setmeta -h "Cache-Control:public, max-age="$INPUT_HTML_TTL gs://"$INPUT_BUCKET_NAME"/**/*.html +fi