File tree Expand file tree Collapse file tree
.github/actions/test-deploy-to-s3-bucket
actions/deploy-to-s3-bucket Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,10 +45,12 @@ runs:
4545 pattern : ' archive.tgz'
4646 s3-bucket : shopsmart-github-actions-tests
4747 s3-bucket-path : ${{ steps.id.outputs.id }}
48+ cache-control : max-age=3600
4849
4950 - name : ' Validate'
5051 shell : bash
5152 run : bats --tap --verbose-run ${{ github.action_path }}/deploy-to-s3-bucket.bats
5253 env :
5354 S3_BUCKET : shopsmart-github-actions-tests
5455 S3_BUCKET_PATH : ${{ steps.id.outputs.id }}
56+ CACHE_CONTROL : max-age=3600
Original file line number Diff line number Diff line change @@ -35,3 +35,15 @@ function teardown() {
3535 [ " $status " -eq 0 ]
3636 [[ " $output " =~ $S3_TAG ]]
3737}
38+
39+
40+ @test " it should have set the cache-control metadata" {
41+ run aws s3api head-object --no-cli-pager \
42+ --bucket " $S3_BUCKET " \
43+ --key " $S3_BUCKET_PATH /style.css" \
44+ --query ' CacheControl' \
45+ --output text
46+
47+ [ " $status " -eq 0 ]
48+ [ " $output " = " $CACHE_CONTROL " ]
49+ }
Original file line number Diff line number Diff line change @@ -34,6 +34,10 @@ inputs:
3434 owner=carl
3535 default : ' '
3636
37+ cache-control :
38+ description : ' Sets the cache-control headers for the content being uploaded'
39+ default : ' '
40+
3741runs :
3842 using : ' composite'
3943 steps :
5862 env :
5963 S3_BUCKET : ${{ inputs.s3-bucket }}
6064 S3_BUCKET_PATH : ${{ inputs.s3-bucket-path }}
65+ CACHE_CONTROL : ${{ inputs.cache-control }}
6166
6267 - name : ' Tag assets'
6368 shell : bash
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ function setup() {
1212
1313function teardown() {
1414 rm -f " $AWS_CMD_FILE "
15+
16+ unset CACHE_CONTROL
1517}
1618
1719function aws() {
@@ -35,3 +37,13 @@ function aws() {
3537 [ -f " $AWS_CMD_FILE " ]
3638 [[ " $( < " $AWS_CMD_FILE " ) " == s3\ cp\ --recursive\ my-path/\ s3://my-s3-bucket/my-s3-path/ ]]
3739}
40+
41+ @test " it should set the cache-control" {
42+ export CACHE_CONTROL=' max-age=36000'
43+
44+ run upload-assets my-path
45+
46+ [ " $status " -eq 0 ]
47+ [ -f " $AWS_CMD_FILE " ]
48+ [[ " $( < " $AWS_CMD_FILE " ) " == s3\ cp\ --recursive\ my-path/\ s3://my-s3-bucket/\ --cache-control\ max-age= 36000 ]]
49+ }
Original file line number Diff line number Diff line change @@ -8,8 +8,14 @@ function upload-assets() {
88 local s3_path=" $S3_BUCKET "
99 [ -z " ${S3_BUCKET_PATH:- } " ] || s3_path+=" /$S3_BUCKET_PATH "
1010
11+ local args=()
12+
13+ if [ -n " ${CACHE_CONTROL:- } " ]; then
14+ args+=(--cache-control " $CACHE_CONTROL " )
15+ fi
16+
1117 echo " [DEBUG] Copying $path / to s3://$s3_path /" >&2
12- aws s3 cp --recursive " $path /" " s3://$s3_path /"
18+ aws s3 cp --recursive " $path /" " s3://$s3_path /" " ${args[@]} "
1319}
1420
1521if [ " ${BASH_SOURCE[0]} " = " $0 " ]; then
You can’t perform that action at this time.
0 commit comments