Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use kebab-case for input names #16

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,53 +28,52 @@ jobs:
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- uses: badsyntax/github-action-aws-cloudformation@v0.0.3
- uses: badsyntax/github-action-aws-cloudformation@v0.0.5
name: Update CloudFormation Stack
id: update-stack
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
stackName: 'badsyntax-github-action-example-aws-cloudfront'
stack-name: 'badsyntax-github-action-example-aws-cloudfront'
template: './cloudformation/s3-cloudfront.yml'
applyChangeSet: ${{ github.event_name != 'repository_dispatch' }}
awsRegion: 'us-east-1'
apply-change-set: ${{ github.event_name != 'repository_dispatch' }}
aws-region: 'us-east-1'
parameters: |
S3BucketName=badsyntax-github-action-example-aws-cloudfront-us-east-1&
S3AllowedOrigins=https://cloudfront-action.richardwillis.info&
CloudFrontRootHosts=cloudfront-action.richardwillis.info&
CertificateARN=arn:aws:acm:us-east-1:008215002370:certificate/cfb34309-b9bb-4f63-9af3-51026b8107d6

- uses: badsyntax/github-action-aws-s3@v0.0.2
- uses: badsyntax/github-action-aws-s3@v0.0.3
name: Sync mutable HTML files to S3
id: sync-html-s3
with:
bucket: ${{ steps.update-stack.outputs.S3BucketName }}
action: 'sync'
srcDir: './out'
filesGlob: '**/*.html'
awsRegion: 'us-east-1'
src-dir: './out'
files-glob: '**/*.html'
aws-region: 'us-east-1'
prefix: 'root'
stripExtensionGlob: '**/**.html'
cacheControl: 'public,max-age=0,s-maxage=31536000,must-revalidate'
strip-extension-glob: '**/**.html'
cache-control: 'public,max-age=0,s-maxage=31536000,must-revalidate'

- uses: badsyntax/github-action-aws-s3@v0.0.2
- uses: badsyntax/github-action-aws-s3@v0.0.3
name: Sync immutable files to S3
id: sync-immutable-s3
with:
bucket: ${{ steps.update-stack.outputs.S3BucketName }}
action: 'sync'
srcDir: './out'
filesGlob: 'css/**'
awsRegion: 'us-east-1'
src-dir: './out'
files-glob: 'css/**'
aws-region: 'us-east-1'
prefix: 'root'
cacheControl: 'public,max-age=31536000,immutable'
cache-control: 'public,max-age=31536000,immutable'

- uses: ./
name: Invalidate CloudFront Cache
id: invalidate-cloudfront-cache
with:
distributionId: ${{ steps.update-stack.outputs.CFDistributionId }}
awsRegion: 'us-east-1'
originPrefix: 'root'
invalidatePaths: ${{ steps.sync-html-s3.outputs.S3SyncedFiles }}
defaultRootObject: 'index'
includeOriginPrefix: true
distribution-id: ${{ steps.update-stack.outputs.CFDistributionId }}
aws-region: 'us-east-1'
origin-prefix: 'root'
invalidate-paths: ${{ steps.sync-html-s3.outputs.S3SyncedFiles }}
default-root-object: 'index'
include-origin-prefix: true
4 changes: 0 additions & 4 deletions FEATURES.md

This file was deleted.

40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

A GitHub Action to invalidate a list of CloudFront paths.

The Action will generate a new list based on input options. This is especially helpful when you're piping in origin paths (eg from an S3 Action) that need to be transformed into absolute URL paths from root. You can also include origin prefixes to cache-bust URL's rewritten by Lambda's (in which case you need to invalidate both the `viewer-request` and rewritten URL's). A root slash `/` is added if a url matches the `defaultRootObject`.
The Action will generate a new list based on input options. This is especially helpful when you're piping in origin paths (eg from an S3 Action) that need to be transformed into absolute URL paths from root. You can also include origin prefixes to cache-bust URL's rewritten by Lambda's (in which case you need to invalidate both the `viewer-request` and rewritten URL's). A root slash `/` is added if a url matches the `default-root-object`.

## Example Path Transformations

| input | prefix | includeOriginPrefix | defaultRootObject | output |
| ------------------------------------- | -------- | ------------------- | ----------------- | ----------------------------------------------------------- |
| `index.html,blog.html,css/styles.css` | `(none)` | `false` | `index.html` | `/index.html,/blog.html,/css/styles.css,/` |
| `root/index,/root/css/styles.css,/` | `root` | `false` | `index` | `/index,/css/styles.css,/` |
| `root/index,root/css/styles.css` | `root` | `true` | `index` | `/index,/root/index,/css/styles.css,/root/css/styles.css,/` |
| input | prefix | include-origin-prefix | default-root-object | output |
| ------------------------------------- | -------- | --------------------- | ------------------- | ----------------------------------------------------------- |
| `index.html,blog.html,css/styles.css` | `(none)` | `false` | `index.html` | `/index.html,/blog.html,/css/styles.css,/` |
| `root/index,/root/css/styles.css,/` | `root` | `false` | `index` | `/index,/css/styles.css,/` |
| `root/index,root/css/styles.css` | `root` | `true` | `index` | `/index,/root/index,/css/styles.css,/root/css/styles.css,/` |

