forked from IBM/dbb-git-migration-modeler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Init-Application-Repositories.sh
executable file
·229 lines (196 loc) · 9.16 KB
/
Init-Application-Repositories.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/env bash
#*******************************************************************************
# Licensed Materials - Property of IBM
# (c) Copyright IBM Corporation 2018, 2024. All Rights Reserved.
#
# Note to U.S. Government Users Restricted Rights:
# Use, duplication or disclosure restricted by GSA ADP Schedule
# Contract with IBM Corp.
#*******************************************************************************
Prolog() {
echo " "
echo " DBB Git Migration Modeler "
echo " Release: $MigrationModelerRelease "
echo " "
echo " Script: InitApplicationRepositories.sh "
echo " "
echo " Description: The purpose of this script is to initialize the Git repositories, by adding a default "
echo " .gitattributes file. It additionally performs build preview that generates and initial "
echo " DBB Build Report that can be examined by the application team. "
echo " "
echo " For more information please refer to: https://github.com/IBM/dbb-git-migration-modeler "
echo " "
}
# Read Migration Modeler Configuration
dir=$(dirname "$0")
. $dir/utils/0-environment.sh "$@"
# Internal variables
DBB_GIT_MIGRATION_MODELER_CONFIG_FILE=
rc=0
Prolog
if [ "$DBB_HOME" = "" ]; then
echo "[ERROR] Environment variable DBB_HOME is not set. Exiting."
else
if [ ! -d "$DBB_MODELER_APPLICATION_DIR" ]; then
echo "[ERROR] The folder indicated by the 'DBB_MODELER_APPLICATION_DIR' variable does not exist. Exiting."
exit 1
fi
echo
echo "[PHASE] Initialize Git repositories"
read -p "Do you want to initialize the Git repositories for the applications in '$DBB_MODELER_APPLICATION_DIR' (Y/n): " variable
if [[ -z "$variable" || $variable =~ ^[Yy]$ ]]; then
# Initialize Repositories
cd $DBB_MODELER_APPLICATION_DIR
for applicationDir in $(ls | grep -v dbb-zappbuild); do
if [ $rc -eq 0 ]; then
echo
cd $DBB_MODELER_APPLICATION_DIR/$applicationDir
touch $DBB_MODELER_LOGS/Init-Application-Repositories.log
chtag -tc IBM-1047 $DBB_MODELER_LOGS/Init-Application-Repositories.log
if [ $(git rev-parse --is-inside-work-tree 2>/dev/null | wc -l) -eq 1 ]; then
echo "[INFO] '$DBB_MODELER_APPLICATION_DIR/$applicationDir' is already a Git repository"
else
echo "[INFO] Initialize Git repository for application '$applicationDir'"
CMD="git init --initial-branch=main"
echo "[CMD] ${CMD}" >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
$CMD >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
rc=$?
# tag application descriptor file
if [ $rc -eq 0 ]; then
if [ -f "${applicationDir}.yaml" ]; then
echo "[INFO] Set file tag for '$applicationDir.yaml'"
CMD="chtag -c IBM-1047 -t $applicationDir.yaml"
echo "[CMD] ${CMD}" >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
$CMD >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
rc=$?
fi
fi
# tag .gitattributes file
if [ $rc -eq 0 ]; then
echo "[INFO] Update Git configuration files '.gitattributes'"
if [ -f ".gitattributes" ]; then
CMD="rm .gitattributes"
echo "[CMD] ${CMD}" >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
$CMD >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
rc=$?
fi
CMD="cp $DBB_MODELER_DEFAULT_GIT_CONFIG/.gitattributes .gitattributes"
echo "[CMD] ${CMD}" >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
$CMD >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
rc=$?
fi
# Git list all changes
if [ $rc -eq 0 ]; then
echo "[INFO] Prepare initial commit"
CMD="git status"
echo "[CMD] ${CMD}" >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
$CMD >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
rc=$?
fi
# Git add all changes
if [ $rc -eq 0 ]; then
CMD="git add --all"
echo "[CMD] ${CMD}" >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
$CMD >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
rc=$?
fi
# Git commit changes
if [ $rc -eq 0 ]; then
echo "[INFO] Commit files to new Git repository"
CMD="git commit -m 'Initial Commit'"
echo "[CMD] ${CMD}" >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
git commit -m 'Initial Commit' >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
rc=$?
fi
# Git commit changes
if [ $rc -eq 0 ]; then
CMD="git tag rel-1.0.0"
echo "[CMD] ${CMD}" >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
$CMD >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
rc=$?
fi
if [ $rc -eq 0 ]; then
echo "[INFO] Initializing Git repository for application '$applicationDir' completed. rc="$rc
else
echo "[ERROR] Initializing Git repository for application '$applicationDir' failed. rc="$rc
fi
fi
fi
done
fi
if [ $rc -eq 0 ]; then
echo
echo "[PHASE] Run preview builds for applications"
read -p "Do you want to run preview builds for the applications in $DBB_MODELER_APPLICATION_DIR (Y/n): " variable
if [[ -z "$variable" || $variable =~ ^[Yy]$ ]]; then
# Run zAppBuild to generate baselines
cd $DBB_MODELER_APPLICATION_DIR
for applicationDir in $(ls | grep -v dbb-zappbuild); do
if [ $rc -eq 0 ]; then
echo
echo "[INFO] Build of application '$applicationDir' started"
# mkdir application log directory
mkdir -p $DBB_MODELER_LOGS/$applicationDir
CMD="$DBB_HOME/bin/groovyz $DBB_ZAPPBUILD/build.groovy \
--workspace $DBB_MODELER_APPLICATION_DIR/$applicationDir \
--application $applicationDir \
--outDir $DBB_MODELER_LOGS/$applicationDir \
--fullBuild \
--hlq DBEHM.DBB.MIG --preview \
--logEncoding UTF-8 \
--applicationCurrentBranch main \
--propOverwrites createBuildOutputSubfolder=false \
--propFiles /var/dbb/dbb-zappbuild-config/build.properties,/var/dbb/dbb-zappbuild-config/datasets.properties"
echo "[INFO] $CMD" >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
$CMD > $DBB_MODELER_LOGS/$applicationDir/build-preview-$applicationDir.log
rc=$?
echo "[INFO] Build of application '$applicationDir' completed with rc="$rc
echo "[INFO] Build logs and reports available at '$DBB_MODELER_LOGS/$applicationDir'"
fi
done
if [ $rc -eq 0 ]; then
echo "[INFO] Performing preview builds completed successfully. rc="$rc
else
echo "[ERROR] Performing preview builds completed failed. rc="$rc
fi
if [ $rc -eq 0 ]; then
echo
echo "[PHASE] Create baseline packages for applications"
read -p "Do you want to create the baseline packages for the application in '$DBB_MODELER_APPLICATION_DIR' (Y/n): " variable
if [[ -z "$variable" || $variable =~ ^[Yy]$ ]]; then
# Run zAppBuild to generate baselines
cd $DBB_MODELER_APPLICATION_DIR
if [ ! -d "${DBB_COMMUNITY_REPO}" ]; then
rc=4
ERRMSG="[ERROR] Directory '$DBB_COMMUNITY_REPO' does not exist. rc="$rc
echo $ERRMSG
fi
if [ ! -f "${DBB_COMMUNITY_REPO}/Pipeline/PackageBuildOutputs/PackageBuildOutputs.groovy" ]; then
rc=4
ERRMSG="[ERROR] Packaging Script '${DBB_COMMUNITY_REPO}/Pipeline/PackageBuildOutputs/PackageBuildOutputs.groovy' does not exist. rc="$rc
echo $ERRMSG
fi
for applicationDir in $(ls | grep -v dbb-zappbuild); do
if [ $rc -eq 0 ]; then
echo
echo "[INFO] Packaging of application '$applicationDir' started"
# mkdir application log directory
mkdir -p $DBB_MODELER_LOGS/$applicationDir
CMD="$DBB_HOME/bin/groovyz $DBB_COMMUNITY_REPO/Pipeline/PackageBuildOutputs/PackageBuildOutputs.groovy \
--workDir $DBB_MODELER_LOGS/$applicationDir \
--addExtension \
--branch main \
--version rel-1.0.0 \
--tarFileName $applicationDir-fullBaseline-rel-1.0.0.tar"
echo "[INFO] $CMD" >> $DBB_MODELER_LOGS/Init-Application-Repositories.log
$CMD > $DBB_MODELER_LOGS/$applicationDir/packaging-preview-$applicationDir.log
rc=$?
echo "[INFO] Packaging of application '$applicationDir' completed with rc="$rc
echo "[INFO] Packaging log available at '$DBB_MODELER_LOGS/$applicationDir/packaging-preview-$applicationDir.log'"
fi
done
fi
fi
fi
fi
fi