Skip to content

Commit

Permalink
Add "immutable" parameter to allow setting immutable cache-control (#97)
Browse files Browse the repository at this point in the history
* Add 'immutable' parameter

* Add immutable parameter to action inputs
  • Loading branch information
henrylegrys committed Mar 1, 2023
1 parent b2b20f0 commit 56640d5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}"` : '';
Expand All @@ -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 : '**';
Expand All @@ -30,6 +31,7 @@ let deploy = function (params) {
${invalidationArg} \
${deleteRemovedArg} \
${noCacheArg} \
${immutableArg} \
${privateArg} `;

const cwd = path.resolve(folder);
Expand Down
7 changes: 5 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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}"` : '';
Expand All @@ -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 : '**';
Expand All @@ -1881,6 +1883,7 @@ let deploy = function (params) {
${invalidationArg} \
${deleteRemovedArg} \
${noCacheArg} \
${immutableArg} \
${privateArg} `;

const cwd = path.resolve(folder);
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 56640d5

Please sign in to comment.