-
-
Save juliancheal/26434828dfb4f3b9d98c621c6764ab7f to your computer and use it in GitHub Desktop.
extract a provider
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 | |
~/src/scratch/manageiq/extract_provider_gem.sh \ | |
-n ovirt \ | |
-d "app/models/manageiq/providers/redhat spec/models/manageiq/providers/redhat spec/vcr_cassettes/manageiq/providers/redhat" \ | |
-l \ | |
-e ~/src/manageiq \ | |
-r \ | |
-g ~/src/manageiq \ | |
-p durandom \ | |
-b durandom |
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 | |
set -e | |
usage() { echo "$0 usage:" && grep " .)\ #" $0; exit 0; } | |
while getopts ":fn:d:c:e:g:b:rlp:" o; do | |
case "${o}" in | |
n) # name of the provider, e.g. ovirt REQUIRED | |
NAME=${OPTARG} | |
;; | |
d) # directories to be extracted, e.g app/models/manageiq/providers/redhat spec/models/manageiq/providers/redhat spec/vcr_cassettes/manageiq/providers/redhat | |
EXTRACT_DIRS=${OPTARG} | |
;; | |
c) # copy from dir instead e.g. -c manageiq.git | |
COPY_FROM=${OPTARG} | |
;; | |
l) # clone fomr manageiq | |
CLONE=1 | |
;; | |
f) # force, as in rm -rf | |
FORCE=1 | |
;; | |
e) # create extract branch in manageiq checkout, e.g. ~/src/manageiq | |
EXTRACT_BRANCH=${OPTARG} | |
;; | |
r) # rewrite tree in target dir | |
REWRITE=1 | |
;; | |
g) # run generator from dir, e.g. ~/src/manageiq | |
GENERATOR=${OPTARG} | |
;; | |
b) # replace URL in Gemfile, e.g. durandom | |
GEMFILE_URL=${OPTARG} | |
;; | |
p) # push to origin (github account name), eg. durandom | |
PUSH=${OPTARG} | |
;; | |
*) | |
usage | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
if [ -z "$NAME" ]; then | |
usage | |
fi | |
if [ ! -z $REWRITE ]; then | |
if [ -z "${EXTRACT_DIRS}" ]; then | |
usage | |
fi | |
fi | |
function extract_branch { | |
branch="extract_$NAME" | |
git checkout master | |
git mup | |
git branch -D $branch | |
git checkout -b $branch | |
git rm -r $EXTRACT_DIRS | |
git commit -m "extract $NAME provider" | |
} | |
function check_dir { | |
if [ -d $DIR ] ; then | |
if [ ! -z $FORCE ] ; then | |
echo "rm -rf $DIR" | |
rm -rf $DIR | |
else | |
echo "$DIR exists, rm or try -f" | |
exit 1 | |
fi | |
fi | |
} | |
function clone { | |
git clone -o upstream [email protected]:ManageIQ/manageiq.git $DIR | |
} | |
function clone_cp { | |
echo "copy manageiq.git to $DIR" | |
cp -a manageiq.git $DIR | |
} | |
function filter_branch { | |
echo "removing tags" | |
git tag -d `git tag` | |
echo "extracting $EXTRACT_DIRS" | |
export EXTRACT_DIRS | |
time git filter-branch --index-filter ' | |
git read-tree --empty | |
git reset $GIT_COMMIT -- $EXTRACT_DIRS | |
' --msg-filter ' | |
cat - | |
echo | |
echo | |
echo "(transferred from ManageIQ/manageiq@$GIT_COMMIT)" | |
' -- --all -- $EXTRACT_DIRS | |
} | |
DIR="`pwd`/manageiq-providers-$NAME" | |
set -x | |
if [ ! -z $EXTRACT_BRANCH ] ; then | |
echo "extracting branch" | |
cd $EXTRACT_BRANCH | |
extract_branch | |
cd - | |
fi | |
echo "Target dir is $DIR" | |
if [ ! -z $CLONE ] ; then | |
echo "clone" | |
check_dir | |
clone | |
fi | |
if [ ! -z $COPY_FROM ] ; then | |
echo "copy" | |
check_dir | |
clone_cp | |
fi | |
if [ ! -z $REWRITE ] ; then | |
echo "rewrite" | |
cd $DIR | |
filter_branch | |
cd - | |
fi | |
if [ ! -z $GENERATOR ] ; then | |
echo "run generator" | |
cd $GENERATOR | |
git checkout provider_generator | |
bundle exec rails g provider $NAME --path `dirname $DIR` | |
if [ ! -z $GEMFILE_URL ] ; then | |
branch="extract_$NAME" | |
git checkout $branch | |
# ruby -pi -e "gsub 'ManageIQ/manageiq-providers-$NAME', '$GEMFILE_URL/manageiq-providers-$NAME'" Gemfile | |
git commit -a -m 'point to provider gem' | |
fi | |
cd $DIR | |
git add . | |
git commit -m "rails g provider $NAME" | |
cd - | |
fi | |
if [ ! -z $PUSH ] ; then | |
cd $DIR | |
git remote remove origin || true | |
# git remote add origin [email protected]:${PUSH}/manageiq-providers-${NAME}.git | |
git remote add origin [email protected]:ManageIQ/manageiq-providers-${NAME}.git | |
git fetch origin | |
git branch master --set-upstream-to=origin/master || true | |
OVERRIDE=true git push -f origin | |
cd - | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment