diff --git a/README.md b/README.md index 1cad90c..47a465d 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,8 @@ Stored as secrets or env vars, doesn't matter. But also please don't put your AW - Partial ARN - `123456789012:function:my-function` - `requirements_txt` The name/path for the `requirements.txt` file. Defaults to `requirements.txt`. - +- `exclude_files` + (Optional) A string of files or folders to exclude, delimited by whitespace. ### Example workflow ```yaml @@ -49,9 +50,10 @@ jobs: with: lambda_layer_arn: 'arn:aws:lambda:us-east-2:123456789012:layer:my-layer' lambda_function_name: 'my-function' + exclude_files: 'tests my-other-file.txt' env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_DEFAULT_REGION: 'us-east-2' -``` +``` \ No newline at end of file diff --git a/action.yml b/action.yml index f06de98..4dc76ef 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,10 @@ inputs: lambda_function_name: description: The Lambda function name. Check the AWS docs/readme for examples. required: true + exclude_files: + description: A string of files or folders to exclude, delimited by whitespace. + required: false + default: '' runs: using: 'docker' image: 'Dockerfile' @@ -19,6 +23,7 @@ runs: - ${{ inputs.requirements_txt }} - ${{ inputs.lambda_layer_arn }} - ${{ inputs.lambda_function_name }} + - ${{ inputs.exclude_files }} branding: icon: 'layers' color: 'yellow' diff --git a/entrypoint.sh b/entrypoint.sh index 0ffdfed..9a8c25b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -euo pipefail install_zip_dependencies(){ echo "Installing and zipping dependencies..." @@ -16,10 +16,21 @@ publish_dependencies_as_layer(){ rm dependencies.zip } +files_to_exclude() { + echo "exclude.lst" > exclude.lst + echo ".git/*" >> exclude.lst + read -ra ADDR <<< "$INPUT_EXCLUDE_FILES" + for i in "${ADDR[@]}"; do + echo "$i*" >> exclude.lst + done +} + publish_function_code(){ echo "Deploying the code itself..." - zip -r code.zip . -x \*.git\* + files_to_exclude + zip -r code.zip . -x@exclude.lst aws lambda update-function-code --function-name "${INPUT_LAMBDA_FUNCTION_NAME}" --zip-file fileb://code.zip + rm exclude.lst } update_function_layers(){