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

Devscript bash refactoring #2724

Merged
merged 28 commits into from
Jan 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
958fee5
devscript: line-terminations, continuations
rolandwalker Jan 31, 2014
c62cc5a
devscript: full path to pwd
rolandwalker Jan 31, 2014
572eea7
devscript: avoid pattern match syntax
rolandwalker Jan 31, 2014
96eb76f
devscript: all large scripts use die/warn idiom
rolandwalker Jan 31, 2014
73c8918
devscript: error msg consistency
rolandwalker Jan 31, 2014
bc650b8
devscript: quote/expansion nit
rolandwalker Jan 31, 2014
e7cdc72
devscript: factor list_apps_in_pkg into functions
rolandwalker Jan 31, 2014
cd4ee5d
devscript: add optional src to list_apps_in_pkg
rolandwalker Jan 31, 2014
bffec0e
devscript: refactor list_ids_in_pkg into functions
rolandwalker Jan 31, 2014
26d4f80
devscript: hoist $tmpdir
rolandwalker Jan 31, 2014
bf19f02
devscript: comments
rolandwalker Jan 31, 2014
73e1509
devscript: rename func to match script name
rolandwalker Jan 31, 2014
abe29d1
devscript: hoist configurable global variables
rolandwalker Jan 31, 2014
bf24e32
devscript: factor out not_inside_homebrew
rolandwalker Jan 31, 2014
f26e0fb
devscript: re-order params for least surprise
rolandwalker Jan 31, 2014
da16653
devscript: move feedback msgs inside functions
rolandwalker Jan 31, 2014
4737707
devscript: docs
rolandwalker Jan 31, 2014
3ce5f46
devscript: improve warn_if_off_branch
rolandwalker Jan 31, 2014
7638cf2
devscript: improve verify_git_object
rolandwalker Jan 31, 2014
1e30189
devscript: clarify $1 in main func
rolandwalker Jan 31, 2014
ac3b058
devscript: find initial_commit from git log
rolandwalker Jan 31, 2014
05170dd
devscript: re-use get_release_tag script
rolandwalker Jan 31, 2014
9c042a9
devscript: switch to array vars for file lists
rolandwalker Jan 31, 2014
278091d
devscript: factor contributor_stats into function
rolandwalker Jan 31, 2014
4bbd125
devscript: factor print_cask_stats into function
rolandwalker Jan 31, 2014
5d153a5
devscript: add commit stats to project_stats
rolandwalker Jan 31, 2014
fcf4735
devscript: add missing paths
rolandwalker Jan 31, 2014
5953587
devscript: whitespace
rolandwalker Jan 31, 2014
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
86 changes: 59 additions & 27 deletions developer/bin/develop_brew_cask
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,43 @@
# develop_brew_cask
#

set -e; # exit on any uncaught error
set +o histexpand; # don't expand history expressions
shopt -s nocasematch; # case-insensitive regular expressions
###
### settings
###

set -e # exit on any uncaught error
set +o histexpand # don't expand history expressions
shopt -s nocasematch # case-insensitive regular expressions

###
### configurable global variables
###

tap_subdir="Library/Taps/phinze-cask"

###
### functions
###

warn () {
local message="$@"
if ! [[ $message =~ "\n"$ ]]; then
message="${message}\n"
fi
printf "$message" 1>&2
}

die () {
warn "$@"
exit 1
}

cd_to_project_root () {
local script_dir="$(/usr/bin/dirname $0)"
cd "$script_dir"
local git_root="$(git rev-parse --show-toplevel)"
if [[ -z "$git_root" ]]; then
printf "Could not find git project root"
exit 1;
die "ERROR: Could not find git project root"
fi
cd "$git_root"
}
Expand All @@ -22,15 +48,22 @@ cd_to_version_dir () {
local cellar_dir="$1"
local version_dir="$2"
if [[ -z "$version_dir" ]]; then
printf "Can't get version dir under $cellar_dir/\n";
exit 1;
die "ERROR: Could not find version dir under $cellar_dir/"
fi
cd "$cellar_dir/$version_dir"
}

not_inside_homebrew () {
local tap_dir="$1"
local git_root="$2"
if [[ "$(/usr/bin/stat -L -f '%i' "$tap_dir")" -eq "$(/usr/bin/stat -L -f '%i' "$git_root")" ]]; then
die "\nERROR: Run this script in your private repo, not inside Homebrew.\n"
fi
}

