|
2 | 2 | set -ue |
3 | 3 |
|
4 | 4 | # Usage: bin/compare.sh -l name=loki |
| 5 | +# Alternative: bin/compare.sh base-branch-copy feat-branch-copy -l name=loki |
5 | 6 | # Optional: --diff-output <filename> writes the final diff to a file and skips common chart version information |
6 | 7 | # Deps: dyff, helmfile |
7 | 8 | # brew install homeport/tap/dyff |
8 | 9 | # brew install helmfile |
9 | 10 |
|
10 | | -export ENV_DIR=$PWD/tests/fixtures |
11 | | - |
12 | 11 | diffOutput= |
13 | 12 | templateArgs= |
| 13 | +srcDirA= |
| 14 | +srcDirB= |
| 15 | +targetDirA= |
| 16 | +targetDirB= |
14 | 17 | # Process arguments |
15 | 18 | while [ $# -ne 0 ]; do |
16 | 19 | case "$1" in |
17 | 20 | --diff-output) |
18 | 21 | diffOutput="$2" |
19 | 22 | shift |
20 | 23 | ;; |
21 | | - *) |
22 | | - # Forward everything else to the template command |
| 24 | + -*) |
| 25 | + # Forward other options to the template command |
23 | 26 | templateArgs=("${templateArgs[@]}" "$1") |
24 | 27 | ;; |
| 28 | + *) |
| 29 | + # Process first two positional arguments as potential working directories |
| 30 | + if [ -z "$srcDirA" ]; then |
| 31 | + srcDirA=$(realpath "$1") |
| 32 | + elif [ -z "$srcDirB" ]; then |
| 33 | + srcDirB=$(realpath "$1") |
| 34 | + else |
| 35 | + # Forward everything else to the template command |
| 36 | + templateArgs=("${templateArgs[@]}" "$1") |
| 37 | + fi |
| 38 | + ;; |
25 | 39 | esac |
26 | 40 | shift |
27 | 41 | done |
28 | 42 |
|
29 | 43 | readonly script_dir=$(dirname "$0") |
30 | | -readonly branchA='main' |
31 | | -# branchB current branch |
32 | | -readonly branchB=$(git rev-parse --abbrev-ref HEAD) |
33 | 44 |
|
34 | | -targetDirA="tmp/${branchA}" |
35 | | -targetDirB="tmp/${branchB}" |
| 45 | +generate_helm_templates() { |
| 46 | + local target_dir="$1" |
| 47 | + rm -rf "$target_dir" |
| 48 | + node --no-warnings --import tsx src/otomi.ts -- values |
| 49 | + helmfile template "${templateArgs[@]}" --output-dir-template="$target_dir/{{.Release.Namespace}}-{{.Release.Name}}" |
| 50 | + mv tests/fixtures/values-repo.yaml "$target_dir/values-repo.yaml" |
| 51 | +} |
36 | 52 |
|
37 | 53 | export NODE_ENV=test |
38 | | -node --no-warnings --import tsx src/otomi.ts -- values |
39 | | -helmfile template "${templateArgs[@]}" --output-dir-template="$targetDirB/{{.Release.Namespace}}-{{.Release.Name }}" |
40 | | -mv tests/fixtures/values-repo.yaml "$targetDirB/values-repo.yaml" |
41 | | -git -c core.hooksPath=/dev/null checkout -f $branchA |
42 | | -# we remove previously rendered manifests so they are not mixed up with newly rendered |
43 | | -rm -rf $targetDirA |
44 | | -node --no-warnings --import tsx src/otomi.ts -- values |
45 | | -helmfile template "${templateArgs[@]}" --output-dir-template="$targetDirA/{{.Release.Namespace}}-{{.Release.Name}}" |
46 | | -mv tests/fixtures/values-repo.yaml "$targetDirA/values-repo.yaml" |
47 | | -git -c core.hooksPath=/dev/null checkout -f $branchB |
| 54 | +if [ -z "$srcDirA" ]; then |
| 55 | + branchA='main' |
| 56 | + # branchB current branch |
| 57 | + branchB=$(git rev-parse --abbrev-ref HEAD) |
| 58 | + |
| 59 | + targetDirA="$PWD/tmp/${branchA}" |
| 60 | + targetDirB="$PWD/tmp/${branchB}" |
| 61 | + export ENV_DIR="$PWD/tests/fixtures" |
| 62 | + generate_helm_templates "$targetDirB" |
| 63 | + git -c core.hooksPath=/dev/null checkout -f $branchA |
| 64 | + generate_helm_templates "$targetDirA" |
| 65 | + git -c core.hooksPath=/dev/null checkout -f $branchB |
| 66 | +else |
| 67 | + if [ -z "$srcDirB" ]; then |
| 68 | + echo "Only one directory passed for comparison" |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | + startDir=$PWD |
| 72 | + pushd "$srcDirB" |
| 73 | + export ENV_DIR="$srcDirB/tests/fixtures" |
| 74 | + branchB=$(git rev-parse --abbrev-ref HEAD) |
| 75 | + targetDirB="$startDir/tmp/${branchB}" |
| 76 | + generate_helm_templates "$targetDirB" |
| 77 | + popd |
| 78 | + pushd "$srcDirA" |
| 79 | + export ENV_DIR="$srcDirA/tests/fixtures" |
| 80 | + branchA=$(git rev-parse --abbrev-ref HEAD) |
| 81 | + targetDirA="$startDir/tmp/${branchA}" |
| 82 | + generate_helm_templates "$targetDirA" |
| 83 | + popd |
| 84 | +fi |
48 | 85 |
|
49 | 86 | # order of arguments matters so new changes are green color |
50 | 87 | echo "Comparing $targetDirB with $targetDirA" |
|
0 commit comments