Skip to content
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
2 changes: 2 additions & 0 deletions .github/actions/test-deploy-to-s3-bucket/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ runs:
pattern: 'archive.tgz'
s3-bucket: shopsmart-github-actions-tests
s3-bucket-path: ${{ steps.id.outputs.id }}
cache-control: max-age=3600

- name: 'Validate'
shell: bash
run: bats --tap --verbose-run ${{ github.action_path }}/deploy-to-s3-bucket.bats
env:
S3_BUCKET: shopsmart-github-actions-tests
S3_BUCKET_PATH: ${{ steps.id.outputs.id }}
CACHE_CONTROL: max-age=3600
12 changes: 12 additions & 0 deletions .github/actions/test-deploy-to-s3-bucket/deploy-to-s3-bucket.bats
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,15 @@ function teardown() {
[ "$status" -eq 0 ]
[[ "$output" =~ $S3_TAG ]]
}


@test "it should have set the cache-control metadata" {
run aws s3api head-object --no-cli-pager \
--bucket "$S3_BUCKET" \
--key "$S3_BUCKET_PATH/style.css" \
--query 'CacheControl' \
--output text

[ "$status" -eq 0 ]
[ "$output" = "$CACHE_CONTROL" ]
}
5 changes: 5 additions & 0 deletions actions/deploy-to-s3-bucket/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ inputs:
owner=carl
default: ''

cache-control:
description: 'Sets the cache-control headers for the content being uploaded'
default: ''

runs:
using: 'composite'
steps:
Expand All @@ -58,6 +62,7 @@ runs:
env:
S3_BUCKET: ${{ inputs.s3-bucket }}
S3_BUCKET_PATH: ${{ inputs.s3-bucket-path }}
CACHE_CONTROL: ${{ inputs.cache-control }}

- name: 'Tag assets'
shell: bash
Expand Down
12 changes: 12 additions & 0 deletions actions/deploy-to-s3-bucket/upload-assets.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function setup() {

function teardown() {
rm -f "$AWS_CMD_FILE"

unset CACHE_CONTROL
}

function aws() {
Expand All @@ -35,3 +37,13 @@ function aws() {
[ -f "$AWS_CMD_FILE" ]
[[ "$(< "$AWS_CMD_FILE")" == s3\ cp\ --recursive\ my-path/\ s3://my-s3-bucket/my-s3-path/ ]]
}

@test "it should set the cache-control" {
export CACHE_CONTROL='max-age=36000'

run upload-assets my-path

[ "$status" -eq 0 ]
[ -f "$AWS_CMD_FILE" ]
[[ "$(< "$AWS_CMD_FILE")" == s3\ cp\ --recursive\ my-path/\ s3://my-s3-bucket/\ --cache-control\ max-age=36000 ]]
}
8 changes: 7 additions & 1 deletion actions/deploy-to-s3-bucket/upload-assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ function upload-assets() {
local s3_path="$S3_BUCKET"
[ -z "${S3_BUCKET_PATH:-}" ] || s3_path+="/$S3_BUCKET_PATH"

local args=()

if [ -n "${CACHE_CONTROL:-}" ]; then
args+=(--cache-control "$CACHE_CONTROL")
fi

echo "[DEBUG] Copying $path/ to s3://$s3_path/" >&2
aws s3 cp --recursive "$path/" "s3://$s3_path/"
aws s3 cp --recursive "$path/" "s3://$s3_path/" "${args[@]}"
}

if [ "${BASH_SOURCE[0]}" = "$0" ]; then
Expand Down
Loading