Skip to content

Update docs and run script #2

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

Merged
merged 1 commit into from
Dec 11, 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
9 changes: 0 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,3 @@ jobs:
originPrefix: 'root'
invalidatePaths: ${{ steps.sync-html-s3.outputs.S3SyncedFiles }}
defaultRootObject: 'index.html'

# - name: Output Synced Files
# run: |
# echo "Synced HTML Files: $S3SyncedHTMLFiles"
# echo "Synced Immutable Files: $S3SyncedImmutableFiles"
# env:
# # Use outputs from the S3 step
# S3SyncedHTMLFiles: ${{ steps.sync-html-s3.outputs.S3SyncedFiles }}
# S3SyncedImmutableFiles: ${{ steps.sync-immutable-s3.outputs.S3SyncedFiles }}
6 changes: 2 additions & 4 deletions FEATURES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Features / TODO

- [x] Sync based on contents hash
- [x] Support prefixes
- [x] Support cleaning an object path
- [x] Custom cache-control headers
- [x] Strip originPrefix
- [x] Include slash for `defaultRootObject`
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,97 @@
# AWS CloudFront GitHub Action

## Motivation

I need a quick and easy way to invalidate a list of paths.

## Features

- Invalidate paths

## Getting Started

```yaml
name: 'Deploy'

concurrency:
group: prod_deploy
cancel-in-progress: false

on:
repository_dispatch:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened, closed]
push:
branches:
- master

jobs:
deploy:
name: 'Deploy'
runs-on: ubuntu-20.04
if: github.actor != 'dependabot[bot]' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
steps:
- uses: actions/checkout@v2

- name: Configure AWS Credentials
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

- uses: badsyntax/[email protected]
name: Update CloudFormation Stack
id: update-stack
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
stackName: 'static-example-richardwillis-cloudformation-stack'
template: './cloudformation/cloudformation-s3bucket-example.yml'
applyChangeSet: ${{ github.event_name != 'repository_dispatch' }}
awsRegion: 'us-east-1'
parameters: |
S3BucketName=static-example-richardwillis-info-us-east-1&
S3AllowedOrigins=https://static-example.richardwillis.info,https://*.preview.static-example.richardwillis.info&
CloudFrontRootHosts=static-example.richardwillis.info&
CertificateARN=arn:aws:acm:us-east-1:008215002370:certificate/39df7626-7d2f-42e9-94f4-a3ce61ca3d5e

- uses: badsyntax/[email protected]
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'
prefix: 'root'
stripExtensionGlob: '**/**.html'
cacheControl: 'public,max-age=0,s-maxage=31536000,must-revalidate'

- uses: badsyntax/[email protected]
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'
prefix: 'root'
cacheControl: 'public,max-age=31536000,immutable'

- uses: badsyntax/[email protected]
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.html'
```

## Debugging

Check the Action output for logs.
Expand Down
9 changes: 4 additions & 5 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env bash

INPUT_BUCKET="richardwillis.info-example-bucket-us-east-1" \
INPUT_ACTION="sync" \
INPUT_SRCGLOB="./out/css/**" \
INPUT_INVALIDATEPATHS="/,/index.html" \
INPUT_ORIGINPREFIX="" \
INPUT_AWSREGION="us-east-1" \
INPUT_PREFIX="preview" \
INPUT_DEFAULTROOTOBJECT="index.html" \
INPUT_CACHECONTROL="public,max-age=31536000,immutable" \
GITHUB_EVENT_NAME="pull_request" \
GITHUB_ACTION="synchronize" \
GITHUB_REPOSITORY="badsyntax/github-action-aws-cloudformation" \
GITHUB_REPOSITORY="badsyntax/github-action-aws-cloudfront" \
GITHUB_WORKSPACE=$(pwd) \
node lib/main.js