From 571c5b6ba01b89aecc731755e6daf94d31fc4767 Mon Sep 17 00:00:00 2001 From: Rocket Date: Wed, 22 May 2024 15:38:37 -0700 Subject: [PATCH 01/11] Add template-only-bin scripts --- .../download-and-install-template.sh | 34 +++++++++++ template-only-bin/install-template.sh | 37 ++++++++++++ template-only-bin/rename-template-app.sh | 47 +++++++++++++++ template-only-bin/update-template.sh | 59 +++++++++++++++++++ 4 files changed, 177 insertions(+) create mode 100755 template-only-bin/download-and-install-template.sh create mode 100755 template-only-bin/install-template.sh create mode 100755 template-only-bin/rename-template-app.sh create mode 100755 template-only-bin/update-template.sh diff --git a/template-only-bin/download-and-install-template.sh b/template-only-bin/download-and-install-template.sh new file mode 100755 index 0000000..e2eaa57 --- /dev/null +++ b/template-only-bin/download-and-install-template.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# ----------------------------------------------------------------------------- +# This script installs an application template to your project. +# Run this script in your project's root directory. +# +# Positional parameters: +# TARGET_VERSION (optional) – the version of the template application to install. +# Defaults to main. Can be any target that can be checked out, including a branch, +# version tag, or commit hash. +# ----------------------------------------------------------------------------- +set -euo pipefail + +TARGET_VERSION=${1:-"main"} +TEMPLATE_NAME="template-application-rails" + +git clone "https://github.com/navapbc/$TEMPLATE_NAME.git" +cd "$TEMPLATE_NAME" + +echo "Checking out $TARGET_VERSION..." +git checkout "$TARGET_VERSION" +cd - &> /dev/null + +echo "Installing $TEMPLATE_NAME..." +"./$TEMPLATE_NAME/template-only-bin/install-template.sh" "$TEMPLATE_NAME" + +echo "Storing template version in a file..." +cd "$TEMPLATE_NAME" +git rev-parse HEAD >../".$TEMPLATE_NAME-version" +cd - &> /dev/null + +echo "Cleaning up $TEMPLATE_NAME folder..." +rm -fr "$TEMPLATE_NAME" + +echo "...Done." \ No newline at end of file diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template.sh new file mode 100755 index 0000000..9ea7f40 --- /dev/null +++ b/template-only-bin/install-template.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# ----------------------------------------------------------------------------- +# This script installs an application template to your project. +# Run this script using ./download-and-install-template.sh +# +# Positional parameters: +# TEMPLATE_NAME (required) – the name of the template to install +# ----------------------------------------------------------------------------- +set -euo pipefail + +CUR_DIR=$(pwd) +SCRIPT_DIR=$(dirname $0) +TEMPLATE_DIR="$SCRIPT_DIR/.." +TEMPLATE_NAME=$1 +# Use shell parameter expansion to get the last word, where the delimiter between +# words is `-`. +# See https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion +TEMPLATE_SHORT_NAME="app-${TEMPLATE_NAME##*-}" + +echo "Copying files from $TEMPLATE_NAME..." +cd $TEMPLATE_DIR +# Note: Keep this list of paths in sync with INCLUDE_PATHS in update-template.sh +# @TODO: Add .grype.yml +cp -r \ + .github \ + .gitignore \ + $TEMPLATE_SHORT_NAME \ + docker-compose.yml \ + docker-compose.mock-production.yml \ + docs \ + $CUR_DIR +cd - >& /dev/null + +echo "Removing files relevant only to template development..." +# Note: Keep this list of paths in sync with EXCLUDE_OPT in update-template.sh +rm -rf .github/workflows/template-only-* +rm -rf .github/ISSUE_TEMPLATE diff --git a/template-only-bin/rename-template-app.sh b/template-only-bin/rename-template-app.sh new file mode 100755 index 0000000..cbd3c3c --- /dev/null +++ b/template-only-bin/rename-template-app.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# ----------------------------------------------------------------------------- +# This script renames the application template in your project. +# Run this script in your project's root directory. +# +# Positional parameters: +# NEW_NAME (required) - the new name for the application, in either snake- or kebab-case +# OLD_NAME (optional) – the old name for the application, in either snake- or kebab-case +# Defaults to the template's short name (e.g. app-rails) +# ----------------------------------------------------------------------------- +set -euo pipefail + +# Helper to get the correct sed -i behavior for both GNU sed and BSD sed (installed by default on macOS) +# Hat tip: https://stackoverflow.com/a/38595160 +sedi () { + sed --version >/dev/null 2>&1 && sed -i -- "$@" || sed -i "" "$@" +} +# Export the function so it can be used in the `find -exec` calls later on +export -f sedi + +NEW_NAME=$1 +OLD_NAME=${2:-"app-rails"} + +# Don't make assumptions about whether the arguments are snake- or kebab-case. Handle both. +# Get kebab-case names +OLD_NAME_KEBAB=$(echo $OLD_NAME | tr "_" "-") +NEW_NAME_KEBAB=$(echo $NEW_NAME | tr "_" "-") + +# Get snake-case names +OLD_NAME_SNAKE=$(echo $OLD_NAME | tr "-" "_") +NEW_NAME_SNAKE=$(echo $NEW_NAME | tr "-" "_") + +# Rename the app directory +if [ -d "$OLD_NAME" ]; then + echo "Renaming $OLD_NAME to $NEW_NAME..." + mv "$OLD_NAME" "$NEW_NAME" +fi + +# Rename all kebab-case instances +echo "Performing a find-and-replace for all instances of (kebab-case) '$OLD_NAME_KEBAB' with '$NEW_NAME_KEBAB'..." +LC_ALL=C find . -type f -exec bash -c "sedi \"s/$OLD_NAME_KEBAB/$NEW_NAME_KEBAB/g\" \"{}\"" \; + +# Rename all snake-case instances +echo "Performing a find-and-replace for all instances of (snake-case) '$OLD_NAME_SNAKE' with '$NEW_NAME_SNAKE'..." +LC_ALL=C find . -type f -exec bash -c "sedi \"s/$OLD_NAME_SNAKE/$NEW_NAME_SNAKE/g\" \"{}\"" \; + +echo "...Done." diff --git a/template-only-bin/update-template.sh b/template-only-bin/update-template.sh new file mode 100755 index 0000000..3db156e --- /dev/null +++ b/template-only-bin/update-template.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +# ----------------------------------------------------------------------------- +# This script updates an application template in your project. +# Run this script in your project's root directory. +# +# Positional parameters: +# TEMPLATE_NAME (required) – the name of the template to update. Should be in the +# format `template-application-`. This is case sensitive and must match +# the name of the application template git repo name. +# +# TARGET_VERSION (optional) – the version of the template application to install. +# Defaults to main. Can be any target that can be checked out, including a branch, +# version tag, or commit hash. +# ----------------------------------------------------------------------------- +set -euo pipefail + +TEMPLATE_NAME=$1 +TARGET_VERSION=${2:-"main"} +CURRENT_VERSION=$(cat ".$TEMPLATE_NAME-version") +# Use shell parameter expansion to get the last word, where the delimiter between +# words is `-`. +# See https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion +TEMPLATE_SHORT_NAME="app-${TEMPLATE_NAME##*-}" + +echo "Cloning $TEMPLATE_NAME..." +git clone "https://github.com/navapbc/$TEMPLATE_NAME.git" + +echo "Creating patch..." +cd "$TEMPLATE_NAME" +git checkout "$TARGET_VERSION" + +# Get version hash to update version file with after patch is successful +TARGET_VERSION_HASH=$(git rev-parse HEAD) + +# Note: Keep this list in sync with the files copied in install-template.sh +# @TODO: Add .grype.yml +INCLUDE_PATHS=" \ + .github \ + .gitignore \ + $TEMPLATE_SHORT_NAME \ + docker-compose.yml \ + docker-compose.mock-production.yml \ + docs" +git diff "$CURRENT_VERSION" "$TARGET_VERSION" -- "$INCLUDE_PATHS" >patch +cd - >& /dev/null + +echo "Applying patch..." +# Note: Keep this list in sync with the removed files in install-template.sh +EXCLUDE_OPT="--exclude=.github/workflows/template-only-* \ + --exclude=.github/ISSUE_TEMPLATE" +git apply "$EXCLUDE_OPT" --allow-empty "$TEMPLATE_NAME/patch" + +echo "Saving new template version to .$TEMPLATE_NAME-version..." +echo "$TARGET_VERSION_HASH" >".$TEMPLATE_NAME-version" + +echo "Cleaning up $TEMPLATE_NAME folder..." +rm -rf "$TEMPLATE_NAME" + +echo "...Done." From ecad5b970c8db093599e12d58dfa352c45c01620 Mon Sep 17 00:00:00 2001 From: Rocket Date: Wed, 22 May 2024 15:40:35 -0700 Subject: [PATCH 02/11] Don't require an arg for update-template --- template-only-bin/update-template.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/template-only-bin/update-template.sh b/template-only-bin/update-template.sh index 3db156e..f5a02e3 100755 --- a/template-only-bin/update-template.sh +++ b/template-only-bin/update-template.sh @@ -4,17 +4,13 @@ # Run this script in your project's root directory. # # Positional parameters: -# TEMPLATE_NAME (required) – the name of the template to update. Should be in the -# format `template-application-`. This is case sensitive and must match -# the name of the application template git repo name. -# # TARGET_VERSION (optional) – the version of the template application to install. # Defaults to main. Can be any target that can be checked out, including a branch, # version tag, or commit hash. # ----------------------------------------------------------------------------- set -euo pipefail -TEMPLATE_NAME=$1 +TEMPLATE_NAME="template-application-rails" TARGET_VERSION=${2:-"main"} CURRENT_VERSION=$(cat ".$TEMPLATE_NAME-version") # Use shell parameter expansion to get the last word, where the delimiter between From 2c58f3b759ed40290f2cfcfafee1f025255799ab Mon Sep 17 00:00:00 2001 From: Rocket Date: Wed, 22 May 2024 15:45:37 -0700 Subject: [PATCH 03/11] Add blank docker-compose.mock-production.yml --- docker-compose.mock-production.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 docker-compose.mock-production.yml diff --git a/docker-compose.mock-production.yml b/docker-compose.mock-production.yml new file mode 100644 index 0000000..e69de29 From 05487d293e8be26f215b5e2d912ce6215e5db5a7 Mon Sep 17 00:00:00 2001 From: Rocket Date: Wed, 22 May 2024 16:03:51 -0700 Subject: [PATCH 04/11] Ignore .git --- template-only-bin/rename-template-app.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/template-only-bin/rename-template-app.sh b/template-only-bin/rename-template-app.sh index cbd3c3c..80ad842 100755 --- a/template-only-bin/rename-template-app.sh +++ b/template-only-bin/rename-template-app.sh @@ -38,10 +38,10 @@ fi # Rename all kebab-case instances echo "Performing a find-and-replace for all instances of (kebab-case) '$OLD_NAME_KEBAB' with '$NEW_NAME_KEBAB'..." -LC_ALL=C find . -type f -exec bash -c "sedi \"s/$OLD_NAME_KEBAB/$NEW_NAME_KEBAB/g\" \"{}\"" \; +LC_ALL=C find . -type f -not -path "./.git/*" -exec bash -c "sedi \"s/$OLD_NAME_KEBAB/$NEW_NAME_KEBAB/g\" \"{}\"" \; # Rename all snake-case instances echo "Performing a find-and-replace for all instances of (snake-case) '$OLD_NAME_SNAKE' with '$NEW_NAME_SNAKE'..." -LC_ALL=C find . -type f -exec bash -c "sedi \"s/$OLD_NAME_SNAKE/$NEW_NAME_SNAKE/g\" \"{}\"" \; +LC_ALL=C find . -type f -not -path "./.git/*" -exec bash -c "sedi \"s/$OLD_NAME_SNAKE/$NEW_NAME_SNAKE/g\" \"{}\"" \; echo "...Done." From bfe6c7b4b47928b657b7c40fe81dbed9de989d26 Mon Sep 17 00:00:00 2001 From: Rocket Date: Wed, 22 May 2024 17:06:58 -0700 Subject: [PATCH 05/11] Refactor template-only-bin scripts --- .../download-and-install-template.sh | 34 ++++++++++++------- template-only-bin/install-template.sh | 28 +++++++++------ template-only-bin/rename-template-app.sh | 31 ++++++++--------- 3 files changed, 54 insertions(+), 39 deletions(-) diff --git a/template-only-bin/download-and-install-template.sh b/template-only-bin/download-and-install-template.sh index e2eaa57..252077c 100755 --- a/template-only-bin/download-and-install-template.sh +++ b/template-only-bin/download-and-install-template.sh @@ -4,31 +4,39 @@ # Run this script in your project's root directory. # # Positional parameters: -# TARGET_VERSION (optional) – the version of the template application to install. +# target_version (optional) – the version of the template application to install. # Defaults to main. Can be any target that can be checked out, including a branch, # version tag, or commit hash. +# app_name (optional) – the new name for the application, in either snake- or kebab-case +# Defaults to app-rails. # ----------------------------------------------------------------------------- set -euo pipefail -TARGET_VERSION=${1:-"main"} -TEMPLATE_NAME="template-application-rails" +template_name="template-application-rails" +# Use shell parameter expansion to get the last word, where the delimiter between +# words is `-`. +# See https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion +template_short_name="app-${template_name##*-}" -git clone "https://github.com/navapbc/$TEMPLATE_NAME.git" -cd "$TEMPLATE_NAME" +target_version=${1:-"main"} +app_name=${2:-"${template_short_name}"} -echo "Checking out $TARGET_VERSION..." -git checkout "$TARGET_VERSION" +git clone "https://github.com/navapbc/${template_name}.git" +cd "${template_name}" + +echo "Checking out $target_version..." +git checkout "$target_version" cd - &> /dev/null -echo "Installing $TEMPLATE_NAME..." -"./$TEMPLATE_NAME/template-only-bin/install-template.sh" "$TEMPLATE_NAME" +echo "Installing ${template_name}..." +"./${template_name}/template-only-bin/install-template.sh" "${template_name}" "${app_name}" echo "Storing template version in a file..." -cd "$TEMPLATE_NAME" -git rev-parse HEAD >../".$TEMPLATE_NAME-version" +cd "${template_name}" +git rev-parse HEAD >../".${template_name}-version" cd - &> /dev/null -echo "Cleaning up $TEMPLATE_NAME folder..." -rm -fr "$TEMPLATE_NAME" +echo "Cleaning up ${template_name} folder..." +rm -fr "${template_name}" echo "...Done." \ No newline at end of file diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template.sh index 9ea7f40..b7c8a0d 100755 --- a/template-only-bin/install-template.sh +++ b/template-only-bin/install-template.sh @@ -4,31 +4,39 @@ # Run this script using ./download-and-install-template.sh # # Positional parameters: -# TEMPLATE_NAME (required) – the name of the template to install +# template_name (required) – the name of the template to install +# app_name (required) – the name of the application # ----------------------------------------------------------------------------- set -euo pipefail -CUR_DIR=$(pwd) -SCRIPT_DIR=$(dirname $0) -TEMPLATE_DIR="$SCRIPT_DIR/.." -TEMPLATE_NAME=$1 +template_name=$1 # Use shell parameter expansion to get the last word, where the delimiter between # words is `-`. # See https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion -TEMPLATE_SHORT_NAME="app-${TEMPLATE_NAME##*-}" +template_short_name="app-${template_name##*-}" +app_name=$2 -echo "Copying files from $TEMPLATE_NAME..." -cd $TEMPLATE_DIR +curr_dir=$(pwd) +script_dir=$(dirname $0) +template_dir="${script_dir}/.." + +if [ "$template_short_name" = "$app_name" ]; then + echo "Modifying template to use ${app_name} instead of ${template_short_name}..." + "./${template_name}/template-only-bin/rename-template.sh" "${app_name}" "${template_short_name}" +fi + +echo "Copying files from $template_name..." +cd $template_dir # Note: Keep this list of paths in sync with INCLUDE_PATHS in update-template.sh # @TODO: Add .grype.yml cp -r \ .github \ .gitignore \ - $TEMPLATE_SHORT_NAME \ + "${app_name}" \ docker-compose.yml \ docker-compose.mock-production.yml \ docs \ - $CUR_DIR + $curr_dir cd - >& /dev/null echo "Removing files relevant only to template development..." diff --git a/template-only-bin/rename-template-app.sh b/template-only-bin/rename-template-app.sh index 80ad842..a012b93 100755 --- a/template-only-bin/rename-template-app.sh +++ b/template-only-bin/rename-template-app.sh @@ -4,9 +4,8 @@ # Run this script in your project's root directory. # # Positional parameters: -# NEW_NAME (required) - the new name for the application, in either snake- or kebab-case -# OLD_NAME (optional) – the old name for the application, in either snake- or kebab-case -# Defaults to the template's short name (e.g. app-rails) +# new_name (required) - the new name for the application, in either snake- or kebab-case +# old_name (required) – the old name for the application, in either snake- or kebab-case # ----------------------------------------------------------------------------- set -euo pipefail @@ -18,30 +17,30 @@ sedi () { # Export the function so it can be used in the `find -exec` calls later on export -f sedi -NEW_NAME=$1 -OLD_NAME=${2:-"app-rails"} +new_name=$1 +old_name=$2 # Don't make assumptions about whether the arguments are snake- or kebab-case. Handle both. # Get kebab-case names -OLD_NAME_KEBAB=$(echo $OLD_NAME | tr "_" "-") -NEW_NAME_KEBAB=$(echo $NEW_NAME | tr "_" "-") +old_name_kebab=$(echo $old_name | tr "_" "-") +new_name_kebab=$(echo $new_name | tr "_" "-") # Get snake-case names -OLD_NAME_SNAKE=$(echo $OLD_NAME | tr "-" "_") -NEW_NAME_SNAKE=$(echo $NEW_NAME | tr "-" "_") +old_name_snake=$(echo $old_name | tr "-" "_") +new_name_snake=$(echo $new_name | tr "-" "_") # Rename the app directory -if [ -d "$OLD_NAME" ]; then - echo "Renaming $OLD_NAME to $NEW_NAME..." - mv "$OLD_NAME" "$NEW_NAME" +if [ -d "$old_name" ]; then + echo "Renaming ${old_name} to ${new_name}..." + mv "${old_name}" "${new_name}" fi # Rename all kebab-case instances -echo "Performing a find-and-replace for all instances of (kebab-case) '$OLD_NAME_KEBAB' with '$NEW_NAME_KEBAB'..." -LC_ALL=C find . -type f -not -path "./.git/*" -exec bash -c "sedi \"s/$OLD_NAME_KEBAB/$NEW_NAME_KEBAB/g\" \"{}\"" \; +echo "Performing a find-and-replace for all instances of (kebab-case) '$old_name_kebab' with '$new_name_kebab'..." +LC_ALL=C find . -type f -not -path "./.git/*" -exec bash -c "sedi \"s/$old_name_kebab/$new_name_kebab/g\" \"{}\"" \; # Rename all snake-case instances -echo "Performing a find-and-replace for all instances of (snake-case) '$OLD_NAME_SNAKE' with '$NEW_NAME_SNAKE'..." -LC_ALL=C find . -type f -not -path "./.git/*" -exec bash -c "sedi \"s/$OLD_NAME_SNAKE/$NEW_NAME_SNAKE/g\" \"{}\"" \; +echo "Performing a find-and-replace for all instances of (snake-case) '$old_name_snake' with '$new_name_snake'..." +LC_ALL=C find . -type f -not -path "./.git/*" -exec bash -c "sedi \"s/$old_name_snake/$new_name_snake/g\" \"{}\"" \; echo "...Done." From 3e7a7ddc84b0f2d6f2299e12003a0496132f7fda Mon Sep 17 00:00:00 2001 From: Rocket Date: Wed, 22 May 2024 21:39:24 -0700 Subject: [PATCH 06/11] Fix typo --- template-only-bin/install-template.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template.sh index b7c8a0d..9093131 100755 --- a/template-only-bin/install-template.sh +++ b/template-only-bin/install-template.sh @@ -20,7 +20,7 @@ curr_dir=$(pwd) script_dir=$(dirname $0) template_dir="${script_dir}/.." -if [ "$template_short_name" = "$app_name" ]; then +if [ "$template_short_name" != "$app_name" ]; then echo "Modifying template to use ${app_name} instead of ${template_short_name}..." "./${template_name}/template-only-bin/rename-template.sh" "${app_name}" "${template_short_name}" fi From 81dc10c1531906cff0418b08bb4d8515dd5f6690 Mon Sep 17 00:00:00 2001 From: Rocket Date: Wed, 22 May 2024 21:40:24 -0700 Subject: [PATCH 07/11] Fix another typo --- template-only-bin/install-template.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template.sh index 9093131..0050f55 100755 --- a/template-only-bin/install-template.sh +++ b/template-only-bin/install-template.sh @@ -22,7 +22,7 @@ template_dir="${script_dir}/.." if [ "$template_short_name" != "$app_name" ]; then echo "Modifying template to use ${app_name} instead of ${template_short_name}..." - "./${template_name}/template-only-bin/rename-template.sh" "${app_name}" "${template_short_name}" + "./${template_name}/template-only-bin/rename-template-app.sh" "${app_name}" "${template_short_name}" fi echo "Copying files from $template_name..." From e190f62a8e36f1fa3037b7b07314bd91e8b4e327 Mon Sep 17 00:00:00 2001 From: Rocket Date: Wed, 22 May 2024 21:42:25 -0700 Subject: [PATCH 08/11] Rename from within the correct dir --- template-only-bin/install-template.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template.sh index 0050f55..54dabd3 100755 --- a/template-only-bin/install-template.sh +++ b/template-only-bin/install-template.sh @@ -20,13 +20,14 @@ curr_dir=$(pwd) script_dir=$(dirname $0) template_dir="${script_dir}/.." +cd $template_dir + if [ "$template_short_name" != "$app_name" ]; then echo "Modifying template to use ${app_name} instead of ${template_short_name}..." "./${template_name}/template-only-bin/rename-template-app.sh" "${app_name}" "${template_short_name}" fi echo "Copying files from $template_name..." -cd $template_dir # Note: Keep this list of paths in sync with INCLUDE_PATHS in update-template.sh # @TODO: Add .grype.yml cp -r \ From e9c22c2c64917f94b23771d2a1db03ab7a410696 Mon Sep 17 00:00:00 2001 From: Rocket Date: Wed, 22 May 2024 21:43:39 -0700 Subject: [PATCH 09/11] Still using the wrong dir --- template-only-bin/install-template.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template.sh index 54dabd3..da2b8e9 100755 --- a/template-only-bin/install-template.sh +++ b/template-only-bin/install-template.sh @@ -24,7 +24,7 @@ cd $template_dir if [ "$template_short_name" != "$app_name" ]; then echo "Modifying template to use ${app_name} instead of ${template_short_name}..." - "./${template_name}/template-only-bin/rename-template-app.sh" "${app_name}" "${template_short_name}" + "./template-only-bin/rename-template-app.sh" "${app_name}" "${template_short_name}" fi echo "Copying files from $template_name..." From c219b8f72b4ae9a60eefb70e8770ba834bfcad4b Mon Sep 17 00:00:00 2001 From: Rocket Date: Wed, 22 May 2024 21:48:35 -0700 Subject: [PATCH 10/11] Add output info --- template-only-bin/download-and-install-template.sh | 4 ++++ template-only-bin/install-template.sh | 3 +++ 2 files changed, 7 insertions(+) diff --git a/template-only-bin/download-and-install-template.sh b/template-only-bin/download-and-install-template.sh index 252077c..0e368cd 100755 --- a/template-only-bin/download-and-install-template.sh +++ b/template-only-bin/download-and-install-template.sh @@ -21,6 +21,10 @@ template_short_name="app-${template_name##*-}" target_version=${1:-"main"} app_name=${2:-"${template_short_name}"} +echo "template_short_name: ${template_short_name}" +echo "app_name: ${app_name}" +echo "target_version: ${target_version}" + git clone "https://github.com/navapbc/${template_name}.git" cd "${template_name}" diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template.sh index da2b8e9..9b7805f 100755 --- a/template-only-bin/install-template.sh +++ b/template-only-bin/install-template.sh @@ -16,6 +16,9 @@ template_name=$1 template_short_name="app-${template_name##*-}" app_name=$2 +echo "template_short_name: ${template_short_name}" +echo "app_name: ${app_name}" + curr_dir=$(pwd) script_dir=$(dirname $0) template_dir="${script_dir}/.." From b6fa41560d0dd76929f89562cc44ef9b91d44a2d Mon Sep 17 00:00:00 2001 From: Rocket Date: Wed, 22 May 2024 22:01:24 -0700 Subject: [PATCH 11/11] Remove update-template.sh --- template-only-bin/update-template.sh | 55 ---------------------------- 1 file changed, 55 deletions(-) delete mode 100755 template-only-bin/update-template.sh diff --git a/template-only-bin/update-template.sh b/template-only-bin/update-template.sh deleted file mode 100755 index f5a02e3..0000000 --- a/template-only-bin/update-template.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash -# ----------------------------------------------------------------------------- -# This script updates an application template in your project. -# Run this script in your project's root directory. -# -# Positional parameters: -# TARGET_VERSION (optional) – the version of the template application to install. -# Defaults to main. Can be any target that can be checked out, including a branch, -# version tag, or commit hash. -# ----------------------------------------------------------------------------- -set -euo pipefail - -TEMPLATE_NAME="template-application-rails" -TARGET_VERSION=${2:-"main"} -CURRENT_VERSION=$(cat ".$TEMPLATE_NAME-version") -# Use shell parameter expansion to get the last word, where the delimiter between -# words is `-`. -# See https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion -TEMPLATE_SHORT_NAME="app-${TEMPLATE_NAME##*-}" - -echo "Cloning $TEMPLATE_NAME..." -git clone "https://github.com/navapbc/$TEMPLATE_NAME.git" - -echo "Creating patch..." -cd "$TEMPLATE_NAME" -git checkout "$TARGET_VERSION" - -# Get version hash to update version file with after patch is successful -TARGET_VERSION_HASH=$(git rev-parse HEAD) - -# Note: Keep this list in sync with the files copied in install-template.sh -# @TODO: Add .grype.yml -INCLUDE_PATHS=" \ - .github \ - .gitignore \ - $TEMPLATE_SHORT_NAME \ - docker-compose.yml \ - docker-compose.mock-production.yml \ - docs" -git diff "$CURRENT_VERSION" "$TARGET_VERSION" -- "$INCLUDE_PATHS" >patch -cd - >& /dev/null - -echo "Applying patch..." -# Note: Keep this list in sync with the removed files in install-template.sh -EXCLUDE_OPT="--exclude=.github/workflows/template-only-* \ - --exclude=.github/ISSUE_TEMPLATE" -git apply "$EXCLUDE_OPT" --allow-empty "$TEMPLATE_NAME/patch" - -echo "Saving new template version to .$TEMPLATE_NAME-version..." -echo "$TARGET_VERSION_HASH" >".$TEMPLATE_NAME-version" - -echo "Cleaning up $TEMPLATE_NAME folder..." -rm -rf "$TEMPLATE_NAME" - -echo "...Done."