Skip to content

Commit

Permalink
Expands wildcards when uploading lambda code to s3 (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-carey authored Oct 25, 2023
1 parent 8298cfd commit 4c7843e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions actions/deploy-lambda-function/upload-lambda.bats
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,13 @@ function aws() {
[ -f "$GITHUB_OUTPUT" ]
[ "$(< "$GITHUB_OUTPUT")" = "s3-key=/$S3_KEY" ]
}

@test "it should expand wildcards" {
S3_KEY=artifact.zip

run upload-lambda "$BATS_TEST_TMPDIR/*.zip" "$S3_BUCKET" "$S3_KEY"

[ "$status" -eq 0 ]
[ -f "$AWS_CMD_FILE" ]
[ "$(< "$AWS_CMD_FILE")" = "s3 cp $ZIP_FILE s3://$S3_BUCKET/$S3_KEY" ]
}
9 changes: 9 additions & 0 deletions actions/deploy-lambda-function/upload-lambda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ function upload-lambda() {
echo "[ERROR] Zip file is required" >&2
return 1
}
# resolve zip file if wildcard
[ "$zip_file" = "${zip_file#*\*}" ] || {
echo "[DEBUG] Found a wildcard file" >&2
local pre_wildcard="${zip_file%\**}"
local post_wildcard="${zip_file#*\*}"
zip_file="$(builtin echo "$pre_wildcard"*"$post_wildcard")"
echo "[DEBUG] Expanded '$pre_wildcard*$post_wildcard' to $zip_file" >&2
}
[ -f "$zip_file" ] || {
echo "[ERROR] Cannot find zip file: $zip_file" >&2
return 2
}

local s3_bucket="${2:-}"
[ -n "$s3_bucket" ] || {
echo "[ERROR] S3 bucket is required" >&2
Expand Down

0 comments on commit 4c7843e

Please sign in to comment.