diff --git a/README.md b/README.md index 6a17691..42208ba 100644 --- a/README.md +++ b/README.md @@ -17,20 +17,24 @@ Bash only (language agnostic) git release script for tagging and bagging a relea * Grep ## TODO - - [ ] Write success cases for releaseable-deployed script + - [ ] Write a proper README - [ ] Optionally force push of tags, otherwise ask for confirmation to send - [ ] Make uniform variable style, either all capped variables or not - [ ] Test mode should display processes it would run (--dry-run option) - [ ] Verbose debug mode (display a lot more info) - - [ ] Split up functions and specs into more logical divisions (changelog, git) rather than one large support file - [ ] Create Ruby gem branch and release as a gem. Use better OPTPARSER to use more human readable variables to pass to - der lying script - [ ] Create Node NPM branch and release as an NPM. - [ ] Create Python PIP branch and release as a PIP. - [ ] Test on variety of systems and servers - [ ] Fix issue in tests where the time can very rarely cross over a second boundary (make specs ignore seconds difference) + - [ ] Review argument naming and choose better letters + - [ ] Make test helpers for setting argument mapping (for easily changing in other wrappers) + - [ ] Make test helpers for generating the content (changing the style now will break a lot of tests) - [ ] [potentially] Make CHANGELOG tagging dynamic (search for initial square brackets), with features + bugs on top of listing - [ ] [potentially] Make CHANGELOG generation read in optional template, with wildcards to apply logic to view + - [x] Write success cases for releaseable-deployed script + - [*] Split up functions and specs into more logical divisions (changelog, git) rather than one large support file - [*] Remove *.sh filenames and rely on shebangs on each executable file. Support files keep for editors to use. - [*] Split into seperate github repo with migrated history - [*] Load Travis-CI diff --git a/bin/releaseable b/bin/releaseable index 3e0c09d..04a980a 100755 --- a/bin/releaseable +++ b/bin/releaseable @@ -63,7 +63,7 @@ usage examples: " #Supporting functions -. "${BASH_SOURCE[0]%/*}/../support/releaseable.sh" +. "${BASH_SOURCE[0]%/*}/../support/support-functions.sh" ############################################################ ##### INPUT CAPTURE ##### diff --git a/bin/releaseable-deployed b/bin/releaseable-deployed index 046a29e..28f4388 100755 --- a/bin/releaseable-deployed +++ b/bin/releaseable-deployed @@ -78,7 +78,7 @@ usage examples: " #Supporting functions -. "${BASH_SOURCE[0]%/*}/../support/releaseable.sh" +. "${BASH_SOURCE[0]%/*}/../support/support-functions.sh" ############################################################ ##### INPUT CAPTURE ##### @@ -126,15 +126,19 @@ if [ ! $SKIP_EXECUTE ]; then #Checkout existing deployed tag next_deploy_tag_name="${DEPLOYED_PREFIX}${DEPLOYED_TAG}" + if [[ $(check_tag_exists "$next_deploy_tag_name" && echo $?) = "0" ]]; then + #Delete existing + git tag -d $next_deploy_tag_name + fi; git checkout -f --no-track -B "$next_deploy_tag_name" "$DEPLOYED_TAG" - #Capture versioning prefix from deployed tag - versioning_prefix=$(get_versioning_prefix_from_tag "$DEPLOYED_TAG") + #Capture versioning prefix from new deploy tag + versioning_prefix=$(get_versioning_prefix_from_tag "$next_deploy_tag_name") #Find last deployed tag for this versioning style last_tag_name=$(get_last_tag_name $versioning_prefix) - deployed_version_number=$(get_version_number_from_tag "$DEPLOYED_TAG") + deployed_version_number=$(get_version_number_from_tag "$next_deploy_tag_name") if [[ "$START_POINT" = '' ]]; then START_POINT=$last_tag_name fi; diff --git a/support/releaseable.sh b/support/changelog-functions.sh old mode 100755 new mode 100644 similarity index 54% rename from support/releaseable.sh rename to support/changelog-functions.sh index 683dca7..dd86420 --- a/support/releaseable.sh +++ b/support/changelog-functions.sh @@ -1,211 +1,5 @@ #!/bin/bash -e -############################################################ -##### GLOBALS ##### -############################################################ - -TAG_VERSION_NUMBER_REGEX="([0-9]+)\\.([0-9]+)\\.([0-9]+)$" - -############################################################ -##### SUPPORT FUNCTIONS ##### -############################################################ - -#Releaseable only -validate_version_type() { - #Confirm version type is in the accepted types - local v="$1" - local error_output="$2" - - if [[ $v != "major" && $v != 'minor' && $v != 'patch' ]]; then - printf "incorrect versioning type: '%s'\\n" "$v" >&2 - echo "Please set to one of 'major', 'minor' or 'patch'" >&2 - echo "$error_output" >&2 - exit 1 - fi; -} - -#Releaseable-deployed only -validate_deploy_tag() { - local t="$1" - local error_output="$2" - - if [[ "$t" = '' ]]; then - echo "Required parameter: Please enter the deploy tag released." - echo "$error_output" - exit 1; - elif [[ "$(git tag -l $t )" = '' ]]; then - echo "Error: Unable to find tag '${t}'. Please check and try again." - exit 1; - fi; -} - -check_tag_exists() { - local tag_find=$(git tag -l "$1") - if [[ "$tag_find" = '' ]]; then - return 1; - else - return 0; - fi; -} - -ensure_git_directory() { - if [[ ! -d '.git' ]]; then - echo "Error - Not a git repository please run from the base of your git repo." >&2 - exit 1 - fi; -} - -ensure_git_is_clean() { - local result=$(git status --porcelain) - - if [[ "$result" != '' ]]; then - result=$(git status) - echo "Error - Current branch is in a dirty state, please commit your changes first." - echo "$result" - exit 1 - fi; -} - -versioning_prefix() { - if [[ $2 ]]; then - echo "${1}/${2}" - else - echo "${1}" - fi; -} - -############################################################ -##### TAG FUNCTIONS ##### -############################################################ - -get_release_tags() { - local filter="" - local tag_names="" - - if [[ $1 ]]; then - local tag_pattern=$1 - filter="${tag_pattern}*" - fi; - tag_names=$(git tag -l $filter) - - # tags// - echo "$tag_names" -} - -get_last_tag_name() { - local versioning_prefix=$1 - - tags=$(get_release_tags $versioning_prefix) - echo "$tags" | tail -1 -} - -get_versioning_prefix_from_tag() { - local tag_name="$1" - if [[ $tag_name =~ $TAG_VERSION_NUMBER_REGEX ]]; then - local version_number=$BASH_REMATCH - local version_prefix="${tag_name%%$version_number}" - else - echo "Error : Unable to determine version prefix from '${tag_name}'" - exit 1; - fi; - echo "${version_prefix}" -} - -get_version_number_from_tag() { - local tag_name="$1" - if [[ $tag_name =~ $TAG_VERSION_NUMBER_REGEX ]]; then - local full_version=$BASH_REMATCH - else - echo "Error : Unable to determine version number from '${tag_name}'" - exit 1; - fi; - #full stop delimited version number - echo "$full_version" -} - -get_next_version_number_from_tag() { - local versioning_type=$1 - local tag_name=$2 - - if [[ "$versioning_type" = "" ]]; then - echo "Error : Versioning type required. eg. major" - exit 1; - fi; - - if [[ $tag_name = '' ]]; then - #No original tag name for version prefix - start increment - local tag_name="0.0.0" - fi; - - if [[ $tag_name =~ $TAG_VERSION_NUMBER_REGEX ]]; then - local full_version=$BASH_REMATCH - local major_version="${BASH_REMATCH[1]}" - local minor_version="${BASH_REMATCH[2]}" - local patch_version="${BASH_REMATCH[3]}" - else - echo "Error : Unable to determine version number from '${tag_name}'" - exit 1; - fi; - - #Increment version - case "$versioning_type" in - 'major' ) - major_version=$(( $major_version + 1 ));; - 'minor' ) - minor_version=$(( $minor_version + 1 ));; - 'patch' ) - patch_version=$(( $patch_version + 1 ));; - esac - - echo "${major_version}.${minor_version}.${patch_version}" -} - -get_sha_for_tag_name() { - local result=$(git show-ref --tags --hash $1) - echo "$result" -} - -get_sha_for_first_commit() { - local filter=$1 - local result=$(git log --reverse --format="%H" $filter | head -1) - echo "$result" -} - -get_commit_message_for_first_commit() { - local filter=$1 - local result=$(git log --reverse --format="%s" $filter | head -1) - echo "$result" -} - -get_commit_message_for_latest_commit() { - local filter=$1 - local result=$(git log -n1 --format="%s" $filter) - echo "$result" -} - -get_commits_between_points() { - local starting_point="$1" #optional - local end_point="$2" #optional - local log_filter="$3" #optional - - local git_command="git log"; - local log_options="--no-notes --format=%H" - local git_range="" - - if [[ "$log_filter" != '' ]]; then - log_options="$log_options --grep="'"'"$log_filter"'"'"" - fi; - if [[ "$starting_point" != '' && "$end_point" != '' ]]; then - git_range="${starting_point}^1..${end_point}"; - elif [[ "$end_point" != '' ]]; then - git_range="${end_point}" - elif [[ "$starting_point" != '' ]]; then - git_range="${starting_point}^1..HEAD" - fi; - - eval $git_command $log_options $git_range -} - ############################################################ ##### CHANGELOG FUNCTIONS ##### ############################################################ @@ -311,6 +105,44 @@ ${bug_tag_lines}" echo "$general_release_lines" } +#generate_changelog_content "$last_tag_name" "$next_tag_name" ":all/:pulls_only" +generate_changelog_content() { + local release_name="$1" + local commit_filter="$2" #all_commits or pulls_only + local starting_point="$3" #optional + local end_point="$4" #optional + local changelog_format="--format=%s" #default -> display title + + if [[ "$release_name" = "" ]]; then + echo "Error : Release name required for changelog generation." + exit 1; + fi; + + case "$commit_filter" in + ':all_commits' | 'all_commits' ) + #No filter + commit_filter='';; + ':pulls_only' | 'pulls_only' ) + #Filter by merged pull requests only + commit_filter=$'^Merge pull request #.* from .*'; + changelog_format="--format=%b";; #use body of pull requests + * ) + echo "Error : Commit filter required. Please specify :all or :pulls_only." + exit 1;; + esac + + local commits=$(get_commits_between_points "$starting_point" "$end_point" "$commit_filter") + local commit_output=$(get_changelog_text_for_commits "$changelog_format" $commits) + local release_date=$(get_current_release_date) + + echo "$(changelog_divider) +|| Release: ${release_name} +|| Released on ${release_date} +$(changelog_divider) +${commit_output} +$(changelog_divider)" +} + #generate_version_file "$version_number" "$optional_file_name" generate_version_file(){ local version_number="$1" @@ -366,41 +198,3 @@ $existing_content" > $changelog_file; exit 1;; esac } - -#generate_changelog_content "$last_tag_name" "$next_tag_name" ":all/:pulls_only" -generate_changelog_content() { - local release_name="$1" - local commit_filter="$2" #all_commits or pulls_only - local starting_point="$3" #optional - local end_point="$4" #optional - local changelog_format="--format=%s" #default -> display title - - if [[ "$release_name" = "" ]]; then - echo "Error : Release name required for changelog generation." - exit 1; - fi; - - case "$commit_filter" in - ':all_commits' | 'all_commits' ) - #No filter - commit_filter='';; - ':pulls_only' | 'pulls_only' ) - #Filter by merged pull requests only - commit_filter=$'^Merge pull request #.* from .*'; - changelog_format="--format=%b";; #use body of pull requests - * ) - echo "Error : Commit filter required. Please specify :all or :pulls_only." - exit 1;; - esac - - local commits=$(get_commits_between_points "$starting_point" "$end_point" "$commit_filter") - local commit_output=$(get_changelog_text_for_commits "$changelog_format" $commits) - local release_date=$(get_current_release_date) - - echo "$(changelog_divider) -|| Release: ${release_name} -|| Released on ${release_date} -$(changelog_divider) -${commit_output} -$(changelog_divider)" -} diff --git a/support/git-functions.sh b/support/git-functions.sh new file mode 100644 index 0000000..30b182c --- /dev/null +++ b/support/git-functions.sh @@ -0,0 +1,78 @@ +#!/bin/bash -e + +############################################################ +##### GIT FUNCTIONS ##### +############################################################ + +check_tag_exists() { + local tag_find=$(git tag -l "$1") + if [[ "$tag_find" = '' ]]; then + return 1; + else + return 0; + fi; +} + +ensure_git_directory() { + if [[ ! -d '.git' ]]; then + echo "Error - Not a git repository please run from the base of your git repo." >&2 + exit 1 + fi; +} + +ensure_git_is_clean() { + local result=$(git status --porcelain) + + if [[ "$result" != '' ]]; then + result=$(git status) + echo "Error - Current branch is in a dirty state, please commit your changes first." + echo "$result" + exit 1 + fi; +} + +get_sha_for_tag_name() { + local result=$(git show-ref --tags --hash $1) + echo "$result" +} + +get_sha_for_first_commit() { + local filter=$1 + local result=$(git log --reverse --format="%H" $filter | head -1) + echo "$result" +} + +get_commit_message_for_first_commit() { + local filter=$1 + local result=$(git log --reverse --format="%s" $filter | head -1) + echo "$result" +} + +get_commit_message_for_latest_commit() { + local filter=$1 + local result=$(git log -n1 --format="%s" $filter) + echo "$result" +} + +get_commits_between_points() { + local starting_point="$1" #optional + local end_point="$2" #optional + local log_filter="$3" #optional + + local git_command="git log"; + local log_options="--no-notes --format=%H" + local git_range="" + + if [[ "$log_filter" != '' ]]; then + log_options="$log_options --grep="'"'"$log_filter"'"'"" + fi; + if [[ "$starting_point" != '' && "$end_point" != '' ]]; then + git_range="${starting_point}^1..${end_point}"; + elif [[ "$end_point" != '' ]]; then + git_range="${end_point}" + elif [[ "$starting_point" != '' ]]; then + git_range="${starting_point}^1..HEAD" + fi; + + eval $git_command $log_options $git_range +} diff --git a/support/releaseable-functions.sh b/support/releaseable-functions.sh new file mode 100755 index 0000000..3d2bbd6 --- /dev/null +++ b/support/releaseable-functions.sh @@ -0,0 +1,133 @@ +#!/bin/bash -e + +############################################################ +##### GLOBALS ##### +############################################################ + +TAG_VERSION_NUMBER_REGEX="([0-9]+)\\.([0-9]+)\\.([0-9]+)$" + +############################################################ +##### SUPPORT FUNCTIONS ##### +############################################################ + +validate_version_type() { + #Confirm version type is in the accepted types + local v="$1" + local error_output="$2" + + if [[ $v != "major" && $v != 'minor' && $v != 'patch' ]]; then + printf "incorrect versioning type: '%s'\\n" "$v" >&2 + echo "Please set to one of 'major', 'minor' or 'patch'" >&2 + echo "$error_output" >&2 + exit 1 + fi; +} + +#Releaseable-deployed only +validate_deploy_tag() { + local t="$1" + local error_output="$2" + + if [[ "$t" = '' ]]; then + echo "Required parameter: Please enter the deploy tag released." + echo "$error_output" + exit 1; + elif [[ "$(git tag -l $t )" = '' ]]; then + echo "Error: Unable to find tag '${t}'. Please check and try again." + exit 1; + fi; +} + +versioning_prefix() { + if [[ $2 ]]; then + echo "${1}/${2}" + else + echo "${1}" + fi; +} + +############################################################ +##### TAG FUNCTIONS ##### +############################################################ + +get_release_tags() { + local filter="" + local tag_names="" + + if [[ $1 ]]; then + local tag_pattern=$1 + filter="${tag_pattern}*" + fi; + tag_names=$(git tag -l $filter) + + # tags// + echo "$tag_names" +} + +get_last_tag_name() { + local versioning_prefix=$1 + + tags=$(get_release_tags $versioning_prefix) + echo "$tags" | tail -1 +} + +get_versioning_prefix_from_tag() { + local tag_name="$1" + if [[ $tag_name =~ $TAG_VERSION_NUMBER_REGEX ]]; then + local version_number=$BASH_REMATCH + local version_prefix="${tag_name%%$version_number}" + else + echo "Error : Unable to determine version prefix from '${tag_name}'" + exit 1; + fi; + echo "${version_prefix}" +} + +get_version_number_from_tag() { + local tag_name="$1" + if [[ $tag_name =~ $TAG_VERSION_NUMBER_REGEX ]]; then + local full_version=$BASH_REMATCH + else + echo "Error : Unable to determine version number from '${tag_name}'" + exit 1; + fi; + #full stop delimited version number + echo "$full_version" +} + +get_next_version_number_from_tag() { + local versioning_type=$1 + local tag_name=$2 + + if [[ "$versioning_type" = "" ]]; then + echo "Error : Versioning type required. eg. major" + exit 1; + fi; + + if [[ $tag_name = '' ]]; then + #No original tag name for version prefix - start increment + local tag_name="0.0.0" + fi; + + if [[ $tag_name =~ $TAG_VERSION_NUMBER_REGEX ]]; then + local full_version=$BASH_REMATCH + local major_version="${BASH_REMATCH[1]}" + local minor_version="${BASH_REMATCH[2]}" + local patch_version="${BASH_REMATCH[3]}" + else + echo "Error : Unable to determine version number from '${tag_name}'" + exit 1; + fi; + + #Increment version + case "$versioning_type" in + 'major' ) + major_version=$(( $major_version + 1 ));; + 'minor' ) + minor_version=$(( $minor_version + 1 ));; + 'patch' ) + patch_version=$(( $patch_version + 1 ));; + esac + + echo "${major_version}.${minor_version}.${patch_version}" +} diff --git a/support/support-functions.sh b/support/support-functions.sh new file mode 100644 index 0000000..31d4537 --- /dev/null +++ b/support/support-functions.sh @@ -0,0 +1,9 @@ +#!/bin/bash -e + +#Manifest to ensure correct loading of all files in order. +# Use to handle sourcing all required files. +# Loading example: . "${BASH_SOURCE[0]%/*}/../support/support-functions.sh" + +. "${BASH_SOURCE[0]%/*}/git-functions.sh" +. "${BASH_SOURCE[0]%/*}/releaseable-functions.sh" +. "${BASH_SOURCE[0]%/*}/changelog-functions.sh" diff --git a/test/bin/run_all b/test/bin/run_all index 4ad1a98..65544e3 100755 --- a/test/bin/run_all +++ b/test/bin/run_all @@ -2,12 +2,6 @@ DIR=$(dirname $0) - - -echo "Running Integration tests:" -time $DIR/../support/roundup $DIR/../integration/* - -echo "Running Unit tests:" -time $DIR/../support/roundup $DIR/../unit/* +time $DIR/../support/roundup $DIR/../{integration,unit}/* diff --git a/test/integration/releaseable-deployed-test.sh b/test/integration/releaseable-deployed-test.sh index d6b2b2c..9ef2e74 100644 --- a/test/integration/releaseable-deployed-test.sh +++ b/test/integration/releaseable-deployed-test.sh @@ -1,7 +1,7 @@ #!/bin/bash -e . ./test/test_helper.sh -. ./support/releaseable.sh +. ./support/support-functions.sh rup() { ./bin/releaseable-deployed $@; } sandbox_rup() { /bin/bash ../bin/releaseable-deployed $@; } @@ -89,6 +89,265 @@ it_will_error_if_deploy_tag_cannot_be_found(){ # ### Success cases +it_will_genereate_a_new_deploy_tag_for_each_release() { + local tags=( "release/production/v3.1.9" ) + generate_sandbox_tags tags[@] + + should_succeed $(check_tag_exists "release/production/v3.1.9") + should_fail $(check_tag_exists "deployed/release/production/v3.1.9") + + output=$(sandbox_rup -d "release/production/v3.1.9") + + should_succeed $(check_tag_exists "deployed/release/production/v3.1.9") +} + +it_will_genereate_a_new_deploy_tag_for_each_release_overwriting_any_existing() { + local tags=( "release/production/v3.1.9" ) + generate_sandbox_tags tags[@] + + should_succeed $(check_tag_exists "release/production/v3.1.9") + should_fail $(check_tag_exists "deployed/release/production/v3.1.9") + + output=$(sandbox_rup -d "release/production/v3.1.9") + should_succeed $(check_tag_exists "deployed/release/production/v3.1.9") + file_should_exist 'CHANGELOG' + file_should_not_exist 'DifferentFile' + + output=$(sandbox_rup -d "release/production/v3.1.9" -C 'DifferentFile') + should_succeed $(check_tag_exists "deployed/release/production/v3.1.9") + file_should_not_exist 'CHANGELOG' + file_should_exist 'DifferentFile' +} + +it_will_genereate_a_new_deploy_tag_for_next_release_with_defaults() { + #From last deployed tag + #With anything else in HEAD + #Overwrite any existing tag + + local tags=( + 'release/v1.0.5' + 'deployed/release/v1.0.5' + 'release/v1.0.6' + ) + local commit_messages=( + '[Any Old] Message for 1.0.5' + 'The last deployed release' + 'latest commit message to 1.0.6' + ) + + generate_sandbox_tags tags[@] commit_messages[@] + + output=$(sandbox_rup -d "release/v1.0.6") + + test "$(cat CHANGELOG)" = "$(changelog_divider) +|| Release: 1.0.6 +|| Released on $(get_current_release_date) +$(changelog_divider) +latest commit message to 1.0.6 +The last deployed release +$(changelog_divider) +$(changelog_footer)" + + output=$(sandbox_rup -d "release/v1.0.6" -C 'DiffChangeLog') + file_should_not_exist 'CHANGELOG' + + test "$(cat DiffChangeLog)" = "$(changelog_divider) +|| Release: 1.0.6 +|| Released on $(get_current_release_date) +$(changelog_divider) +latest commit message to 1.0.6 +The last deployed release +$(changelog_divider) +$(changelog_footer)" +} + +it_will_generate_a_deploy_changelog_for_a_set_starting_point() { + local tags=( + 'release/v1.0.4' + 'release/v1.0.5' + 'release/v1.0.6' + ) + local commit_messages=( + 'commit message for 1.0.4' + '[Any Old] Message for 1.0.5' + 'latest commit message to 1.0.6' + ) + + generate_sandbox_tags tags[@] commit_messages[@] + + output=$(sandbox_rup -d "release/v1.0.6") + + test "$(cat CHANGELOG)" = "$(changelog_divider) +|| Release: 1.0.6 +|| Released on $(get_current_release_date) +$(changelog_divider) +latest commit message to 1.0.6 +[Any Old] Message for 1.0.5 +commit message for 1.0.4 +Initial Commit +$(changelog_divider) +$(changelog_footer)" + + output=$(sandbox_rup -d "release/v1.0.6" -s "release/v1.0.5") + + test "$(cat CHANGELOG)" = "$(changelog_divider) +|| Release: 1.0.6 +|| Released on $(get_current_release_date) +$(changelog_divider) +latest commit message to 1.0.6 +[Any Old] Message for 1.0.5 +$(changelog_divider) +$(changelog_footer)" +} + +it_will_generate_a_deploy_changelog_for_a_set_range_with_start_and_end() { + local tags=( + 'release/v1.0.4' + 'release/v1.0.5' + 'release/v1.0.6' + ) + local commit_messages=( + 'commit message for 1.0.4' + '[Any Old] Message for 1.0.5' + 'latest commit message to 1.0.6' + ) + + generate_sandbox_tags tags[@] commit_messages[@] + + output=$(sandbox_rup -d "release/v1.0.6" -s "release/v1.0.4" -f "release/v1.0.5") + test "$(cat CHANGELOG)" = "$(changelog_divider) +|| Release: 1.0.6 +|| Released on $(get_current_release_date) +$(changelog_divider) +[Any Old] Message for 1.0.5 +commit message for 1.0.4 +$(changelog_divider) +$(changelog_footer)" +} + +it_will_generate_a_deploy_changelog_with_optional_names() { + local tags=( + 'release/v1.0.5' + 'release/v1.0.6' + ) + local commit_messages=( + '[Any Old] Message for 1.0.5' + 'latest commit message to 1.0.6' + ) + + generate_sandbox_tags tags[@] commit_messages[@] + + file_should_not_exist "CHANGELOG" + + output=$(sandbox_rup -d "release/v1.0.6") + + file_should_exist "CHANGELOG" + + output=$(sandbox_rup -d "release/v1.0.6" -C 'NewChangelog') + file_should_not_exist 'CHANGELOG' + file_should_exist "NewChangelog" +} + +it_will_generate_a_deploy_changelog_file_scoped_to_pull_requests() { + local tags=( + 'tag_with_pulls/1' + 'tag_with_pulls/2' + 'tag_without_pulls/1' + 'tag_with_pulls/3' + 'tag_with_pulls/4' + 'releases/v0.0.1' + ) + local commit_messages=( + "Merge pull request #705 from Ferocia/bug/limit-payment-description-length + +[BUG] Pay anyone from the accounts screen" + "Merge pull request #722 from Ferocia/feature/running-balance-field (Anthony Langhorne, 18 hours ago) + +[Features] This is a pull request merging a feature across multiple +lines and continuing" + " A commit,that isn't a pull request" + "Merge pull request #714 from Ferocia/fix-customer-login + +Fixing the customer login but no tag displayed." + "Merge pull request #685 from Ferocia/bug/modal-new-payee + +[Security] Commit fixing the modal with security flaw" + ) + generate_sandbox_tags tags[@] commit_messages[@] + + output=$(sandbox_rup -d "releases/v0.0.1" -P) + + test "$(cat CHANGELOG)" = "$(changelog_divider) +|| Release: 0.0.1 +|| Released on $(get_current_release_date) +$(changelog_divider) +Features: + This is a pull request merging a feature across multiple +lines and continuing + +Security: + Commit fixing the modal with security flaw + +Bugs: + Pay anyone from the accounts screen + +Fixing the customer login but no tag displayed. +$(changelog_divider) +$(changelog_footer)" +} + +it_will_append_to_a_deploy_changelog_optionally(){ + local tags=( + 'release/v1.0.4' + 'release/v1.0.5' + 'release/v1.0.6' + ) + local commit_messages=( + 'commit message for 1.0.4' + '[Any Old] Message for 1.0.5' + 'latest commit message to 1.0.6' + ) + + generate_sandbox_tags tags[@] commit_messages[@] + + output=$(sandbox_rup -d "release/v1.0.4") + + test "$(cat CHANGELOG)" = "$(changelog_divider) +|| Release: 1.0.4 +|| Released on $(get_current_release_date) +$(changelog_divider) +commit message for 1.0.4 +Initial Commit +$(changelog_divider) +$(changelog_footer)" + + #Add current changelog to tag + git checkout release/v1.0.5 + git merge deployed/release/v1.0.4 + git tag -f release/v1.0.5 + git checkout master + + output=$(sandbox_rup -d "release/v1.0.5" -A) + +test "$(cat CHANGELOG)" = "$(changelog_divider) +|| Release: 1.0.5 +|| Released on $(get_current_release_date) +$(changelog_divider) +Merge tag 'deployed/release/v1.0.4' into HEAD +[Any Old] Message for 1.0.5 +Release deployed : release/v1.0.4 +$(changelog_divider) +$(changelog_divider) +|| Release: 1.0.4 +|| Released on $(get_current_release_date) +$(changelog_divider) +commit message for 1.0.4 +Initial Commit +$(changelog_divider) +$(changelog_footer)" +} +#TODO +# it_will_optionally_force_push_of_tag() diff --git a/test/integration/releaseable-test.sh b/test/integration/releaseable-test.sh index 6198190..63dd627 100644 --- a/test/integration/releaseable-test.sh +++ b/test/integration/releaseable-test.sh @@ -1,7 +1,7 @@ #!/bin/bash -e . ./test/test_helper.sh -. ./support/releaseable.sh +. ./support/support-functions.sh rup() { ./bin/releaseable $@; } sandbox_rup() { /bin/bash ../bin/releaseable $@; } diff --git a/test/unit/changelog-functions-test.sh b/test/unit/changelog-functions-test.sh new file mode 100644 index 0000000..92aeb05 --- /dev/null +++ b/test/unit/changelog-functions-test.sh @@ -0,0 +1,443 @@ +#!/bin/bash -e + +. ./test/test_helper.sh +. ./support/git-functions.sh +. ./support/changelog-functions.sh + +describe "releaseable - unit - changelog" + +after() { + if [[ $MAINTAIN_SANDBOX != true ]]; then + remove_sandbox + fi; +} + + +#get_changelog_text_for_commits + +it_uses_get_changelog_text_for_commits_to_return_titles_by_default() { + local tags=( + 'random_tag_1' + 'release/v1.0.5' + 'random_tag_2' + 'release/v1.0.6' + ) + + local commit_message_1="Release 1.0.6" + local commit_message_2="Random Release 2" + local commit_message_3="Older Release 1.0.5" + + local commit_messages=( + "Random Release numero uno" + "$commit_message_3" + "$commit_message_2" + "$commit_message_1" + ) + generate_sandbox_tags tags[@] commit_messages[@] + + local commit_shas=$(get_commits_between_points "release/v1.0.5" "release/v1.0.6") + + output=$(get_changelog_text_for_commits "$commit_shas") + + test "$output" = "${commit_message_1} +${commit_message_2} +${commit_message_3}" +} + +it_uses_get_changelog_text_for_commits_to_return_titles_with_a_custom_format() { + local tags=( + 'random_tag_1' + 'release/v1.0.5' + 'random_tag_2' + 'release/v1.0.6' + ) + + local commit_message_1="Release 1.0.6" + local commit_message_2="Random Release 2" + local commit_message_3="Older Release 1.0.5" + + local commit_messages=( + "Random Release numero uno" + "$commit_message_3" + "$commit_message_2" + "$commit_message_1" + ) + generate_sandbox_tags tags[@] commit_messages[@] + + local commit_shas=$(get_commits_between_points "release/v1.0.5" "release/v1.0.6") + local sha_array=($commit_shas) + + output=$(get_changelog_text_for_commits "--format=%H--%s" "$commit_shas") + + test "$output" = "${sha_array[0]}--${commit_message_1} +${sha_array[1]}--${commit_message_2} +${sha_array[2]}--${commit_message_3}" +} + +it_uses_get_changelog_text_for_commits_to_return_titles_grouped_by_tags() { + local tags=( + "releases/v0.0.3" + "releases/v0.0.4" + "releases/v0.1.4" + "releases/v1.1.4" + "releases/v1.1.5" + "releases/v1.1.6" + ) + local commit_messages=( + "Start of the project" + "[bugs]Argh, I fixed a bug here" + "[feature] OMG. I had time to write something of use" + "[features]Its so exciting writing useful things!!" + "[bug] What comes up, must come down" + "Some random tweak fix" + ) + generate_sandbox_tags tags[@] commit_messages[@] + local commit_shas=$(get_commits_between_points "${tags[0]}" "${tags[5]}") + + output=$(get_changelog_text_for_commits "$commit_shas") + + local sha_array=($commit_shas) + test "$output" = "Features: + Its so exciting writing useful things!! + OMG. I had time to write something of use + +Bugs: + What comes up, must come down + Argh, I fixed a bug here + +Some random tweak fix +Start of the project" +} + +it_uses_get_changelog_text_for_commits_to_return_titles_grouped_by_tags_case_insensitive() { + local tags=( + "releases/v0.0.3" + "releases/v1.1.5" + "releases/v1.1.6" + ) + local commit_messages=( + "[Bug] Start of the project" + "[BUGS] Argh, I fixed a bug here" + "[fEaTuRes] OMG. I had time to write something of use" + ) + generate_sandbox_tags tags[@] commit_messages[@] + local commit_shas=$(get_commits_between_points "${tags[0]}" "${tags[2]}") + + output=$(get_changelog_text_for_commits "$commit_shas") + + local sha_array=($commit_shas) + test "$output" = "Features: + OMG. I had time to write something of use + +Bugs: + Argh, I fixed a bug here + Start of the project" +} + +it_uses_get_changelog_text_for_commits_to_return_titles_grouped_by_tags_with_multiple_brackets() { + local tags=( + "releases/v0.0.3" + "releases/v1.1.6" + ) + local commit_messages=( + "[BUGS] [QC Some Reference][More Custom References] Fixed the tagged bugs" + "[fEaTuRes][Additonal Tag one] Another referenced feature" + ) + generate_sandbox_tags tags[@] commit_messages[@] + local commit_shas=$(get_commits_between_points "${tags[0]}" "${tags[1]}") + + output=$(get_changelog_text_for_commits "$commit_shas") + + test "$output" = "Features: + [Additonal Tag one] Another referenced feature + +Bugs: + [QC Some Reference][More Custom References] Fixed the tagged bugs" +} + +#generate_changelog_content + +it_uses_generate_changelog_content_to_exit_with_errors_without_release_name() { + generate_git_repo + + should_fail $(generate_changelog_content) + should_fail $(generate_changelog_content '') +} + +it_uses_generate_changelog_content_to_exit_with_errors_with_invalid_commit_filter() { + generate_git_repo + + should_fail $(generate_changelog_content 'AnyOldReleaseName') + should_fail $(generate_changelog_content 'AnyOldReleaseName' '') + should_fail $(generate_changelog_content 'AnyOldReleaseName' ':unknown') + should_fail $(generate_changelog_content 'AnyOldReleaseName' ':anything') + + should_succeed $(generate_changelog_content 'AnyOldReleaseName' ':all_commits') + should_succeed $(generate_changelog_content 'AnyOldReleaseName' ':pulls_only') +} + +it_uses_generate_changelog_content_to_succeed_without_a_startpoint() { + generate_git_repo + + should_succeed $(generate_changelog_content 'v0.0.5' ':all_commits' '' 'releases/end/v02.34') +} + +it_uses_generate_changelog_content_to_succeed_without_an_endpoint() { + generate_git_repo + + should_succeed $(generate_changelog_content 'v0.0.5' ':all_commits' 'releases/v1.0.45') +} + +it_uses_generate_changelog_content_to_generate_with_all_commit_messages(){ + local tags=( + 'random_tag_1' + 'release/v1.0.5' + 'random_tag_2' + 'release/v1.0.6' + ) + local commit_messages=( + 'Message For Random Tag 1' + '[Any Old] Message for 1.0.5' + 'Lots of changes in this commit for random tag 2' + 'latest release to 1.0.6' + ) + + generate_sandbox_tags tags[@] commit_messages[@] + + local custom_release_name="v1.0.7" + local output=$(generate_changelog_content "$custom_release_name" ':all_commits') + + test "$output" = "$(changelog_divider) +|| Release: ${custom_release_name} +|| Released on $(get_current_release_date) +$(changelog_divider) +${commit_messages[3]} +${commit_messages[2]} +${commit_messages[1]} +${commit_messages[0]} +$(get_commit_message_for_first_commit) +$(changelog_divider)" +} + +it_uses_generate_changelog_content_to_generate_with_commit_messages_for_a_range(){ + local tags=( + 'random_tag_1' + 'release/v1.0.5' + 'random_tag_2' + 'release/v1.0.6' + ) + local commit_messages=( + 'Message For Random Tag 1' + '[Any Old] Message for 1.0.5' + 'Lots of changes in this commit for random tag 2' + 'latest release to 1.0.6' + ) + + generate_sandbox_tags tags[@] commit_messages[@] + + local custom_release_name="v1.0.7" + local output=$(generate_changelog_content "$custom_release_name" ':all_commits' 'release/v1.0.5' 'random_tag_2') + + test "$output" = "$(changelog_divider) +|| Release: ${custom_release_name} +|| Released on $(get_current_release_date) +$(changelog_divider) +${commit_messages[2]} +${commit_messages[1]} +$(changelog_divider)" +} + +it_uses_generate_changelog_content_to_generate_scoped_to_only_pull_requests(){ + local tags=( + 'tag_with_pulls_1' + 'tag_witout_pull' + 'tag_with_pulls_2' + 'another_tag_without' + 'tag_with_pulls_3' + 'tag_with_pulls_4' + ) + local commit_messages=( + "Merge pull request #705 from Ferocia/bug/limit-payment-description-length + +[BUG] Pay anyone from the accounts screen" + " This commit is not a pull request and should be ignored" + "Merge pull request #722 from Ferocia/feature/running-balance-field (Anthony Langhorne, 18 hours ago) + +[Features] This is a pull request merging a feature across multiple +lines and continuing" + " Yet another commit,that isn't a pull request" + "Merge pull request #714 from Ferocia/fix-customer-login + +Fixing the customer login but no tag displayed." + "Merge pull request #685 from Ferocia/bug/modal-new-payee + +[Security] Commit fixing the modal with security flaw" + ) + + generate_sandbox_tags tags[@] commit_messages[@] + + local custom_release_name="v2.0.5" + local output=$(generate_changelog_content "$custom_release_name" ':pulls_only') + + test "$output" = "$(changelog_divider) +|| Release: ${custom_release_name} +|| Released on $(get_current_release_date) +$(changelog_divider) +Features: + This is a pull request merging a feature across multiple +lines and continuing + +Security: + Commit fixing the modal with security flaw + +Bugs: + Pay anyone from the accounts screen + +Fixing the customer login but no tag displayed. +$(changelog_divider)" +} + +#generate_version_file + +it_uses_generate_version_file_to_fail_with_no_version_number_passed() { + should_fail $(generate_version_file) +} + +it_uses_generate_version_file_to_create_a_version_file() { + enter_sandbox + + file_should_not_exist "VERSION" + + output=$(generate_version_file 'v12.03.23') + + file_should_exist "VERSION" + + local contents=`cat VERSION` + test "$contents" = "v12.03.23" +} + +it_uses_generate_version_file_to_create_a_custom_version_file() { + enter_sandbox + + file_should_not_exist "CUSTOM_VERSION" + + output=$(generate_version_file 'v12.03.23' 'CUSTOM_VERSION') + + file_should_exist "CUSTOM_VERSION" + + test "`cat CUSTOM_VERSION`" = "v12.03.23" +} + +it_uses_generate_version_file_to_replace_any_existing_version_file() { + enter_sandbox + + file_should_not_exist "VERSION" + + output=$(generate_version_file 'v12.03.23') + + file_should_exist "VERSION" + + test "`cat VERSION`" = "v12.03.23" + + output=$(generate_version_file 'v14.05.25') + + test "`cat VERSION`" = "v14.05.25" +} + +#generate_changelog_file + +it_uses_generate_changelog_file_to_fail_with_content_passed_or_strategy() { + enter_sandbox + + should_fail $(generate_changelog_file) + should_fail $(generate_changelog_file 'some content') + should_fail $(generate_changelog_file 'some content' '') + + should_succeed $(generate_changelog_file 'some content' ':overwrite') +} + +it_uses_generate_changelog_file_to_fail_with_invalid_strategy() { + enter_sandbox + + should_fail $(generate_changelog_file 'some content' '') + should_fail $(generate_changelog_file 'some content' ':anything') + should_fail $(generate_changelog_file 'some content' ':unknown') + + + should_succeed $(generate_changelog_file 'some content' ':overwrite') + should_succeed $(generate_changelog_file 'some content' ':append') +} + +it_uses_generate_changelog_file_file_to_create_a_changelog_file() { + enter_sandbox + + file_should_not_exist "CHANGELOG" + + local content=" +My Content +Is Here Across Multiple Lines +" + local output=$(generate_changelog_file "$content" ':overwrite') + + file_should_exist "CHANGELOG" + + local contents=`cat CHANGELOG` + test "$contents" = "$content +$(changelog_footer)" +} + +it_uses_generate_changelog_file_file_to_create_a_custom_version_file() { + enter_sandbox + + file_should_not_exist "CHANGELOG" + file_should_not_exist "CUSTOM_CHANGELOG" + + local content=" +My Content +Is Here Across Multiple Lines +" + output=$(generate_changelog_file "$content" ':overwrite' 'CUSTOM_CHANGELOG') + + file_should_not_exist "CHANGELOG" + file_should_exist "CUSTOM_CHANGELOG" + + test "`cat CUSTOM_CHANGELOG`" = "$content +$(changelog_footer)" +} + +it_uses_generate_changelog_file_to_replace_any_existing_file_with_overwrite_strategy() { + enter_sandbox + + file_should_not_exist "CHANGELOG" + + output=$(generate_changelog_file 'Original Content' ':overwrite') + + file_should_exist "CHANGELOG" + + test "`cat CHANGELOG`" = "Original Content +$(changelog_footer)" + + output=$(generate_changelog_file 'Updated Content' ':overwrite') + + test "`cat CHANGELOG`" = "Updated Content +$(changelog_footer)" +} + +it_uses_generate_changelog_file_to_append_to_any_existing_file_with_append_strategy() { + enter_sandbox + + file_should_not_exist "CHANGELOG" + + output=$(generate_changelog_file 'Original Content' ':append') + + file_should_exist "CHANGELOG" + + test "`cat CHANGELOG`" = "Original Content +$(changelog_footer)" + + output=$(generate_changelog_file 'Updated Content' ':append') + + test "`cat CHANGELOG`" = "Updated Content +Original Content +$(changelog_footer)" +} diff --git a/test/unit/git-functions-test.sh b/test/unit/git-functions-test.sh new file mode 100644 index 0000000..56d5f0d --- /dev/null +++ b/test/unit/git-functions-test.sh @@ -0,0 +1,215 @@ +#!/bin/bash -e + +. ./test/test_helper.sh +. ./support/git-functions.sh + +describe "releaseable - unit - git functions" + +after() { + if [[ $MAINTAIN_SANDBOX != true ]]; then + remove_sandbox + fi; +} + +it_uses_check_tag_exists_to_return_false_if_no_tags_exist() { + generate_git_repo + + result=$(set +e ; check_tag_exists "not/found/anything" ; echo $?) + test 1 -eq $result + + result=$(set +e ; check_tag_exists "" ; echo $?) + test 1 -eq $result +} + +it_uses_check_tag_exists_to_return_false_if_it_doesnt_exist() { + local tags=( + "release/v1.0.5" + "release/v1.0.6" + ) + generate_sandbox_tags tags[@] + + result=$(set +e ; check_tag_exists "not/found/anything" ; echo $?) + test 1 -eq $result + + result=$(set +e ; check_tag_exists ""; echo $?) + test 1 -eq $result +} + +it_uses_check_tag_exists_to_return_true_if_tag_exists() { + + local tags=( + "release/v1.0.5" + "release/v1.0.6" + ) + generate_sandbox_tags tags[@] + + result=$(set +e ; check_tag_exists "release/v1.0.5" ; echo $?) + test 0 -eq $result + + result=$(set +e ; check_tag_exists "release/v1.0.6" ; echo $?) + test 0 -eq $result +} + +#ensure_git_directory() + +it_fails_on_ensure_git_directory_with_no_git() { + enter_sandbox + rm -rf .git + + should_fail "$(ensure_git_directory)" +} + +it_passes_on_ensure_git_directory_with_git_directory() { + enter_sandbox + mkdir -p .git + + should_succeed $(ensure_git_directory) +} + +#ensure_git_is_clean() + +it_fails_on_ensure_git_is_clean_when_dirty(){ + generate_git_repo + should_succeed $(ensure_git_is_clean) + touch 'AnyOldFile' + should_fail $(ensure_git_is_clean) + + test "$(ensure_git_is_clean)" = "Error - Current branch is in a dirty state, please commit your changes first. +# On branch master +# Untracked files: +# (use \"git add ...\" to include in what will be committed) +# +#"$'\t'"AnyOldFile +nothing added to commit but untracked files present (use \"git add\" to track)" +} + +it_passes_on_ensure_git_is_clean_when_clean(){ + generate_git_repo + + should_succeed $(ensure_git_is_clean) +} + +#get_commits_between_points + +it_uses_get_commits_between_points_to_list_all_commits_with_nothing_passed() { + generate_git_repo + + test "$(get_commits_between_points)" = "$(get_sha_for_first_commit)" +} + +it_uses_get_commits_between_points_to_list_all_commits_from_a_start_point() { + local tags=( + "random_tag_1" + "release/v1.0.5" + "random_tag_2" + "release/v1.0.6" + "random_tag_3" + ) + generate_sandbox_tags tags[@] + + output=$(get_commits_between_points 'random_tag_2') + test "$output" = "$(get_sha_for_tag_name 'random_tag_3') +$(get_sha_for_tag_name 'release/v1.0.6') +$(get_sha_for_tag_name 'random_tag_2')" +} + +it_uses_get_commits_between_points_to_get_nothing_when_no_commits_exists() { + generate_git_repo + + should_fail $(get_commits_between_points 'anyTagName' 'anotherTagName') +} + +it_uses_get_commits_between_points_to_return_commits_with_no_start_point() { + local tags=( + "random_tag_1" + "release/v1.0.5" + "random_tag_2" + "release/v1.0.6" + "random_tag_3" + ) + generate_sandbox_tags tags[@] + + local start_point="" + local end_point="release/v1.0.6" + output=$(get_commits_between_points "$start_point" "$end_point") + + #Ordered by creation date + local target_tag_sha=$(get_sha_for_tag_name 'release/v1.0.6') + local older_sha_1=$(get_sha_for_tag_name 'random_tag_2') + local older_sha_2=$(get_sha_for_tag_name 'release/v1.0.5') + local older_sha_3=$(get_sha_for_tag_name 'random_tag_1') + local initial_commit=$(get_sha_for_first_commit) + + test "$output" = "$target_tag_sha +$older_sha_1 +$older_sha_2 +$older_sha_3 +$initial_commit" +} + +it_uses_get_commits_between_points_to_return_all_commits_between_points_with_filter() { + local tags=( + "random_tag_1" + "random_tag_2" + "release/production/v1.0.9" + "release/production/v3.0.9" + "release/production/v3.1.9" + "release/staging/v2.0.3" + ) + generate_sandbox_tags tags[@] + + local start_point="release/production/v1.0.9" + local end_point="release/production/v3.0.9" + + local commit_message=$(get_commit_message_for_latest_commit 'release/production/v3.0.9') + local target_tag_sha=$(get_sha_for_tag_name 'release/production/v3.0.9') + + output=$(get_commits_between_points "$start_point" "$end_point" "$commit_message") + + test "$output" = "$target_tag_sha" +} + +it_uses_get_commits_between_points_to_return_all_commits_with_no_start_point_with_filter() { + local tags=( + "random_tag_1" + "random_tag_2" + "release/production/v1.0.9" + "release/production/v3.0.9" + "release/production/v3.1.9" + "release/staging/v2.0.3" + ) + generate_sandbox_tags tags[@] + + local start_point="" + local end_point="release/production/v3.1.9" + + local commit_message=$(get_commit_message_for_latest_commit 'release/production/v3.1.9') + local target_tag_sha=$(get_sha_for_tag_name 'release/production/v3.1.9') + + output=$(get_commits_between_points "$start_point" "$end_point" "$commit_message") + + test "$output" = "$target_tag_sha" +} + +it_uses_get_commits_between_points_to_return_all_commits_between_points() { + local tags=( + 'random_tag_1' + 'release/v1.0.5' + 'random_tag_2' + 'release/v1.0.6' + ) + generate_sandbox_tags tags[@] + + local start_point="release/v1.0.5" + local end_point="release/v1.0.6" + output=$(get_commits_between_points "$start_point" "$end_point") + + #Ordered by creation date + local target_tag_sha=$(get_sha_for_tag_name 'release/v1.0.6') + local older_sha_1=$(get_sha_for_tag_name 'random_tag_2') + local older_sha_2=$(get_sha_for_tag_name 'release/v1.0.5') + + test "$output" = "$target_tag_sha +$older_sha_1 +$older_sha_2" +} diff --git a/test/unit/releaseable-test.sh b/test/unit/releaseable-test.sh index e1242fe..a8f56e8 100644 --- a/test/unit/releaseable-test.sh +++ b/test/unit/releaseable-test.sh @@ -1,7 +1,7 @@ #!/bin/bash -e . ./test/test_helper.sh -. ./support/releaseable.sh +. ./support/releaseable-functions.sh describe "releaseable - unit" @@ -33,45 +33,6 @@ it_passes_on_validate_inputs_with_patch_version_type() { should_succeed $(validate_version_type "patch") } -#ensure_git_directory() - -it_fails_on_ensure_git_directory_with_no_git() { - enter_sandbox - rm -rf .git - - should_fail "$(ensure_git_directory)" -} - -it_passes_on_ensure_git_directory_with_git_directory() { - enter_sandbox - mkdir -p .git - - should_succeed $(ensure_git_directory) -} - -#ensure_git_is_clean() - -it_fails_on_ensure_git_is_clean_when_dirty(){ - generate_git_repo - should_succeed $(ensure_git_is_clean) - touch 'AnyOldFile' - should_fail $(ensure_git_is_clean) - - test "$(ensure_git_is_clean)" = "Error - Current branch is in a dirty state, please commit your changes first. -# On branch master -# Untracked files: -# (use \"git add ...\" to include in what will be committed) -# -#"$'\t'"AnyOldFile -nothing added to commit but untracked files present (use \"git add\" to track)" -} - -it_passes_on_ensure_git_is_clean_when_clean(){ - generate_git_repo - - should_succeed $(ensure_git_is_clean) -} - #versioning_prefix() it_uses_versioning_prefix_to_generate_concatenated_prefix() { @@ -237,560 +198,3 @@ it_uses_get_next_version_number_from_tag_to_succeed_incrementing_each_type() { output=$(get_next_version_number_from_tag patch release/v1.0.6) test $output = "1.0.7" } - -#get_commits_between_points - -it_uses_get_commits_between_points_to_list_all_commits_with_nothing_passed() { - generate_git_repo - - test "$(get_commits_between_points)" = "$(get_sha_for_first_commit)" -} - -it_uses_get_commits_between_points_to_list_all_commits_from_a_start_point() { - local tags=( - "random_tag_1" - "release/v1.0.5" - "random_tag_2" - "release/v1.0.6" - "random_tag_3" - ) - generate_sandbox_tags tags[@] - - output=$(get_commits_between_points 'random_tag_2') - test "$output" = "$(get_sha_for_tag_name 'random_tag_3') -$(get_sha_for_tag_name 'release/v1.0.6') -$(get_sha_for_tag_name 'random_tag_2')" -} - -it_uses_get_commits_between_points_to_get_nothing_when_no_commits_exists() { - generate_git_repo - - should_fail $(get_commits_between_points 'anyTagName' 'anotherTagName') -} - -it_uses_get_commits_between_points_to_return_commits_with_no_start_point() { - local tags=( - "random_tag_1" - "release/v1.0.5" - "random_tag_2" - "release/v1.0.6" - "random_tag_3" - ) - generate_sandbox_tags tags[@] - - local start_point="" - local end_point="release/v1.0.6" - output=$(get_commits_between_points "$start_point" "$end_point") - - #Ordered by creation date - local target_tag_sha=$(get_sha_for_tag_name 'release/v1.0.6') - local older_sha_1=$(get_sha_for_tag_name 'random_tag_2') - local older_sha_2=$(get_sha_for_tag_name 'release/v1.0.5') - local older_sha_3=$(get_sha_for_tag_name 'random_tag_1') - local initial_commit=$(get_sha_for_first_commit) - - test "$output" = "$target_tag_sha -$older_sha_1 -$older_sha_2 -$older_sha_3 -$initial_commit" -} - -it_uses_get_commits_between_points_to_return_all_commits_between_points_with_filter() { - local tags=( - "random_tag_1" - "random_tag_2" - "release/production/v1.0.9" - "release/production/v3.0.9" - "release/production/v3.1.9" - "release/staging/v2.0.3" - ) - generate_sandbox_tags tags[@] - - local start_point="release/production/v1.0.9" - local end_point="release/production/v3.0.9" - - local commit_message=$(get_commit_message_for_latest_commit 'release/production/v3.0.9') - local target_tag_sha=$(get_sha_for_tag_name 'release/production/v3.0.9') - - output=$(get_commits_between_points "$start_point" "$end_point" "$commit_message") - - test "$output" = "$target_tag_sha" -} - -it_uses_get_commits_between_points_to_return_all_commits_with_no_start_point_with_filter() { - local tags=( - "random_tag_1" - "random_tag_2" - "release/production/v1.0.9" - "release/production/v3.0.9" - "release/production/v3.1.9" - "release/staging/v2.0.3" - ) - generate_sandbox_tags tags[@] - - local start_point="" - local end_point="release/production/v3.1.9" - - local commit_message=$(get_commit_message_for_latest_commit 'release/production/v3.1.9') - local target_tag_sha=$(get_sha_for_tag_name 'release/production/v3.1.9') - - output=$(get_commits_between_points "$start_point" "$end_point" "$commit_message") - - test "$output" = "$target_tag_sha" -} - -it_uses_get_commits_between_points_to_return_all_commits_between_points() { - local tags=( - 'random_tag_1' - 'release/v1.0.5' - 'random_tag_2' - 'release/v1.0.6' - ) - generate_sandbox_tags tags[@] - - local start_point="release/v1.0.5" - local end_point="release/v1.0.6" - output=$(get_commits_between_points "$start_point" "$end_point") - - #Ordered by creation date - local target_tag_sha=$(get_sha_for_tag_name 'release/v1.0.6') - local older_sha_1=$(get_sha_for_tag_name 'random_tag_2') - local older_sha_2=$(get_sha_for_tag_name 'release/v1.0.5') - - test "$output" = "$target_tag_sha -$older_sha_1 -$older_sha_2" -} - -#get_changelog_text_for_commits - -it_uses_get_changelog_text_for_commits_to_return_titles_by_default() { - local tags=( - 'random_tag_1' - 'release/v1.0.5' - 'random_tag_2' - 'release/v1.0.6' - ) - - local commit_message_1="Release 1.0.6" - local commit_message_2="Random Release 2" - local commit_message_3="Older Release 1.0.5" - - local commit_messages=( - "Random Release numero uno" - "$commit_message_3" - "$commit_message_2" - "$commit_message_1" - ) - generate_sandbox_tags tags[@] commit_messages[@] - - local commit_shas=$(get_commits_between_points "release/v1.0.5" "release/v1.0.6") - - output=$(get_changelog_text_for_commits "$commit_shas") - - test "$output" = "${commit_message_1} -${commit_message_2} -${commit_message_3}" -} - -it_uses_get_changelog_text_for_commits_to_return_titles_with_a_custom_format() { - local tags=( - 'random_tag_1' - 'release/v1.0.5' - 'random_tag_2' - 'release/v1.0.6' - ) - - local commit_message_1="Release 1.0.6" - local commit_message_2="Random Release 2" - local commit_message_3="Older Release 1.0.5" - - local commit_messages=( - "Random Release numero uno" - "$commit_message_3" - "$commit_message_2" - "$commit_message_1" - ) - generate_sandbox_tags tags[@] commit_messages[@] - - local commit_shas=$(get_commits_between_points "release/v1.0.5" "release/v1.0.6") - local sha_array=($commit_shas) - - output=$(get_changelog_text_for_commits "--format=%H--%s" "$commit_shas") - - test "$output" = "${sha_array[0]}--${commit_message_1} -${sha_array[1]}--${commit_message_2} -${sha_array[2]}--${commit_message_3}" -} - -it_uses_get_changelog_text_for_commits_to_return_titles_grouped_by_tags() { - local tags=( - "releases/v0.0.3" - "releases/v0.0.4" - "releases/v0.1.4" - "releases/v1.1.4" - "releases/v1.1.5" - "releases/v1.1.6" - ) - local commit_messages=( - "Start of the project" - "[bugs]Argh, I fixed a bug here" - "[feature] OMG. I had time to write something of use" - "[features]Its so exciting writing useful things!!" - "[bug] What comes up, must come down" - "Some random tweak fix" - ) - generate_sandbox_tags tags[@] commit_messages[@] - local commit_shas=$(get_commits_between_points "${tags[0]}" "${tags[5]}") - - output=$(get_changelog_text_for_commits "$commit_shas") - - local sha_array=($commit_shas) - test "$output" = "Features: - Its so exciting writing useful things!! - OMG. I had time to write something of use - -Bugs: - What comes up, must come down - Argh, I fixed a bug here - -Some random tweak fix -Start of the project" -} - -it_uses_get_changelog_text_for_commits_to_return_titles_grouped_by_tags_case_insensitive() { - local tags=( - "releases/v0.0.3" - "releases/v1.1.5" - "releases/v1.1.6" - ) - local commit_messages=( - "[Bug] Start of the project" - "[BUGS] Argh, I fixed a bug here" - "[fEaTuRes] OMG. I had time to write something of use" - ) - generate_sandbox_tags tags[@] commit_messages[@] - local commit_shas=$(get_commits_between_points "${tags[0]}" "${tags[2]}") - - output=$(get_changelog_text_for_commits "$commit_shas") - - local sha_array=($commit_shas) - test "$output" = "Features: - OMG. I had time to write something of use - -Bugs: - Argh, I fixed a bug here - Start of the project" -} - -it_uses_get_changelog_text_for_commits_to_return_titles_grouped_by_tags_with_multiple_brackets() { - local tags=( - "releases/v0.0.3" - "releases/v1.1.6" - ) - local commit_messages=( - "[BUGS] [QC Some Reference][More Custom References] Fixed the tagged bugs" - "[fEaTuRes][Additonal Tag one] Another referenced feature" - ) - generate_sandbox_tags tags[@] commit_messages[@] - local commit_shas=$(get_commits_between_points "${tags[0]}" "${tags[1]}") - - output=$(get_changelog_text_for_commits "$commit_shas") - - test "$output" = "Features: - [Additonal Tag one] Another referenced feature - -Bugs: - [QC Some Reference][More Custom References] Fixed the tagged bugs" -} - -#generate_changelog_content - -it_uses_generate_changelog_content_to_exit_with_errors_without_release_name() { - generate_git_repo - - should_fail $(generate_changelog_content) - should_fail $(generate_changelog_content '') -} - -it_uses_generate_changelog_content_to_exit_with_errors_with_invalid_commit_filter() { - generate_git_repo - - should_fail $(generate_changelog_content 'AnyOldReleaseName') - should_fail $(generate_changelog_content 'AnyOldReleaseName' '') - should_fail $(generate_changelog_content 'AnyOldReleaseName' ':unknown') - should_fail $(generate_changelog_content 'AnyOldReleaseName' ':anything') - - should_succeed $(generate_changelog_content 'AnyOldReleaseName' ':all_commits') - should_succeed $(generate_changelog_content 'AnyOldReleaseName' ':pulls_only') -} - -it_uses_generate_changelog_content_to_succeed_without_a_startpoint() { - generate_git_repo - - should_succeed $(generate_changelog_content 'v0.0.5' ':all_commits' '' 'releases/end/v02.34') -} - -it_uses_generate_changelog_content_to_succeed_without_an_endpoint() { - generate_git_repo - - should_succeed $(generate_changelog_content 'v0.0.5' ':all_commits' 'releases/v1.0.45') -} - -it_uses_generate_changelog_content_to_generate_with_all_commit_messages(){ - local tags=( - 'random_tag_1' - 'release/v1.0.5' - 'random_tag_2' - 'release/v1.0.6' - ) - local commit_messages=( - 'Message For Random Tag 1' - '[Any Old] Message for 1.0.5' - 'Lots of changes in this commit for random tag 2' - 'latest release to 1.0.6' - ) - - generate_sandbox_tags tags[@] commit_messages[@] - - local custom_release_name="v1.0.7" - local output=$(generate_changelog_content "$custom_release_name" ':all_commits') - - test "$output" = "$(changelog_divider) -|| Release: ${custom_release_name} -|| Released on $(get_current_release_date) -$(changelog_divider) -${commit_messages[3]} -${commit_messages[2]} -${commit_messages[1]} -${commit_messages[0]} -$(get_commit_message_for_first_commit) -$(changelog_divider)" -} - -it_uses_generate_changelog_content_to_generate_with_commit_messages_for_a_range(){ - local tags=( - 'random_tag_1' - 'release/v1.0.5' - 'random_tag_2' - 'release/v1.0.6' - ) - local commit_messages=( - 'Message For Random Tag 1' - '[Any Old] Message for 1.0.5' - 'Lots of changes in this commit for random tag 2' - 'latest release to 1.0.6' - ) - - generate_sandbox_tags tags[@] commit_messages[@] - - local custom_release_name="v1.0.7" - local output=$(generate_changelog_content "$custom_release_name" ':all_commits' 'release/v1.0.5' 'random_tag_2') - - test "$output" = "$(changelog_divider) -|| Release: ${custom_release_name} -|| Released on $(get_current_release_date) -$(changelog_divider) -${commit_messages[2]} -${commit_messages[1]} -$(changelog_divider)" -} - -it_uses_generate_changelog_content_to_generate_scoped_to_only_pull_requests(){ - local tags=( - 'tag_with_pulls_1' - 'tag_witout_pull' - 'tag_with_pulls_2' - 'another_tag_without' - 'tag_with_pulls_3' - 'tag_with_pulls_4' - ) - local commit_messages=( - "Merge pull request #705 from Ferocia/bug/limit-payment-description-length - -[BUG] Pay anyone from the accounts screen" - " This commit is not a pull request and should be ignored" - "Merge pull request #722 from Ferocia/feature/running-balance-field (Anthony Langhorne, 18 hours ago) - -[Features] This is a pull request merging a feature across multiple -lines and continuing" - " Yet another commit,that isn't a pull request" - "Merge pull request #714 from Ferocia/fix-customer-login - -Fixing the customer login but no tag displayed." - "Merge pull request #685 from Ferocia/bug/modal-new-payee - -[Security] Commit fixing the modal with security flaw" - ) - - generate_sandbox_tags tags[@] commit_messages[@] - - local custom_release_name="v2.0.5" - local output=$(generate_changelog_content "$custom_release_name" ':pulls_only') - - test "$output" = "$(changelog_divider) -|| Release: ${custom_release_name} -|| Released on $(get_current_release_date) -$(changelog_divider) -Features: - This is a pull request merging a feature across multiple -lines and continuing - -Security: - Commit fixing the modal with security flaw - -Bugs: - Pay anyone from the accounts screen - -Fixing the customer login but no tag displayed. -$(changelog_divider)" -} - -#generate_version_file - -it_uses_generate_version_file_to_fail_with_no_version_number_passed() { - should_fail $(generate_version_file) -} - -it_uses_generate_version_file_to_create_a_version_file() { - enter_sandbox - - file_should_not_exist "VERSION" - - output=$(generate_version_file 'v12.03.23') - - file_should_exist "VERSION" - - local contents=`cat VERSION` - test "$contents" = "v12.03.23" -} - -it_uses_generate_version_file_to_create_a_custom_version_file() { - enter_sandbox - - file_should_not_exist "CUSTOM_VERSION" - - output=$(generate_version_file 'v12.03.23' 'CUSTOM_VERSION') - - file_should_exist "CUSTOM_VERSION" - - test "`cat CUSTOM_VERSION`" = "v12.03.23" -} - -it_uses_generate_version_file_to_replace_any_existing_version_file() { - enter_sandbox - - file_should_not_exist "VERSION" - - output=$(generate_version_file 'v12.03.23') - - file_should_exist "VERSION" - - test "`cat VERSION`" = "v12.03.23" - - output=$(generate_version_file 'v14.05.25') - - test "`cat VERSION`" = "v14.05.25" -} - -#generate_changelog_file - -it_uses_generate_changelog_file_to_fail_with_content_passed_or_strategy() { - enter_sandbox - - should_fail $(generate_changelog_file) - should_fail $(generate_changelog_file 'some content') - should_fail $(generate_changelog_file 'some content' '') - - should_succeed $(generate_changelog_file 'some content' ':overwrite') -} - -it_uses_generate_changelog_file_to_fail_with_invalid_strategy() { - enter_sandbox - - should_fail $(generate_changelog_file 'some content' '') - should_fail $(generate_changelog_file 'some content' ':anything') - should_fail $(generate_changelog_file 'some content' ':unknown') - - - should_succeed $(generate_changelog_file 'some content' ':overwrite') - should_succeed $(generate_changelog_file 'some content' ':append') -} - -it_uses_generate_changelog_file_file_to_create_a_changelog_file() { - enter_sandbox - - file_should_not_exist "CHANGELOG" - - local content=" -My Content -Is Here Across Multiple Lines -" - local output=$(generate_changelog_file "$content" ':overwrite') - - file_should_exist "CHANGELOG" - - local contents=`cat CHANGELOG` - test "$contents" = "$content -$(changelog_footer)" -} - -it_uses_generate_changelog_file_file_to_create_a_custom_version_file() { - enter_sandbox - - file_should_not_exist "CHANGELOG" - file_should_not_exist "CUSTOM_CHANGELOG" - - local content=" -My Content -Is Here Across Multiple Lines -" - output=$(generate_changelog_file "$content" ':overwrite' 'CUSTOM_CHANGELOG') - - file_should_not_exist "CHANGELOG" - file_should_exist "CUSTOM_CHANGELOG" - - test "`cat CUSTOM_CHANGELOG`" = "$content -$(changelog_footer)" -} - -it_uses_generate_changelog_file_to_replace_any_existing_file_with_overwrite_strategy() { - enter_sandbox - - file_should_not_exist "CHANGELOG" - - output=$(generate_changelog_file 'Original Content' ':overwrite') - - file_should_exist "CHANGELOG" - - test "`cat CHANGELOG`" = "Original Content -$(changelog_footer)" - - output=$(generate_changelog_file 'Updated Content' ':overwrite') - - test "`cat CHANGELOG`" = "Updated Content -$(changelog_footer)" -} - -it_uses_generate_changelog_file_to_append_to_any_existing_file_with_append_strategy() { - enter_sandbox - - file_should_not_exist "CHANGELOG" - - output=$(generate_changelog_file 'Original Content' ':append') - - file_should_exist "CHANGELOG" - - test "`cat CHANGELOG`" = "Original Content -$(changelog_footer)" - - output=$(generate_changelog_file 'Updated Content' ':append') - - test "`cat CHANGELOG`" = "Updated Content -Original Content -$(changelog_footer)" -} - - -