## Getting Started

Expand Down Expand Up @@ -50,24 +50,24 @@ jobs:
name: Invalidate CloudFront Cache
id: invalidate-cloudfront-cache
with:
distributionId: ${{ secrets.CFDistributionId }}
awsRegion: 'us-east-1'
originPrefix: 'root'
includeOriginPrefix: true
invalidatePaths: '/index.html,/'
defaultRootObject: 'index.html'
distribution-id: ${{ secrets.CFDistributionId }}
aws-region: 'us-east-1'
origin-prefix: 'root'
include-origin-prefix: true
invalidate-paths: '/index.html,/'
default-root-object: 'index.html'
```

## Action Inputs

| key | description | example |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
| `invalidatePaths` | Comma separated list of invalidation paths | `root/blog.html,root/index.html` |
| `distributionId` | The CloudFront Distribution Id | `ABC123DEF` |
| `originPrefix` | The prefix of the object location in origin, which will be optionally stripped from the invalidation paths, if `includeOriginPrefix` is false. For example if originPrefix is "root" and invalidationPath is "root/blog.html" then the final path will be "blog.html" | `root` |
| `includeOriginPrefix` | Whether to include origin prefix paths. Useful when paths ere rewritten by Lambda's | `true` |
| `defaultRootObject` | The object returned when a user requests the root URL for your distribution. If this path is invalidated then a slash (/) is added to the invalidation paths | `index.html` |
| `awsRegion` | The AWS region | `us-east-1` |
| key | description | example |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------- |
| `invalidate-paths` | Comma separated list of invalidation paths | `root/blog.html,root/index.html` |
| `distribution-id` | The CloudFront Distribution Id | `ABC123DEF` |
| `origin-prefix` | The prefix of the object location in origin, which will be optionally stripped from the invalidation paths, if `include-origin-prefix` is false. For example if origin-prefix is "root" and invalidationPath is "root/blog.html" then the final path will be "blog.html" | `root` |
| `include-origin-prefix` | Whether to include origin prefix paths. Useful when paths ere rewritten by Lambda's | `true` |
| `default-root-object` | The object returned when a user requests the root URL for your distribution. If this path is invalidated then a slash (/) is added to the invalidation paths | `index.html` |
| `aws-region` | The AWS region | `us-east-1` |

## Cache Invalidation Gotchas

Expand Down
14 changes: 7 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ branding:
icon: 'upload-cloud'
color: 'gray-dark'
inputs:
invalidatePaths:
invalidate-paths:
required: false
default: ''
description: 'Comma separated list of invalidation paths. For example: root/blog.html,root/index.html'
distributionId:
distribution-id:
required: true
description: 'The CloudFront Distribution Id'
originPrefix:
origin-prefix:
required: false
default: ''
description: 'The prefix of the object location in origin, which will be stripped from the invalidation paths. For example if originPrefix is "root" and invalidationPath is "root/blog.html" then the final path will be "blog.html"'
defaultRootObject:
description: 'The prefix of the object location in origin, which will be stripped from the invalidation paths. For example if origin-prefix is "root" and invalidationPath is "root/blog.html" then the final path will be "blog.html"'
default-root-object:
required: true
description: 'The object returned when a user requests the root URL for your distribution. If this path is invalidated then a slash (/) is added to the invalidation paths'
awsRegion:
aws-region:
require: true
description: 'The AWS region. For example: us-east-1'
includeOriginPrefix:
include-origin-prefix:
require: true
description: "Whether to include origin prefix paths. Useful when paths ere rewritten by Lambda's"
runs:
Expand Down
12 changes: 6 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@ import { getInput } from '@actions/core';

export function getInputs() {
const invalidatePaths =
getInput('invalidatePaths', {
getInput('invalidate-paths', {
required: false,
trimWhitespace: true,
}) || '';

const distributionId = getInput('distributionId', {
const distributionId = getInput('distribution-id', {
required: true,
trimWhitespace: true,
});

const originPrefix =
getInput('originPrefix', {
getInput('origin-prefix', {
required: false,
trimWhitespace: true,
}) || '';

const defaultRootObject = getInput('defaultRootObject', {
const defaultRootObject = getInput('default-root-object', {
required: true,
trimWhitespace: true,
});

const region = getInput('awsRegion', {
const region = getInput('aws-region', {
required: true,
trimWhitespace: true,
});

const includeOriginPrefix =
getInput('includeOriginPrefix', {
getInput('include-origin-prefix', {
required: true,
trimWhitespace: true,
}).toLowerCase() === 'true';
Expand Down