Created
January 9, 2020 15:20
-
-
Save jairamc/befd92028b7d18c1fbd220e95d4683ba to your computer and use it in GitHub Desktop.
Helper script to run drone build locally with some defaults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
command -v drone >/dev/null 2>&1 || { echo >&2 "Could not find drone-cli. Aborting."; exit 1; } | |
function usage() { | |
echo "NAME:" | |
echo " drone-local - Helper to run drone build locally" | |
echo | |
echo "USAGE:" | |
echo " drone-local [options]" | |
echo | |
echo "OPTIONS:" | |
echo " -r | --ref git reference used as trigger. DEFAULT: refs/heads/master" | |
echo " -e | --event git event used as trigger. DEFAULT: push" | |
echo " -s | --secrets-file secret file, define values that can be used with from_secret. DEFAULT: secrets.txt" | |
echo " -n | --env-file env file" | |
echo " -h | --help print this message" | |
} | |
ref="refs/heads/master" | |
event="push" | |
secrets="secrets.txt" | |
function run() { | |
# Automatically pick up the repo name using git remote | |
repo=$(git remote get-url origin | cut -d ":" -f 2 | cut -d "." -f 1) | |
cmd="drone exec --trusted --privileged true --repo ${repo} --ref ${ref} --event ${event} --secret-file ${secrets}" | |
if [ ! -z "$env" ]; then | |
cmd="${cmd} --env-file ${env}" | |
fi | |
echo "${cmd}" | |
eval "${cmd}" | |
} | |
while [ "$1" != "" ]; do | |
case $1 in | |
-r | --ref ) shift | |
ref=$1 | |
;; | |
-t | --event ) shift | |
event=$1 | |
;; | |
-s | --secret-file ) shift | |
secrets=$1 | |
;; | |
-e | --env-file ) shift | |
env=$1 | |
;; | |
-h | --help ) usage | |
exit | |
;; | |
* ) usage | |
exit 1 | |
esac | |
shift | |
done | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment