This repository has been archived on 2021-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
drone-abra/plugin.sh

63 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
set -e
ABRA=/root/.local/bin/abra
PLUGIN_BRANCH=${PLUGIN_BRANCH:-main}
PLUGIN_HOST=${PLUGIN_HOST:-git.autonomic.zone}
PLUGIN_PORT=${PLUGIN_PORT:-2222}
checkout_main_or_master() {
git checkout main > /dev/null 2>&1 || git checkout master > /dev/null 2>&1
}
load_deploy_key() {
echo "--- start ssh key load ---"
mkdir -p "$HOME/.ssh/"
ssh-keyscan -p "$PLUGIN_PORT" "$PLUGIN_HOST" > "$HOME/.ssh/known_hosts"
# shellcheck disable=SC2046,SC2006
eval `ssh-agent`
echo "$PLUGIN_DEPLOY_KEY" | ssh-add -
echo "--- end ssh key load ---"
}
output_versions(){
echo "--- start versions"
$ABRA version
echo "--- end versions"
}
run_abra_cmd() {
echo "--- start command ---"
if [[ $PLUGIN_COMMAND == *"release"* ]]; then
echo "Detected release command, attempting to detect recipe now..."
recipe=$(echo "$PLUGIN_COMMAND" | cut -d' ' -f2)
echo "Automagically detected $recipe as desired recipe repository, cloning now..."
git clone "https://git.autonomic.zone/coop-cloud/$recipe.git" "/root/.abra/apps/$recipe"
cd "/root/.abra/apps/$recipe" && checkout_main_or_master && \
git remote rm origin && \
git remote add origin "ssh://git@git.autonomic.zone:2222/coop-cloud/$recipe.git"
git push --set-upstream origin "$PLUGIN_BRANCH"
fi
# shellcheck disable=SC2086
$ABRA --debug --no-prompt $PLUGIN_COMMAND
echo "--- end command ---"
}
run_plugin() {
echo "--- start drone-abra ---"
output_versions
load_deploy_key
run_abra_cmd
echo "--- end drone-abra ---"
}
run_plugin