Changeset - d9514fba012b
[Not reviewed]
0 1 0
Branko Majic (branko) - 7 years ago 2017-05-01 18:19:43
branko@majic.rs
MAR-102: Refactored the check to ensure pip-compile exit code is properly verified.
1 file changed with 10 insertions and 5 deletions:
0 comments (0 inline, 0 general)
roles/common/files/pip_check_requirements_upgrades.sh
Show inline comments
 
@@ -146,12 +146,15 @@ function error() {
 
function on_exit() {
 
    debug "Cleaning-up temporary file: $tmp_current"
 
    [[ -f $tmp_current ]] && rm "$tmp_current"
 

	
 
    debug "Cleaning-up temporary file: $tmp_new"
 
    [[ -f $tmp_new ]] && rm "$tmp_new"
 

	
 
    debug "Cleaning-up temporary file: $tmp_new_sorted"
 
    [[ -f $tmp_new_sorted ]] && rm "$tmp_new_sorted"
 
}
 
trap on_exit EXIT
 

	
 
# Define error codes.
 
SUCCESS=0
 
ERROR_ARGUMENTS=1
 
@@ -218,12 +221,13 @@ if ! which pip-compile >/dev/null 2>&1; then
 
fi
 

	
 
# Create temporary files where files where "normalised" outputs will be
 
# stored.
 
tmp_current=$(mktemp)
 
tmp_new=$(mktemp)
 
tmp_new_sorted=$(mktemp)
 

	
 
# Process each environment.
 
for environment in "$config_dir"/*; do
 
    # Empty directory.
 
    if [[ ! -e $environment ]]; then
 
	error "Configuration directory is empty: $config_dir"
 
@@ -244,24 +248,25 @@ for environment in "$config_dir"/*; do
 
	    warning "Missing .txt file for: $req_in"
 
	    continue
 
	fi
 

	
 
	# Deploy the existing requirements file and the new one.
 
	sed -e 's/[[:blank:]]*#.*//' "$req_txt" | grep -v "^$" | sort -u > "$tmp_current" 
 
	if ! pip-compile --upgrade --dry-run --no-header --no-annotate --no-index "$req_in" 2>&1 | \
 
               grep -v 'Dry-run' | sed -e 's/[[:blank:]]*#.*//' | grep -v "^$" | \
 
               sort -u > "$tmp_new" ; then
 
	if ! pip-compile --no-header --no-annotate --no-index --output-file "$tmp_new" --upgrade "$req_in" > /dev/null; then
 
	    error "Failed while running pip-compile command against (see error stack trace above): $req_in"
 
	    continue
 
	fi
 

	
 
        # Sort the new requirements file.
 
        sed -e 's/[[:blank:]]*#.*//' "$tmp_new" | grep -v "^$" | sort -u > "$tmp_new_sorted"
 

	
 
        debug "Current requirements:\n$(cat "$tmp_current")"
 
        debug "New requirements:\n$(cat "$tmp_new")"
 
        debug "New requirements:\n$(cat "$tmp_new_sorted")"
 

	
 
	# Run diff, storing the output and result.
 
	diff=$(diff -u "$tmp_current" "$tmp_new")
 
	diff=$(diff -u "$tmp_current" "$tmp_new_sorted")
 
	result="$?"
 

	
 
	# Show warning about available updates.
 
	if [[ $result == 0 ]]; then
 
	    [[ $quiet == 0 ]] && info "No upgrades available for: $req_txt"
 
	else
0 comments (0 inline, 0 general)