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
1 change: 1 addition & 0 deletions actions/python-lambda-zip/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ The runner needs `pip`, `zip`, `unzip` and Docker, which `ubuntu-latest` has.
| `requirements-file` | `requirements.txt` | Fully resolved requirements file |
| `requirements-command` | | Command printing the requirements, e.g. `pipenv requirements`; used instead of the file when set |
| `smoke-test-glob` | `*.py` | Modules (relative to the zip root) to import; build fails if nothing matches |
| `smoke-test-env` | | Newline-separated `NAME=value` variables for the smoke test; `AWS_REGION` and `AWS_DEFAULT_REGION` are always set to `us-east-1`, like in the Lambda runtime |
| `output-dir` | `build` | Where to put the zip |
| `zip-name` | `package.zip` | File name of the zip |

Expand Down
7 changes: 7 additions & 0 deletions actions/python-lambda-zip/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ inputs:
fails if nothing matches.
required: false
default: '*.py'
smoke-test-env:
description: >
Newline-separated NAME=value environment variables for the smoke test, for code that reads
its configuration when imported. AWS_REGION and AWS_DEFAULT_REGION are always set to
us-east-1, as the Lambda runtime sets them.
required: false
output-dir:
description: 'Directory to put the zip in'
required: false
Expand Down Expand Up @@ -75,6 +81,7 @@ runs:
REQUIREMENTS_FILE: ${{ inputs.requirements-file }}
REQUIREMENTS_COMMAND: ${{ inputs.requirements-command }}
SMOKE_TEST_GLOB: ${{ inputs.smoke-test-glob }}
SMOKE_TEST_ENV: ${{ inputs.smoke-test-env }}
OUTPUT_DIR: ${{ inputs.output-dir }}
ZIP_NAME: ${{ inputs.zip-name }}
run: ${{ github.action_path }}/build.sh
7 changes: 6 additions & 1 deletion actions/python-lambda-zip/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ echo "Built $zip_path"
mkdir -p "$stage/smoke"
unzip -q "$zip_path" -d "$stage/smoke"
echo "::group::Smoke test in $image ($docker_platform)"
# The Lambda runtime always sets the region, and code often creates AWS clients at import time
smoke_env=(-e AWS_REGION=us-east-1 -e AWS_DEFAULT_REGION=us-east-1)
while IFS= read -r var; do
[[ -n "$var" ]] && smoke_env+=(-e "$var")
done <<< "${SMOKE_TEST_ENV:-}"
docker run --rm --platform "$docker_platform" --entrypoint python \
-v "$stage/smoke:/var/task:ro" -w /var/task -e GLOB="$SMOKE_TEST_GLOB" "$image" \
-v "$stage/smoke:/var/task:ro" -w /var/task -e GLOB="$SMOKE_TEST_GLOB" "${smoke_env[@]}" "$image" \
-c "import glob, importlib, os
files = glob.glob(os.environ['GLOB'], recursive=True)
mods = sorted(f[:-3].replace('/', '.') for f in files if not os.path.basename(f).startswith('_'))
Expand Down
Loading