From bc26f0f48bd85ee87607f488ed7e71fbe9cf7859 Mon Sep 17 00:00:00 2001 From: Sawyer Hollenshead Date: Wed, 3 Jan 2024 13:58:33 -0800 Subject: [PATCH] Make update-template.sh more robust to deletions and changes to files (#217) ## Ticket Resolves #196 ## Changes - Copies the changes made in https://github.com/navapbc/template-infra/issues/352 --- .../download-and-install-template.sh | 5 +++ template-only-bin/install-template.sh | 6 ++- template-only-bin/update-template.sh | 44 +++++++++++++++++-- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/template-only-bin/download-and-install-template.sh b/template-only-bin/download-and-install-template.sh index d2b6b896..7a5efe81 100755 --- a/template-only-bin/download-and-install-template.sh +++ b/template-only-bin/download-and-install-template.sh @@ -7,5 +7,10 @@ git clone --single-branch --branch main --depth 1 git@github.com:navapbc/templat echo "Install template" ./template-application-flask/template-only-bin/install-template.sh +# Store template version in a file +cd template-application-flask +git rev-parse HEAD >../.template-flask-version +cd - + echo "Clean up template-application-flask folder" rm -fr template-application-flask diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template.sh index d723362e..37074db0 100755 --- a/template-only-bin/install-template.sh +++ b/template-only-bin/install-template.sh @@ -1,8 +1,8 @@ #!/bin/bash # -# This script installs template-application-flask to your project. Run +# This script installs the template-application-flask to your project. Run # This script from your project's root directory. -set -euo pipefail +set -euox pipefail CUR_DIR=$(pwd) SCRIPT_DIR=$(dirname $0) @@ -10,6 +10,7 @@ TEMPLATE_DIR="$SCRIPT_DIR/.." echo "Copy files from template-application-flask" cd $TEMPLATE_DIR +# Note: Keep this list of paths in sync with INCLUDE_PATHS in update-template.sh cp -r \ .github \ .dockleconfig \ @@ -21,4 +22,5 @@ cp -r \ cd - echo "Remove files relevant only to template development" +# Note: Keep this list of paths in sync with EXCLUDE_OPT in update-template.sh rm .github/workflows/template-only-* diff --git a/template-only-bin/update-template.sh b/template-only-bin/update-template.sh index f989ef85..9f4a1b32 100755 --- a/template-only-bin/update-template.sh +++ b/template-only-bin/update-template.sh @@ -1,10 +1,46 @@ #!/bin/bash -# +# ----------------------------------------------------------------------------- # This script updates template-application-flask in your project. Run # This script from your project's root directory. +# +# Positional parameters: +# TARGET_VERSION (optional) – the version of template-application-flask to upgrade to. +# Defaults to main. +# ----------------------------------------------------------------------------- set -euo pipefail -SCRIPT_DIR=$(dirname $0) +TARGET_VERSION=${1:-"main"} + +CURRENT_VERSION=$(cat .template-flask-version) + +echo "Clone template-application-flask" +git clone https://github.com/navapbc/template-application-flask.git + +echo "Creating patch" +cd template-application-flask +git checkout $TARGET_VERSION + +# Get version hash to update .template-flask-version 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 +INCLUDE_PATHS=" \ + github \ + .dockleconfig \ + .hadolint.yaml \ + app \ + docker-compose.yml \ + docs" +git diff $CURRENT_VERSION $TARGET_VERSION -- $INCLUDE_PATHS >patch +cd - + +echo "Applying patch" +# Note: Keep this list in sync with the removed files in install-template.sh +EXCLUDE_OPT="--exclude=.github/workflows/template-only-*" +git apply $EXCLUDE_OPT --allow-empty template-application-flask/patch + +echo "Saving new template version to .template-application-flask" +echo $TARGET_VERSION_HASH >.template-flask-version -echo "Install template" -$SCRIPT_DIR/install-template.sh +echo "Clean up template-application-flask folder" +rm -fr template-application-flask