From 56640d5ff51c6b50d74596a2762a3b7c7271250b Mon Sep 17 00:00:00 2001 From: Henry Le Grys <92093353+henrylegrys@users.noreply.github.com> Date: Wed, 1 Mar 2023 21:58:11 +0000 Subject: [PATCH] Add "immutable" parameter to allow setting immutable cache-control (#97) * Add 'immutable' parameter * Add immutable parameter to action inputs --- README.md | 25 +++++++++++++------------ action.yml | 3 +++ deploy.js | 4 +++- dist/index.js | 7 +++++-- index.js | 3 ++- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 1282f0b..f64d133 100644 --- a/README.md +++ b/README.md @@ -20,18 +20,19 @@ with: S3 Deploy's Action supports inputs from the user listed in the table below: -| Input | Type | Required | Default | Description | -|--------------------|------------------|----------|-----------|--------------------------------------------------------------------------------------------| -| `folder` | string | Yes | | The folder to upload | -| `bucket` | string | Yes | | The destination bucket | -| `bucket-region` | string | Yes | | The destination bucket region | -| `dist-id` | string | No | undefined | The CloudFront Distribution ID to invalidate | -| `invalidation` | string | No | '/' | The CloudFront Distribution path(s) to invalidate | -| `delete-removed` | boolean / string | No | false | Removes files in S3, that are not available in the local copy of the directory | -| `no-cache` | boolean | No | false | Use this parameter to specify `Cache-Control: no-cache, no-store, must-revalidate` header | -| `private` | boolean | No | false | Upload files with private ACL, needed for S3 static website hosting | -| `cache` | string | No | | Sets the Cache-Control: max-age=X header | -| `files-to-include` | string | No | "**" | Allows for a comma delineated Regex String that matches files to include in the deployment | + Input | Type | Required | Default | Description +--------------------| ---------------- | -------- | ------------ | ----------- +| `folder` | string | Yes | | The folder to upload +| `bucket` | string | Yes | | The destination bucket +| `bucket-region` | string | Yes | | The destination bucket region +| `dist-id` | string | No | undefined | The CloudFront Distribution ID to invalidate +| `invalidation` | string | No | '/' | The CloudFront Distribution path(s) to invalidate +| `delete-removed` | boolean / string | No | false | Removes files in S3, that are not available in the local copy of the directory +| `noCache` | boolean | No | false | Use this parameter to specify `Cache-Control: no-cache, no-store, must-revalidate` header +| `private` | boolean | No | false | Upload files with private ACL, needed for S3 static website hosting +| `cache` | string | No | | Sets the Cache-Control: max-age=X header +| `immutable` | boolean | No | false | Sets the Cache-Control header to 'immutable' +| `files-to-include` | string | No | "**" | Allows for a comma delineated Regex String that matches files to include in the deployment ### Example `workflow.yml` with S3 Deploy Action diff --git a/action.yml b/action.yml index 16b2752..cf50369 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,9 @@ inputs: cache: description: 'Sets the Cache-Control: max-age=X header' required: false + immutable: + description: 'Sets the Cache-Control header to immutable' + required: false files-to-include: description: 'Allows for a comma delineated Regex String that matches files to include in the deployment' required: false diff --git a/deploy.js b/deploy.js index fed83c9..df109de 100644 --- a/deploy.js +++ b/deploy.js @@ -3,7 +3,7 @@ const exec = require('@actions/exec'); let deploy = function (params) { return new Promise((resolve, reject) => { - const { folder, bucket, bucketRegion, distId, invalidation, deleteRemoved, noCache, private, cache, filesToInclude } = params; + const { folder, bucket, bucketRegion, distId, invalidation, deleteRemoved, noCache, private, cache, immutable, filesToInclude } = params; const distIdArg = distId ? `--distId ${distId}` : ''; const invalidationArg = distId ? `--invalidate "${invalidation}"` : ''; @@ -14,6 +14,7 @@ let deploy = function (params) { : `--deleteRemoved ${deleteRemoved}` : ''; const noCacheArg = noCache ? '--noCache' : ''; + const immutableArg = immutable ? '--immutable' : ''; const privateArg = private ? '--private' : ''; const cacheFlag = cache ? `--cache ${cache}` : ''; const filesRegex = filesToInclude ? filesToInclude : '**'; @@ -30,6 +31,7 @@ let deploy = function (params) { ${invalidationArg} \ ${deleteRemovedArg} \ ${noCacheArg} \ + ${immutableArg} \ ${privateArg} `; const cwd = path.resolve(folder); diff --git a/dist/index.js b/dist/index.js index fc2927d..de08b91 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1218,10 +1218,11 @@ async function run() { const deleteRemoved = core.getInput('delete-removed') || false; const noCache = getBooleanInput('no-cache'); const private = getBooleanInput('private'); + const immutable = getBooleanInput('immutable'); const cache = core.getInput('cache') || null; const filesToInclude = core.getInput('files-to-include') || null; - await deploy({ folder, bucket, bucketRegion, distId, invalidation, deleteRemoved, noCache, private, cache, filesToInclude }); + await deploy({ folder, bucket, bucketRegion, distId, invalidation, deleteRemoved, noCache, private, cache, immutable, filesToInclude }); } catch (error) { core.setFailed(error.message); } @@ -1854,7 +1855,7 @@ const exec = __webpack_require__(986); let deploy = function (params) { return new Promise((resolve, reject) => { - const { folder, bucket, bucketRegion, distId, invalidation, deleteRemoved, noCache, private, cache, filesToInclude } = params; + const { folder, bucket, bucketRegion, distId, invalidation, deleteRemoved, noCache, private, cache, immutable, filesToInclude } = params; const distIdArg = distId ? `--distId ${distId}` : ''; const invalidationArg = distId ? `--invalidate "${invalidation}"` : ''; @@ -1865,6 +1866,7 @@ let deploy = function (params) { : `--deleteRemoved ${deleteRemoved}` : ''; const noCacheArg = noCache ? '--noCache' : ''; + const immutableArg = immutable ? '--immutable' : ''; const privateArg = private ? '--private' : ''; const cacheFlag = cache ? `--cache ${cache}` : ''; const filesRegex = filesToInclude ? filesToInclude : '**'; @@ -1881,6 +1883,7 @@ let deploy = function (params) { ${invalidationArg} \ ${deleteRemovedArg} \ ${noCacheArg} \ + ${immutableArg} \ ${privateArg} `; const cwd = path.resolve(folder); diff --git a/index.js b/index.js index 89fea12..ddd9360 100644 --- a/index.js +++ b/index.js @@ -15,10 +15,11 @@ async function run() { const deleteRemoved = core.getInput('delete-removed') || false; const noCache = getBooleanInput('no-cache'); const private = getBooleanInput('private'); + const immutable = getBooleanInput('immutable'); const cache = core.getInput('cache') || null; const filesToInclude = core.getInput('files-to-include') || null; - await deploy({ folder, bucket, bucketRegion, distId, invalidation, deleteRemoved, noCache, private, cache, filesToInclude }); + await deploy({ folder, bucket, bucketRegion, distId, invalidation, deleteRemoved, noCache, private, cache, immutable, filesToInclude }); } catch (error) { core.setFailed(error.message); }