Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script-run.sh to run arbitrary bash scripts #62

Merged
merged 1 commit into from
Aug 20, 2024
Merged
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
44 changes: 44 additions & 0 deletions scripts/script-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

set -euE
set -o pipefail

PARENT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

source "${PARENT}/../functions"

KAYOBE_AUTOMATION_CONTEXT_SCRIPT="$(basename $1)"

function pull_request_branch_name {
# script.sh/<uuid> -> script.sh/<script name>/<uuid>
echo "script-run.sh/$KAYOBE_AUTOMATION_CONTEXT_SCRIPT/$(uuidgen)"
}

function main {
script=$1
args=("${@:2}")
shift $#
log_info "Running custom script: $script"
log_debug "Script args: ${args[@]}"
kayobe_init
# Use eval so we can do something like: script-run.sh '$KAYOBE_CONFIG_PATH/../../tools/foo.sh'
# NOTE: KAYOBE_CONFIG_PATH gets defined by kayobe_init
local SCRIPT_PATH="$(eval echo $script)"
if ! is_absolute_path "$SCRIPT_PATH"; then
# Default to a path relative to repository root
SCRIPT_PATH="$KAYOBE_CONFIG_PATH/../../$SCRIPT_PATH"
fi
if [ ! -f "$SCRIPT_PATH" ]; then
die $LINENO "Script path does not exist: $SCRIPT_PATH"
fi
$SCRIPT_PATH "${args[@]}"
pull_request "${KAYOBE_AUTOMATION_CONTEXT_ENV_PATH}/src/kayobe-config"
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
if [ "$#" -lt 1 ]; then
die $LINENO "Error: You must provide a script to run" \
"Usage: script-run.sh <script>"
fi
main "${@:1}"
fi
Loading