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
17 changes: 16 additions & 1 deletion .github/workflows/deploy-lambda-function.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ on:
description: 'If true, a lambda version will be published'
type: boolean
default: true
version-description:
description: 'The description of the version being published (if publish-version is true)'
type: string
default: ${{ github.sha }}
update-alias:
description: 'If true, the alias will be updated to the new version'
type: boolean
default: false
alias-name:
description: 'The name of the alias to update. Required if update-alias is true'
type: string
default: ''

# s3 options
upload-to-s3:
Expand Down Expand Up @@ -186,14 +198,17 @@ jobs:
# deploy
- name: 'Deploy'
id: deploy
uses: shopsmart/github-actions/actions/deploy-lambda-function@v3
uses: shopsmart/github-actions/actions/deploy-lambda-function@feature/lambda-update-alias
with:
zip-file: ${{ inputs.pattern }}
function-name: ${{ inputs.function-name }}
function-tags: |
version=${{ inputs.version }}
${{ inputs.function-tags }}
publish-version: ${{ inputs.publish-version }}
version-description: ${{ inputs.version-description || inputs.version }}
update-alias: ${{ inputs.update-alias }}
alias-name: ${{ inputs.alias-name }}
upload-to-s3: ${{ inputs.upload-to-s3 }}
s3-bucket: ${{ inputs.s3-bucket }}
s3-key: ${{ inputs.s3-key }}
Expand Down
16 changes: 15 additions & 1 deletion actions/deploy-lambda-function/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ inputs:
publish-version:
description: If true, a lambda version will be published
default: 'true'
version-description:
description: 'The description of the version being published (if publish-version is true)'
default: ${{ github.sha }}
update-alias:
description: 'If true, the alias will be updated to the new version. Also requires publish-version to be true'
default: 'false'
alias-name:
description: 'The name of the alias to update. Required if update-alias is true'
default: ''

# s3 options
upload-to-s3:
Expand Down Expand Up @@ -74,4 +83,9 @@ runs:
id: publish-version
if: inputs.publish-version == 'true'
shell: bash
run: ${{ github.action_path }}/version-lambda.sh "${{ inputs.function-name }}" "${{ inputs.tag || github.sha }}"
run: ${{ github.action_path }}/version-lambda.sh "${{ inputs.function-name }}" "${{ inputs.version-description || github.sha }}"

- name: 'Update the alias'
if: inputs.update-alias == 'true' && inputs.publish-version == 'true'
shell: bash
run: ${{ github.action_path }}/update-alias.sh "${{ inputs.function-name }}" "${{ inputs.alias-name }}" "${{ steps.publish-version.outputs.version }}"
44 changes: 44 additions & 0 deletions actions/deploy-lambda-function/update-alias.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bats

load update-alias.sh

function setup() {
export AWS_CMD_FILE="$BATS_TEST_TMPDIR/aws.cmd"
export -f aws

export GITHUB_OUTPUT="$BATS_TEST_TMPDIR/output.txt"
}

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

function aws() {
echo "$*" > "$AWS_CMD_FILE"
}

@test "it should require the function name" {
run update-alias

[ "$status" -ne 0 ]
}

@test "it should require the alias name" {
run update-alias my-function

[ "$status" -ne 0 ]
}

@test "it should require the version" {
run update-alias my-function my-alias

[ "$status" -ne 0 ]
}

@test "it should update the alias" {
run update-alias my-function my-alias 1

[ "$status" -eq 0 ]
[ -f "$AWS_CMD_FILE" ]
[ "$(< "$AWS_CMD_FILE")" = "lambda update-alias --function-name my-function --name my-alias --function-version 1 --no-cli-pager" ]
}
36 changes: 36 additions & 0 deletions actions/deploy-lambda-function/update-alias.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

function update-alias() {
set -eo pipefail

local function_name="${1:-}"
[ -n "$function_name" ] || {
echo "[ERROR] Function name not provided" >&2
return 1
}

local alias_name="${2:-}"
[ -n "$alias_name" ] || {
echo "[ERROR] Alias name not provided" >&2
return 2
}

local version="${3:-}"
[ -n "$version" ] || {
echo "[ERROR] Version not provided" >&2
return 2
}

aws lambda update-alias \
--function-name "$function_name" \
--name "$alias_name" \
--function-version "$version" \
--no-cli-pager
}

if [ "${BASH_SOURCE[0]}" = "$0" ]; then
set -u

update-alias "${@:-}"
exit $?
fi
Loading