From f812dcd4eb7d4455a184135f12a317414671878b Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Sat, 11 Nov 2023 19:35:20 -0500 Subject: [PATCH 01/24] feat: create bin dir This creates a bin/ directory in the user's home directory and puts it in the path --- scripts/add-bin-dir.sh | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 scripts/add-bin-dir.sh diff --git a/scripts/add-bin-dir.sh b/scripts/add-bin-dir.sh new file mode 100755 index 0000000..8da4528 --- /dev/null +++ b/scripts/add-bin-dir.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Define the bin directory path +BIN_DIR="$HOME/bin" + +# Create the bin directory if it doesn't exist +if [ ! -d "$BIN_DIR" ]; then + mkdir -p "$BIN_DIR" + echo "Created $BIN_DIR" +else + echo "$BIN_DIR already exists." +fi + +# add bin to the PATH only if it's not already there +update_path() { + local profile=$1 + if ! grep -q "PATH=.*:$BIN_DIR" "$profile" && ! grep -q "PATH=$BIN_DIR:.*" "$profile"; then + echo "export PATH=\"\$PATH:$BIN_DIR\"" >> "$profile" + echo "Added $BIN_DIR to PATH in $profile" + else + echo "$BIN_DIR is already in the PATH in $profile" + fi +} + +# Check for zsh or bash and their respective files +if [ -n "$ZSH_VERSION" ]; then + if [ -f "$HOME/.zshrc" ]; then + update_path "$HOME/.zshrc" + fi +elif [ -n "$BASH_VERSION" ]; then + if [ -f "$HOME/.bash_profile" ]; then + update_path "$HOME/.bash_profile" + elif [ -f "$HOME/.bashrc" ]; then + update_path "$HOME/.bashrc" + elif [ -f "$HOME/.profile" ]; then + update_path "$HOME/.profile" + fi +else + echo "Unrecognized shell or profile file not found." +fi + +# Apply the changes by sourcing the profile files +if [ -n "$ZSH_VERSION" ] && [ -f "$HOME/.zshrc" ]; then + source "$HOME/.zshrc" +elif [ -n "$BASH_VERSION" ]; then + if [ -f "$HOME/.bash_profile" ]; then + source "$HOME/.bash_profile" + elif [ -f "$HOME/.bashrc" ]; then + source "$HOME/.bashrc" + elif [ -f "$HOME/.profile" ]; then + source "$HOME/.profile" + fi +fi From eba8203c22c5016965a9d19851cd4c8074d6d2f1 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Sat, 11 Nov 2023 19:36:39 -0500 Subject: [PATCH 02/24] feat: symlink git commands this ensures the home dir has a bin dir and is in the path, then symlinks the git commands --- scripts/link-git-commands.sh | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 scripts/link-git-commands.sh diff --git a/scripts/link-git-commands.sh b/scripts/link-git-commands.sh new file mode 100755 index 0000000..f37d397 --- /dev/null +++ b/scripts/link-git-commands.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Get the directory of the current script +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# Path to the 'add-bin-dir' script, assuming it's in the same directory as this script +ADD_BIN_DIR_SCRIPT="$SCRIPT_DIR/add-bin-dir.sh" + +# Call the 'add-bin-dir' script to ensure 'bin' directory is created and in the PATH +/bin/bash "$ADD_BIN_DIR_SCRIPT" + +# Define the directory where your 'git-' scripts are located, assuming the current directory +GIT_SCRIPTS_DIR="$SCRIPT_DIR" + +# The 'bin' directory path +BIN_DIR="$HOME/bin" + +# Check if the --dry flag is set +DRY_RUN=false +if [ "$1" == "--dry" ]; then + DRY_RUN=true +fi + +# Function to create symlinks or simulate creating them +create_symlink() { + local script=$1 + local symlink_path="$BIN_DIR/$(basename "$script")" + if [ -x "$script" ]; then # Check if the script file is executable + if $DRY_RUN; then + echo "Dry run: Would create symlink for $(basename "$script")" + else + ln -s "$script" "$symlink_path" + echo "Symlink created for $(basename "$script")" + fi + else + echo "Skipped $(basename "$script") as it is not executable." + fi +} + +# Now create symlinks for all 'git-' scripts in the 'bin' directory +for script in "$GIT_SCRIPTS_DIR"/git-*; do + if [[ -f "$script" ]]; then + create_symlink "$script" + fi +done + +# Let the user know the operation is complete +if $DRY_RUN; then + echo "Dry run complete. No symlinks were actually created." +else + echo "All executable Git scripts have been symlinked to $BIN_DIR." +fi From e918e6118acfe955fbccc22a233805d7474cc080 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Sat, 11 Nov 2023 19:38:44 -0500 Subject: [PATCH 03/24] feat: git tickets command This command is used to get the new tickets between two branches --- scripts/git-tickets | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 scripts/git-tickets diff --git a/scripts/git-tickets b/scripts/git-tickets new file mode 100755 index 0000000..b023859 --- /dev/null +++ b/scripts/git-tickets @@ -0,0 +1,66 @@ +#!/bin/bash +# Prompt for a branch name with a default +prompt_for_branch() { + read -p "Enter the name of the $1 branch (default: $2): " branch + echo "${branch:-$2}" # Return the entered branch name or the default if none was entered +} + +# Check for --update flag +UPDATE_BRANCHES=false +for arg in "$@"; do + if [ "$arg" == "--update" ]; then + UPDATE_BRANCHES=true + break + fi +done + +# Prompt for the first branch name if not provided +if [ -z "$1" ] || [ "$1" == "--update" ]; then + BRANCH1=$(prompt_for_branch "first" "master") +else + BRANCH1="$1" +fi + +# Prompt for the second branch name if not provided +if [ -z "$2" ] || [ "$2" == "--update" ]; then + BRANCH2=$(prompt_for_branch "second" "staging") +else + BRANCH2="$2" +fi +# Function to update or create temporary branches +process_branch() { + local branch_name=$1 + local temp_branch="temp_${branch_name}_$$" + if $UPDATE_BRANCHES; then + git checkout $branch_name &> /dev/null + git pull origin $branch_name &> /dev/null + echo "$branch_name" + else + git fetch origin $branch_name:$temp_branch &> /dev/null + echo $temp_branch + fi +} + +# Process the first branch +BRANCH1=$(process_branch $BRANCH1) + +# Process the second branch +BRANCH2=$(process_branch $BRANCH2) + +# If not updating branches, use the temporary branches for log +if ! $UPDATE_BRANCHES; then + # Run the git log command and process the output on temporary branches + git log $BRANCH2..$BRANCH1 --oneline --no-merges | grep -Eio "(\w+)-([0-9]+)" | tr '[:lower:]' '[:upper:]' | sort -u + + # Delete the temporary branches + git branch -D $BRANCH1 &> /dev/null + git branch -D $BRANCH2 &> /dev/null + git status; +else + # Run the git log command and process the output on updated branches + git log $BRANCH2..$BRANCH1 --oneline --no-merges | grep -Eio "(\w+)-([0-9]+)" | tr '[:lower:]' '[:upper:]' | sort -u + + # Checkout to the first branch (assumed to be 'master') + git checkout $BRANCH1 &> /dev/null + git status +fi From 089e44cc625e5638f0a11079c920eac34389759b Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Sat, 11 Nov 2023 19:39:29 -0500 Subject: [PATCH 04/24] feat: git make-release command This command automates the process of preparing a new software release. It creates a release branch from the current branch, increments the version number, updates the `CHANGELOG.md` --- scripts/git-make-release | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 scripts/git-make-release diff --git a/scripts/git-make-release b/scripts/git-make-release new file mode 100755 index 0000000..3f82da3 --- /dev/null +++ b/scripts/git-make-release @@ -0,0 +1,83 @@ +#!/bin/bash + +# Prompt for the version number +prompt_for_version() { + read -p "Enter the version number (default: $1): " version + echo "${version:-$1}" # Return the entered version number or the default if none was entered +} + +# Increment version number +increment_version() { + local IFS='.' + read -a version_parts <<< "$1" + # Increment the minor version and reset patch version + local next_version="${version_parts[0]}.$((version_parts[1] + 1)).0" + + # Prompt for the version number, using the next version as the default + read -p "Enter the version number (default: $next_version): " version + echo "${version:-$next_version}" # Return the entered version number or the default if none was entered +} + +# Get the latest version tag +get_latest_version() { + git describe --tags "$(git rev-list --tags --max-count=1)" +} + +# Prepend the tickets to the CHANGELOG.md +prepend_to_changelog() { + local version=$1 + local tickets=$2 + local date=$(date +"%b %d, %Y") + local changelog="CHANGELOG.md" + + # Create a backup of the CHANGELOG.md + cp "$changelog" "$changelog.bak" + + # Prepend the new content to the CHANGELOG.md + { + echo "# v$version ($date)" + for ticket in $tickets; do + echo "* $ticket - " + done + echo "" + cat "$changelog.bak" + } > "$changelog" + + rm "$changelog.bak" +} + +# Check if the --dry flag is set +DRY_RUN=false +if [ "$1" == "--dry" ]; then + DRY_RUN=true +fi + +# Get the latest tag and suggest the next version number +LATEST_TAG=$(get_latest_version) +NEXT_VERSION=$(increment_version ${LATEST_TAG#v}) # Assuming the tag is in the 'v1.2.3' format + +if $DRY_RUN; then + # Perform a dry run + echo "This is a dry run. The release branch will not be created." + echo "The next version number would be: ${NEXT_VERSION}" + git tickets | grep -Eo '(\w+)-([0-9]+)' +else + # Perform the actual release process + # Capture the output of git-tickets + TICKETS_OUTPUT=$(git tickets --update) + + # Use grep to filter the output + TICKET_IDS=$(echo "$TICKETS_OUTPUT" | grep -Eo '(\w+)-([0-9]+)') + + # Prepend the tickets to the CHANGELOG.md + prepend_to_changelog "$NEXT_VERSION" "$TICKET_IDS" + + # Checkout a new branch with the pattern release-### + git checkout -b "release-${NEXT_VERSION}" + + # Add the CHANGELOG.md to the staging area + git add CHANGELOG.md + + echo "Tickets to be included in this release:" + echo "$TICKET_IDS" +fi From 644711eb2a23d155f50bf7537c61afed5cc4b16c Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Sat, 11 Nov 2023 19:44:20 -0500 Subject: [PATCH 05/24] docs: document the setup scripts and how to use the git scripts --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/README.md b/README.md index 3b44fe3..94ce405 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,55 @@ Inside the `scripts` folder you will find one-off scripts to help with tasks. * `db_migrate.sh` - Helps migrate databases between versions of mysql. +## Git Scripts +Custom scripts that extend Git functionality, to streamline the process of tracking tickets and managing releases + +### Installation +Either copy the scripts into your `PATH` or run the following command to add the scripts to your `PATH` +```shell +scripts/link-git-commands.sh +``` +* This will link git scripts to a `bin` folder in your home directory. If you do not have a `bin` folder, it will create one for you. + +`git-tickets` +--------- +This command is used to get the tickets since staging was was last updated. By default it does not update the branches + +```shell +git tickets [options] [arguments] +``` + +| Options | Description | Default | Any of | +|----------|-----------------------------------------------------------------|---------|--------| +| --update | Update the specified branches from the remote before comparison | | | + +| Arguments | Description | Default | Any of | +|-----------|--------------------------------------|---------|------------| +| branch 1 | the target branch that is up to date | master | any branch | +| branch 2 | the branch that is behind | staging | any branch | + +### Example +```shell + git tickets --update master staging +``` + +`git-make-release` +--------- +This command automates the process of preparing a new software release. It creates a release branch from the current branch, increments the version number, updates the `CHANGELOG.md` + +```shell + git make-release [options] +``` + +| Options | Description | Default | +|----------|-----------------------------------------------------------|---------| +| --dry | Perform a dry run without any changes to branches or tags | N/A | + +### Example +```shell +git make-release --dry +``` + ## Docs * [Setting up Nginx-Proxy](docs/nginx-proxy/README.md) * [Setting up PHP Testing in PhpStorm](docs/phpstorm-docker/README.md) From cb17ff4cef427377de4b90417a64974d29e04f7c Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Sat, 11 Nov 2023 19:54:03 -0500 Subject: [PATCH 06/24] style: fix markdown formatting --- README.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 94ce405..93418ae 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,15 @@ Custom scripts that extend Git functionality, to streamline the process of track ### Installation Either copy the scripts into your `PATH` or run the following command to add the scripts to your `PATH` + ```shell scripts/link-git-commands.sh ``` + * This will link git scripts to a `bin` folder in your home directory. If you do not have a `bin` folder, it will create one for you. -`git-tickets` ---------- +### `git-tickets` + This command is used to get the tickets since staging was was last updated. By default it does not update the branches ```shell @@ -74,13 +76,13 @@ git tickets [options] [arguments] | branch 1 | the target branch that is up to date | master | any branch | | branch 2 | the branch that is behind | staging | any branch | -### Example +### Tickets Example + ```shell git tickets --update master staging ``` -`git-make-release` ---------- +### `git-make-release` This command automates the process of preparing a new software release. It creates a release branch from the current branch, increments the version number, updates the `CHANGELOG.md` ```shell @@ -91,7 +93,8 @@ This command automates the process of preparing a new software release. It creat |----------|-----------------------------------------------------------|---------| | --dry | Perform a dry run without any changes to branches or tags | N/A | -### Example +### Make Release Example + ```shell git make-release --dry ``` From 33126bcd1b437fad0c17064ba641a7f1bc5c7dd3 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Sat, 11 Nov 2023 19:59:50 -0500 Subject: [PATCH 07/24] refactor: fix linting errors --- scripts/git-make-release | 12 +++++++----- scripts/git-tickets | 24 ++++++++++++------------ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/scripts/git-make-release b/scripts/git-make-release index 3f82da3..489d12c 100755 --- a/scripts/git-make-release +++ b/scripts/git-make-release @@ -2,19 +2,19 @@ # Prompt for the version number prompt_for_version() { - read -p "Enter the version number (default: $1): " version + read -rp "Enter the version number (default: $1): " version echo "${version:-$1}" # Return the entered version number or the default if none was entered } # Increment version number increment_version() { local IFS='.' - read -a version_parts <<< "$1" + read -ar version_parts <<< "$1" # Increment the minor version and reset patch version local next_version="${version_parts[0]}.$((version_parts[1] + 1)).0" # Prompt for the version number, using the next version as the default - read -p "Enter the version number (default: $next_version): " version + read -rp "Enter the version number (default: $next_version): " version echo "${version:-$next_version}" # Return the entered version number or the default if none was entered } @@ -27,7 +27,9 @@ get_latest_version() { prepend_to_changelog() { local version=$1 local tickets=$2 - local date=$(date +"%b %d, %Y") + local date + + date=$(date +"%b %d, %Y") local changelog="CHANGELOG.md" # Create a backup of the CHANGELOG.md @@ -54,7 +56,7 @@ fi # Get the latest tag and suggest the next version number LATEST_TAG=$(get_latest_version) -NEXT_VERSION=$(increment_version ${LATEST_TAG#v}) # Assuming the tag is in the 'v1.2.3' format +NEXT_VERSION=$(increment_version "${LATEST_TAG#v}") # Assuming the tag is in the 'v1.2.3' format if $DRY_RUN; then # Perform a dry run diff --git a/scripts/git-tickets b/scripts/git-tickets index b023859..9557139 100755 --- a/scripts/git-tickets +++ b/scripts/git-tickets @@ -1,7 +1,7 @@ #!/bin/bash # Prompt for a branch name with a default prompt_for_branch() { - read -p "Enter the name of the $1 branch (default: $2): " branch + read -rp "Enter the name of the $1 branch (default: $2): " branch echo "${branch:-$2}" # Return the entered branch name or the default if none was entered } @@ -32,35 +32,35 @@ process_branch() { local branch_name=$1 local temp_branch="temp_${branch_name}_$$" if $UPDATE_BRANCHES; then - git checkout $branch_name &> /dev/null - git pull origin $branch_name &> /dev/null + git checkout "$branch_name" &> /dev/null + git pull origin "$branch_name" &> /dev/null echo "$branch_name" else - git fetch origin $branch_name:$temp_branch &> /dev/null - echo $temp_branch + git fetch origin "$branch_name":"$temp_branch" &> /dev/null + echo "$temp_branch" fi } # Process the first branch -BRANCH1=$(process_branch $BRANCH1) +BRANCH1=$(process_branch "$BRANCH1") # Process the second branch -BRANCH2=$(process_branch $BRANCH2) +BRANCH2=$(process_branch "$BRANCH2") # If not updating branches, use the temporary branches for log if ! $UPDATE_BRANCHES; then # Run the git log command and process the output on temporary branches - git log $BRANCH2..$BRANCH1 --oneline --no-merges | grep -Eio "(\w+)-([0-9]+)" | tr '[:lower:]' '[:upper:]' | sort -u + git log "$BRANCH2".."$BRANCH1" --oneline --no-merges | grep -Eio "(\w+)-([0-9]+)" | tr '[:lower:]' '[:upper:]' | sort -u # Delete the temporary branches - git branch -D $BRANCH1 &> /dev/null - git branch -D $BRANCH2 &> /dev/null + git branch -D "$BRANCH1" &> /dev/null + git branch -D "$BRANCH2" &> /dev/null git status; else # Run the git log command and process the output on updated branches - git log $BRANCH2..$BRANCH1 --oneline --no-merges | grep -Eio "(\w+)-([0-9]+)" | tr '[:lower:]' '[:upper:]' | sort -u + git log "$BRANCH2".."$BRANCH1" --oneline --no-merges | grep -Eio "(\w+)-([0-9]+)" | tr '[:lower:]' '[:upper:]' | sort -u # Checkout to the first branch (assumed to be 'master') - git checkout $BRANCH1 &> /dev/null + git checkout "$BRANCH1" &> /dev/null git status fi From 4d605c236d54373bba53283e5ad7bbce948e76d7 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Sat, 11 Nov 2023 20:08:09 -0500 Subject: [PATCH 08/24] style: readme line length --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 93418ae..ca2ca7d 100644 --- a/README.md +++ b/README.md @@ -57,11 +57,13 @@ Either copy the scripts into your `PATH` or run the following command to add the scripts/link-git-commands.sh ``` -* This will link git scripts to a `bin` folder in your home directory. If you do not have a `bin` folder, it will create one for you. +* This will link git scripts to a `bin` folder in your home directory. + If you do not have a `bin` folder, it will create one for you. ### `git-tickets` -This command is used to get the tickets since staging was was last updated. By default it does not update the branches +This command is used to get the tickets since staging was was last updated. +By default, it does not update the branches ```shell git tickets [options] [arguments] @@ -83,7 +85,8 @@ git tickets [options] [arguments] ``` ### `git-make-release` -This command automates the process of preparing a new software release. It creates a release branch from the current branch, increments the version number, updates the `CHANGELOG.md` +This command automates the process of preparing a new software release. +It creates a release branch from the current branch, increments the version number, updates the `CHANGELOG.md` ```shell git make-release [options] From d75fbdcf154156262f938d0d880cf884db945a1a Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Sat, 11 Nov 2023 20:08:40 -0500 Subject: [PATCH 09/24] style: remove double word --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ca2ca7d..ec7f24b 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ scripts/link-git-commands.sh ### `git-tickets` -This command is used to get the tickets since staging was was last updated. +This command is used to get the tickets since staging was last updated. By default, it does not update the branches ```shell From 3164672721d8e197793113f3772a50d5dc6f4352 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Sat, 11 Nov 2023 20:10:36 -0500 Subject: [PATCH 10/24] refactor: delcare and assign separately --- scripts/link-git-commands.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/link-git-commands.sh b/scripts/link-git-commands.sh index f37d397..d48f907 100755 --- a/scripts/link-git-commands.sh +++ b/scripts/link-git-commands.sh @@ -24,7 +24,9 @@ fi # Function to create symlinks or simulate creating them create_symlink() { local script=$1 - local symlink_path="$BIN_DIR/$(basename "$script")" + local symlink_path + symlink_path="$BIN_DIR/$(basename "$script")" + if [ -x "$script" ]; then # Check if the script file is executable if $DRY_RUN; then echo "Dry run: Would create symlink for $(basename "$script")" From 67ce1e22e167271ad4b924fabad657cf6fd29769 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Sat, 11 Nov 2023 20:14:18 -0500 Subject: [PATCH 11/24] style: remove pesky trailing spaces --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ec7f24b..af24688 100644 --- a/README.md +++ b/README.md @@ -57,17 +57,17 @@ Either copy the scripts into your `PATH` or run the following command to add the scripts/link-git-commands.sh ``` -* This will link git scripts to a `bin` folder in your home directory. +* This will link git scripts to a `bin` folder in your home directory. If you do not have a `bin` folder, it will create one for you. ### `git-tickets` -This command is used to get the tickets since staging was last updated. -By default, it does not update the branches +This command is used to get the tickets since staging was last updated. +By default, it does not update the branches. ```shell git tickets [options] [arguments] -``` +``` | Options | Description | Default | Any of | |----------|-----------------------------------------------------------------|---------|--------| @@ -85,7 +85,7 @@ git tickets [options] [arguments] ``` ### `git-make-release` -This command automates the process of preparing a new software release. +This command automates the process of preparing a new software release. It creates a release branch from the current branch, increments the version number, updates the `CHANGELOG.md` ```shell From 25b753624ec6db3c9e7f54bb6673fb2a905bb736 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Sun, 19 Nov 2023 15:15:32 -0500 Subject: [PATCH 12/24] ci: disable shell check SC1091 --- scripts/add-bin-dir.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/add-bin-dir.sh b/scripts/add-bin-dir.sh index 8da4528..38238b0 100755 --- a/scripts/add-bin-dir.sh +++ b/scripts/add-bin-dir.sh @@ -23,11 +23,14 @@ update_path() { } # Check for zsh or bash and their respective files + if [ -n "$ZSH_VERSION" ]; then + echo "updating zsh profile" if [ -f "$HOME/.zshrc" ]; then update_path "$HOME/.zshrc" fi elif [ -n "$BASH_VERSION" ]; then + echo "updating bash profile" if [ -f "$HOME/.bash_profile" ]; then update_path "$HOME/.bash_profile" elif [ -f "$HOME/.bashrc" ]; then @@ -41,13 +44,17 @@ fi # Apply the changes by sourcing the profile files if [ -n "$ZSH_VERSION" ] && [ -f "$HOME/.zshrc" ]; then + # shellcheck disable=SC1091 source "$HOME/.zshrc" elif [ -n "$BASH_VERSION" ]; then if [ -f "$HOME/.bash_profile" ]; then + # shellcheck disable=SC1091 source "$HOME/.bash_profile" elif [ -f "$HOME/.bashrc" ]; then + # shellcheck disable=SC1091 source "$HOME/.bashrc" elif [ -f "$HOME/.profile" ]; then + # shellcheck disable=SC1091 source "$HOME/.profile" fi fi From 5f61c2f1e1336d5a9d7b08494516e2bdf3b84fe9 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:12:12 -0500 Subject: [PATCH 13/24] feat: remove adding bin dir to home --- scripts/add-bin-dir.sh | 60 ------------------------------------------ 1 file changed, 60 deletions(-) delete mode 100755 scripts/add-bin-dir.sh diff --git a/scripts/add-bin-dir.sh b/scripts/add-bin-dir.sh deleted file mode 100755 index 38238b0..0000000 --- a/scripts/add-bin-dir.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash - -# Define the bin directory path -BIN_DIR="$HOME/bin" - -# Create the bin directory if it doesn't exist -if [ ! -d "$BIN_DIR" ]; then - mkdir -p "$BIN_DIR" - echo "Created $BIN_DIR" -else - echo "$BIN_DIR already exists." -fi - -# add bin to the PATH only if it's not already there -update_path() { - local profile=$1 - if ! grep -q "PATH=.*:$BIN_DIR" "$profile" && ! grep -q "PATH=$BIN_DIR:.*" "$profile"; then - echo "export PATH=\"\$PATH:$BIN_DIR\"" >> "$profile" - echo "Added $BIN_DIR to PATH in $profile" - else - echo "$BIN_DIR is already in the PATH in $profile" - fi -} - -# Check for zsh or bash and their respective files - -if [ -n "$ZSH_VERSION" ]; then - echo "updating zsh profile" - if [ -f "$HOME/.zshrc" ]; then - update_path "$HOME/.zshrc" - fi -elif [ -n "$BASH_VERSION" ]; then - echo "updating bash profile" - if [ -f "$HOME/.bash_profile" ]; then - update_path "$HOME/.bash_profile" - elif [ -f "$HOME/.bashrc" ]; then - update_path "$HOME/.bashrc" - elif [ -f "$HOME/.profile" ]; then - update_path "$HOME/.profile" - fi -else - echo "Unrecognized shell or profile file not found." -fi - -# Apply the changes by sourcing the profile files -if [ -n "$ZSH_VERSION" ] && [ -f "$HOME/.zshrc" ]; then - # shellcheck disable=SC1091 - source "$HOME/.zshrc" -elif [ -n "$BASH_VERSION" ]; then - if [ -f "$HOME/.bash_profile" ]; then - # shellcheck disable=SC1091 - source "$HOME/.bash_profile" - elif [ -f "$HOME/.bashrc" ]; then - # shellcheck disable=SC1091 - source "$HOME/.bashrc" - elif [ -f "$HOME/.profile" ]; then - # shellcheck disable=SC1091 - source "$HOME/.profile" - fi -fi From b73539d40572c09c4d5a4932cfd7f350c49c0e56 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:12:41 -0500 Subject: [PATCH 14/24] feat: remove linking git commands --- scripts/link-git-commands.sh | 54 ------------------------------------ 1 file changed, 54 deletions(-) delete mode 100755 scripts/link-git-commands.sh diff --git a/scripts/link-git-commands.sh b/scripts/link-git-commands.sh deleted file mode 100755 index d48f907..0000000 --- a/scripts/link-git-commands.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash - -# Get the directory of the current script -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - -# Path to the 'add-bin-dir' script, assuming it's in the same directory as this script -ADD_BIN_DIR_SCRIPT="$SCRIPT_DIR/add-bin-dir.sh" - -# Call the 'add-bin-dir' script to ensure 'bin' directory is created and in the PATH -/bin/bash "$ADD_BIN_DIR_SCRIPT" - -# Define the directory where your 'git-' scripts are located, assuming the current directory -GIT_SCRIPTS_DIR="$SCRIPT_DIR" - -# The 'bin' directory path -BIN_DIR="$HOME/bin" - -# Check if the --dry flag is set -DRY_RUN=false -if [ "$1" == "--dry" ]; then - DRY_RUN=true -fi - -# Function to create symlinks or simulate creating them -create_symlink() { - local script=$1 - local symlink_path - symlink_path="$BIN_DIR/$(basename "$script")" - - if [ -x "$script" ]; then # Check if the script file is executable - if $DRY_RUN; then - echo "Dry run: Would create symlink for $(basename "$script")" - else - ln -s "$script" "$symlink_path" - echo "Symlink created for $(basename "$script")" - fi - else - echo "Skipped $(basename "$script") as it is not executable." - fi -} - -# Now create symlinks for all 'git-' scripts in the 'bin' directory -for script in "$GIT_SCRIPTS_DIR"/git-*; do - if [[ -f "$script" ]]; then - create_symlink "$script" - fi -done - -# Let the user know the operation is complete -if $DRY_RUN; then - echo "Dry run complete. No symlinks were actually created." -else - echo "All executable Git scripts have been symlinked to $BIN_DIR." -fi From 8678f4987cd91fcb326e0018906ca8cb5b2963e3 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:13:15 -0500 Subject: [PATCH 15/24] refactor: move git scripts to hop project bin --- {scripts => bin}/git-make-release | 0 {scripts => bin}/git-tickets | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {scripts => bin}/git-make-release (100%) rename {scripts => bin}/git-tickets (100%) diff --git a/scripts/git-make-release b/bin/git-make-release similarity index 100% rename from scripts/git-make-release rename to bin/git-make-release diff --git a/scripts/git-tickets b/bin/git-tickets similarity index 100% rename from scripts/git-tickets rename to bin/git-tickets From 036e8af4eb71e7f3c9cd6a60164b70288b412857 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:13:40 -0500 Subject: [PATCH 16/24] docs: remove the install section --- README.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/README.md b/README.md index af24688..19b49df 100644 --- a/README.md +++ b/README.md @@ -50,16 +50,6 @@ Inside the `scripts` folder you will find one-off scripts to help with tasks. ## Git Scripts Custom scripts that extend Git functionality, to streamline the process of tracking tickets and managing releases -### Installation -Either copy the scripts into your `PATH` or run the following command to add the scripts to your `PATH` - -```shell -scripts/link-git-commands.sh -``` - -* This will link git scripts to a `bin` folder in your home directory. - If you do not have a `bin` folder, it will create one for you. - ### `git-tickets` This command is used to get the tickets since staging was last updated. From aec9c39ad79d0cec755c803efe55c45c1c3e3aba Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:32:53 -0500 Subject: [PATCH 17/24] docs: add CLI tooling setup section Stub a section for Hop --- README.md | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 19b49df..3742d55 100644 --- a/README.md +++ b/README.md @@ -27,27 +27,45 @@ cd ./devop-tools/docker/data-source-services && docker-compose up --build -d ``` #### Specific Setup - Windows + * Kill, and optionally disable, the `World Wide Web Publishing Service` * Run `set COMPOSE_CONVERT_WINDOWS_PATHS=1` in your CMD or PowerShell terminal * Optionally, [read](https://github.com/docker/compose/issues/4303#issuecomment-379563170) this bug report. ### Optional: Data Source Tools + * Optionally included is the following tools: - * phpMyAdmin + * phpMyAdmin * `cd ./devop-tools/docker/data-source-tools && docker-compose up --build -d` ## phpMyAdmin + If the optional tools are launched, you can find phpMyAdmin at: localhost:8080 + * It supports the following databases... - * mariadb106 (lts) - * mariadb1011 (lts) + * mariadb106 (lts) + * mariadb1011 (lts) ## Scripts + Inside the `scripts` folder you will find one-off scripts to help with tasks. * `db_migrate.sh` - Helps migrate databases between versions of mysql. +## CLI Tooling Setup + +Add the `bin` directory to your path to use **Hop** and **Git Scripts**. + +```shell +ln -s /path/to/DevopsToolKit/bin /usr/local/bin/sidt +``` + +## Hop + +**MISSING DESCRIPTION** + ## Git Scripts + Custom scripts that extend Git functionality, to streamline the process of tracking tickets and managing releases ### `git-tickets` @@ -75,6 +93,7 @@ git tickets [options] [arguments] ``` ### `git-make-release` + This command automates the process of preparing a new software release. It creates a release branch from the current branch, increments the version number, updates the `CHANGELOG.md` @@ -82,9 +101,9 @@ It creates a release branch from the current branch, increments the version numb git make-release [options] ``` -| Options | Description | Default | -|----------|-----------------------------------------------------------|---------| -| --dry | Perform a dry run without any changes to branches or tags | N/A | +| Options | Description | Default | +|---------|-----------------------------------------------------------|---------| +| --dry | Perform a dry run without any changes to branches or tags | N/A | ### Make Release Example @@ -93,6 +112,7 @@ git make-release --dry ``` ## Docs + * [Setting up Nginx-Proxy](docs/nginx-proxy/README.md) * [Setting up PHP Testing in PhpStorm](docs/phpstorm-docker/README.md) * [Leveraging Yii2 Shell](docs/yii2/yii-shell.md) From a4d95d986bd351eb4e3f56dc0b4b6a6db6d65d8d Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:23:23 -0500 Subject: [PATCH 18/24] fix: correctly get the versioning segments and increment --- bin/git-make-release | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/bin/git-make-release b/bin/git-make-release index 489d12c..4350fd5 100755 --- a/bin/git-make-release +++ b/bin/git-make-release @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Prompt for the version number prompt_for_version() { @@ -8,19 +8,26 @@ prompt_for_version() { # Increment version number increment_version() { - local IFS='.' - read -ar version_parts <<< "$1" - # Increment the minor version and reset patch version + # Split the version string into parts using read -a + IFS='.' + read -ra version_parts <<< "$1" + + # Ensure that we have exactly three parts for major, minor, and patch versions + if [ ${#version_parts[@]} -ne 3 ]; then + echo "Error: Invalid version format '$1'. Expected format 'Major.Minor.Patch'." >&2 + return 1 # Exit the function with an error status + fi + + # Increment the minor version and reset the patch version to 0 local next_version="${version_parts[0]}.$((version_parts[1] + 1)).0" - # Prompt for the version number, using the next version as the default - read -rp "Enter the version number (default: $next_version): " version - echo "${version:-$next_version}" # Return the entered version number or the default if none was entered + # Call prompt_for_version, using the next version as the default + prompt_for_version "$next_version" } # Get the latest version tag get_latest_version() { - git describe --tags "$(git rev-list --tags --max-count=1)" + git describe --tags "$(git rev-list --tags --max-count=1)" 2>/dev/null || echo "v0.0.0" } # Prepend the tickets to the CHANGELOG.md From 5559d58a34d46dedde08fd52cb2dc4bb658bed10 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:38:32 -0500 Subject: [PATCH 19/24] feat: improve branch processing if a target branch doesn't exist --- bin/git-tickets | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bin/git-tickets b/bin/git-tickets index 9557139..1ae9623 100755 --- a/bin/git-tickets +++ b/bin/git-tickets @@ -33,14 +33,23 @@ process_branch() { local temp_branch="temp_${branch_name}_$$" if $UPDATE_BRANCHES; then git checkout "$branch_name" &> /dev/null + if [ $? -ne 0 ]; then + echo "Failed to checkout branch $branch_name" >&2 + exit 1 + fi git pull origin "$branch_name" &> /dev/null echo "$branch_name" else git fetch origin "$branch_name":"$temp_branch" &> /dev/null + if ! git rev-parse --verify "$temp_branch" &> /dev/null; then + echo "Failed to fetch and create temp branch for $branch_name" >&2 + exit 1 + fi echo "$temp_branch" fi } + # Process the first branch BRANCH1=$(process_branch "$BRANCH1") From 1358fc93d507c5f9fda9d9c0455391434398fff2 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:44:06 -0500 Subject: [PATCH 20/24] style: fix formatting --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3742d55..f4cf3ab 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ cd ./devop-tools/docker/data-source-services && docker-compose up --build -d ### Optional: Data Source Tools * Optionally included is the following tools: - * phpMyAdmin +* phpMyAdmin * `cd ./devop-tools/docker/data-source-tools && docker-compose up --build -d` ## phpMyAdmin @@ -43,8 +43,8 @@ cd ./devop-tools/docker/data-source-services && docker-compose up --build -d If the optional tools are launched, you can find phpMyAdmin at: localhost:8080 * It supports the following databases... - * mariadb106 (lts) - * mariadb1011 (lts) +* mariadb106 (lts) +* mariadb1011 (lts) ## Scripts @@ -62,7 +62,7 @@ ln -s /path/to/DevopsToolKit/bin /usr/local/bin/sidt ## Hop -**MISSING DESCRIPTION** +MISSING DESCRIPTION ## Git Scripts From 6a6a4853c65fdbe3aab286046aaffd2076ae8356 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:48:10 -0500 Subject: [PATCH 21/24] style: SC2181 (style): Check exit code directly --- bin/git-tickets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-tickets b/bin/git-tickets index 1ae9623..efddc6b 100755 --- a/bin/git-tickets +++ b/bin/git-tickets @@ -33,7 +33,7 @@ process_branch() { local temp_branch="temp_${branch_name}_$$" if $UPDATE_BRANCHES; then git checkout "$branch_name" &> /dev/null - if [ $? -ne 0 ]; then + if ! git checkout "$branch_name" &> /dev/null; then echo "Failed to checkout branch $branch_name" >&2 exit 1 fi From 5b28a9d92766167c6d29b28451e0b31428c3427c Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:59:18 -0500 Subject: [PATCH 22/24] docs: remove shell command example, decided it's just easier to add bin to path than to symlink it --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index f4cf3ab..f18c5dd 100644 --- a/README.md +++ b/README.md @@ -56,10 +56,6 @@ Inside the `scripts` folder you will find one-off scripts to help with tasks. Add the `bin` directory to your path to use **Hop** and **Git Scripts**. -```shell -ln -s /path/to/DevopsToolKit/bin /usr/local/bin/sidt -``` - ## Hop MISSING DESCRIPTION From 53eaad28b44a5730831fb65fab032c095fd5e453 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Thu, 7 Mar 2024 17:08:01 -0500 Subject: [PATCH 23/24] Update README.md Co-authored-by: Erik Perri <46399654+erik-perri@users.noreply.github.com> --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f18c5dd..0bbe7f9 100644 --- a/README.md +++ b/README.md @@ -73,9 +73,9 @@ By default, it does not update the branches. git tickets [options] [arguments] ``` -| Options | Description | Default | Any of | -|----------|-----------------------------------------------------------------|---------|--------| -| --update | Update the specified branches from the remote before comparison | | | +| Options | Description | Default | +|----------|-----------------------------------------------------------------|---------| +| --update | Update the specified branches from the remote before comparison | N/A | | Arguments | Description | Default | Any of | |-----------|--------------------------------------|---------|------------| From 02d7051b1f090a573394df33b4014a765b053313 Mon Sep 17 00:00:00 2001 From: charlesreffett <59833910+charlesreffett@users.noreply.github.com> Date: Mon, 19 Aug 2024 13:10:14 -0400 Subject: [PATCH 24/24] docs: add simple hop description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a6b666..f814cdb 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ Add the `bin` directory to your path to use **Hop** and **Git Scripts**. ## Hop -MISSING DESCRIPTION +A script that makes it easy to hop into your project containers and run commands. ## Git Scripts