Skip to content

Commit bc26f0f

Browse files
authored
Make update-template.sh more robust to deletions and changes to files (#217)
## Ticket Resolves #196 ## Changes - Copies the changes made in navapbc/template-infra#352
1 parent 0dd8c92 commit bc26f0f

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

template-only-bin/download-and-install-template.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@ git clone --single-branch --branch main --depth 1 [email protected]:navapbc/templat
77
echo "Install template"
88
./template-application-flask/template-only-bin/install-template.sh
99

10+
# Store template version in a file
11+
cd template-application-flask
12+
git rev-parse HEAD >../.template-flask-version
13+
cd -
14+
1015
echo "Clean up template-application-flask folder"
1116
rm -fr template-application-flask

template-only-bin/install-template.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
#!/bin/bash
22
#
3-
# This script installs template-application-flask to your project. Run
3+
# This script installs the template-application-flask to your project. Run
44
# This script from your project's root directory.
5-
set -euo pipefail
5+
set -euox pipefail
66

77
CUR_DIR=$(pwd)
88
SCRIPT_DIR=$(dirname $0)
99
TEMPLATE_DIR="$SCRIPT_DIR/.."
1010

1111
echo "Copy files from template-application-flask"
1212
cd $TEMPLATE_DIR
13+
# Note: Keep this list of paths in sync with INCLUDE_PATHS in update-template.sh
1314
cp -r \
1415
.github \
1516
.dockleconfig \
@@ -21,4 +22,5 @@ cp -r \
2122
cd -
2223

2324
echo "Remove files relevant only to template development"
25+
# Note: Keep this list of paths in sync with EXCLUDE_OPT in update-template.sh
2426
rm .github/workflows/template-only-*

template-only-bin/update-template.sh

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,46 @@
11
#!/bin/bash
2-
#
2+
# -----------------------------------------------------------------------------
33
# This script updates template-application-flask in your project. Run
44
# This script from your project's root directory.
5+
#
6+
# Positional parameters:
7+
# TARGET_VERSION (optional) – the version of template-application-flask to upgrade to.
8+
# Defaults to main.
9+
# -----------------------------------------------------------------------------
510
set -euo pipefail
611

7-
SCRIPT_DIR=$(dirname $0)
12+
TARGET_VERSION=${1:-"main"}
13+
14+
CURRENT_VERSION=$(cat .template-flask-version)
15+
16+
echo "Clone template-application-flask"
17+
git clone https://github.com/navapbc/template-application-flask.git
18+
19+
echo "Creating patch"
20+
cd template-application-flask
21+
git checkout $TARGET_VERSION
22+
23+
# Get version hash to update .template-flask-version after patch is successful
24+
TARGET_VERSION_HASH=$(git rev-parse HEAD)
25+
26+
# Note: Keep this list in sync with the files copied in install-template.sh
27+
INCLUDE_PATHS=" \
28+
github \
29+
.dockleconfig \
30+
.hadolint.yaml \
31+
app \
32+
docker-compose.yml \
33+
docs"
34+
git diff $CURRENT_VERSION $TARGET_VERSION -- $INCLUDE_PATHS >patch
35+
cd -
36+
37+
echo "Applying patch"
38+
# Note: Keep this list in sync with the removed files in install-template.sh
39+
EXCLUDE_OPT="--exclude=.github/workflows/template-only-*"
40+
git apply $EXCLUDE_OPT --allow-empty template-application-flask/patch
41+
42+
echo "Saving new template version to .template-application-flask"
43+
echo $TARGET_VERSION_HASH >.template-flask-version
844

9-
echo "Install template"
10-
$SCRIPT_DIR/install-template.sh
45+
echo "Clean up template-application-flask folder"
46+
rm -fr template-application-flask

0 commit comments

Comments
 (0)