create_dev_links () {
local git_root="$1"
local tap_dir="$2"
local tap_dir="$1"
local git_root="$2"
/bin/mv rubylib production_rubylib
/bin/mv Casks production_Casks
/bin/ln -s "$git_root/Casks" .
Expand All @@ -40,46 +73,44 @@ create_dev_links () {
/bin/mv Casks production_Casks
/bin/ln -s "$git_root/Casks" .
/bin/ln -s "$git_root/lib" .
printf "brew-cask is now in development mode\n"
printf "Note: it is not safe to run 'brew update' while in development mode\n"
}

_develop_brew_cask () {
###
### main
###

# configurable
local tap_subdir="Library/Taps/phinze-cask"
_develop_brew_cask () {

# initialization
cd_to_project_root;
local git_root="$(pwd)"
cd_to_project_root
local git_root="$(/bin/pwd)"
local brew_prefix="$(brew --prefix)"
local cellar_dir="$brew_prefix/Cellar/brew-cask"
local version_dir="$(/bin/ls "$cellar_dir/" | /usr/bin/sort | /usr/bin/tail -1)"
local tap_dir="$brew_prefix/$tap_subdir"

# sanity check
if [[ "$(/usr/bin/stat -L -f '%i' "$tap_dir")" -eq "$(/usr/bin/stat -L -f '%i' "$git_root")" ]]; then
printf "\nERROR: run this script in your private repo, not inside Homebrew.\n";
exit 1;
fi
not_inside_homebrew "$tap_dir" "$git_root"

# action
cd_to_version_dir "$cellar_dir" "$version_dir";
cd_to_version_dir "$cellar_dir" "$version_dir"
if [[ -e "production_rubylib" ]]; then
printf "brew-cask is already set up for development\n";
exit 1
die "brew-cask is already set up for development"
else
create_dev_links "$git_root" "$tap_dir";
printf "brew-cask is now in development mode\n"
printf "Note: it is not safe to run 'brew update' while in development mode\n"
create_dev_links "$tap_dir" "$git_root"
fi

}

# process args
if [[ $1 =~ ^-+h(elp)?$ ]]; then
printf "develop_brew_cask

Symlink private repo directories into Homebrew's Cellar, so
that the 'brew cask' command will use the current development
branch in your private repo.
that the 'brew cask' command will use code and Casks from
the current development branch in your private repo.

Saves the production Homebrew directories under new names.

Expand All @@ -92,6 +123,7 @@ mode is in effect.
exit
fi

_develop_brew_cask "$@";
# dispatch main
_develop_brew_cask "${@}"

#
65 changes: 43 additions & 22 deletions developer/bin/get_release_tag
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,36 @@
# get_release_tag
#

set -e; # exit on any uncaught error
set +o histexpand; # don't expand history expressions
shopt -s nocasematch; # case-insensitive regular expressions
###
### settings
###

opt_next='';
opt_latest='';
opt_verbose='';
set -e # exit on any uncaught error
set +o histexpand # don't expand history expressions
shopt -s nocasematch # case-insensitive regular expressions

die () {
local message="$@";
###
### global variables
###

opt_next=''
opt_latest=''
opt_verbose=''

###
### functions
###

warn () {
local message="$@"
if ! [[ $message =~ "\n"$ ]]; then
message="${message}\n"
fi
printf "$message" 1>&2
}

die () {
warn "$@"
exit 1
}

Expand All @@ -25,23 +41,23 @@ cd_to_project_root () {
cd "$script_dir"
local git_root="$(git rev-parse --show-toplevel)"
if [[ -z "$git_root" ]]; then
die "Could not find git project root"
die "ERROR: Could not find git project root"
fi
cd "$git_root"
}

verify_git_object_is_new () {
if git rev-parse --verify "$1" >/dev/null 2>&1; then
die "\nERROR: proposed new tag: '$1' already exists as a commit object\n\n"
die "\nERROR: Proposed new tag: '$1' already exists as a commit object\n\n"
fi
}

sanity_check_parsed_version () {
if [[ $# -ne 3 ]]; then
die "Error: can't parse version tag, wrong number of elements"
die "ERROR: Could not parse version tag: wrong number of elements"
fi
if ! [[ $1 =~ ^v[0-9]+$ ]]; then
die "Error: can't parse version tag, does not start with v[0-9]"
die "ERROR: Could not parse version tag: does not start with v[0-9]"
fi
}

Expand Down Expand Up @@ -71,7 +87,7 @@ generate_next_major_tag () {

generate_next_minor_tag () {
local -a version_elts
IFS='.' read -a version_elts <<< "$1";
IFS='.' read -a version_elts <<< "$1"
sanity_check_parsed_version "${version_elts[@]}"
(( version_elts[1] += 1 )) # increment minor field
version_elts[2]='0' # reset patch field
Expand Down Expand Up @@ -123,30 +139,34 @@ See RELEASING.md for more information.
fi
elif [[ $arg =~ ^-+patch$ ]]; then
if [[ "$opt_next" == 'major' ]]; then
die "Error: -patch is incompatible with -major";
die "ERROR: -patch is incompatible with -major"
fi
opt_next='patch'
elif [[ $arg =~ ^-+major$ ]]; then
if [[ "$opt_next" == 'patch' ]]; then
die "Error: -patch is incompatible with -major";
die "ERROR: -patch is incompatible with -major"
fi
opt_next='major'
elif [[ $arg =~ ^-+latest$ ]]; then
opt_latest='true'
else
die "Error: unknown argument '$arg'"
die "ERROR: Unknown argument '$arg'"
fi
if [[ -n "$opt_latest" && -n "$opt_next" ]]; then
die "Error: -latest is incompatible with -next/-patch/-major"
die "ERROR: -latest is incompatible with -next/-patch/-major"
fi
done
}

###
### main
###

_get_release_tag () {
cd_to_project_root;
cd_to_project_root
local latest_tag="$(git describe --tags --abbrev=0 2>/dev/null)"
if [[ -z "$latest_tag" ]]; then
die "Error: no recent tag found"
die "ERROR: No recent tag found"
elif [[ -z "$opt_next" ]]; then
if [[ -n "$opt_verbose" ]]; then
printf "Latest tag\t"
Expand All @@ -159,12 +179,13 @@ _get_release_tag () {
elif [[ "$opt_next" == 'patch' ]]; then
generate_next_patch_tag "$latest_tag"
else
die "Error: should not happen. Unknown argument?"
die "ERROR: Should not happen. Unknown argument?"
fi
}

process_args "$@";
process_args "${@}"

_get_release_tag;
# dispatch main
_get_release_tag

#
Loading