Skip to content

Commit 8b8c9f3

Browse files
committed
Use cd_or_die function for mandatory directory changes
Copied from build_all_repos
1 parent 13c43ff commit 8b8c9f3

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/releasing/releaser.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ clean_templates() {
4747

4848
# Commit to template-library-core the removal of obsolete configuration modules
4949
remove_obsolete_components () {
50-
cd "${LIBRARY_CORE_DIR}" || echo_error "Failed to change directory to '$LIBRARY_CORE_DIR'"
50+
cd_or_die "${LIBRARY_CORE_DIR}"
5151
#FIXME: ideally should check that there is only deleted files left
5252
git add -A .
5353
git commit -m 'Remove obsolete components'
@@ -60,12 +60,12 @@ publish_templates() {
6060
echo_info "Publishing Component Templates"
6161
type=$1
6262
tag=$2
63-
cd "configuration-modules-$1" || echo_error "Failed to change directory to 'configuration-modules-$1'"
63+
cd_or_die "configuration-modules-$1"
6464
git checkout "$tag"
6565
mvn-c clean compile
6666
# ugly hack
6767
if [ -d ncm-metaconfig ]; then
68-
cd ncm-metaconfig || echo_error "Failed to change directory to 'ncm-metaconfig'"
68+
cd_or_die ncm-metaconfig
6969
mvn-c clean test
7070
cd ..
7171
fi
@@ -76,7 +76,7 @@ publish_templates() {
7676
cp -r ncm-*/target/pan/components/* "${components_root}"
7777
cp -r ncm-metaconfig/target/pan/metaconfig/* "${metaconfig_root}"
7878
git checkout master
79-
cd "${LIBRARY_CORE_DIR}"
79+
cd_or_die "${LIBRARY_CORE_DIR}"
8080
git add .
8181
git commit -m "Component templates (${type}) for tag ${tag}"
8282
cd ..
@@ -138,7 +138,7 @@ update_version_file() {
138138
release_minor="_1"
139139
fi
140140
version_template=quattor/client/version.pan
141-
cd "$LIBRARY_CORE_DIR" || echo_error "Failed to change directory to '$LIBRARY_CORE_DIR'"
141+
cd_or_die "$LIBRARY_CORE_DIR"
142142

143143
cat > ${version_template} <<EOF
144144
template quattor/client/version;
@@ -156,7 +156,7 @@ EOF
156156
tag_repository() {
157157
repo=$1
158158
tag=$2
159-
cd "$repo" || echo_error "Failed to change directory to '$repo'"
159+
cd_or_die "$repo"
160160
#FIXME: we may want to check that the tag doesn't exist already
161161
git tag -s -m "Release ${tag}" "${tag}"
162162
git push origin --tags HEAD
@@ -166,7 +166,7 @@ tag_repository() {
166166
tag_branches() {
167167
repo=$1
168168
version=$2
169-
cd "$repo" || echo_error "Failed to change directory to '$repo'"
169+
cd_or_die "$repo"
170170
# Ignore remote HEAD symlink and branches marked as obsolete
171171
branches=$(git branch -r | grep -v ' -> ' | egrep -v 'obsolete$' )
172172
for branch in ${branches}
@@ -202,6 +202,12 @@ function exit_usage {
202202
exit 3
203203
}
204204

205+
function cd_or_die {
206+
# Change directory or die trying
207+
cd "$@" || error 2 "Failed to change directory to $*"
208+
return 0
209+
}
210+
205211
# Check that dependencies required to perform a release are available
206212
missing_deps=0
207213
for cmd in {gpg,gpg-agent,git,mvn,createrepo,tar,sed}; do
@@ -251,7 +257,7 @@ if gpg-agent; then
251257
if [[ ! -d "$r" ]]; then
252258
git clone -q "[email protected]:quattor/$r.git"
253259
fi
254-
cd "$r" || echo_error "Failed to change directory to '$r'"
260+
cd_or_die "$r"
255261
git branch -r | grep "$RELEASE" > /dev/null && git checkout -q "quattor-$RELEASE" || git checkout -q master
256262
details="$details\n$r\t$(git branch | grep '^\*')"
257263
cd ..
@@ -266,7 +272,7 @@ if gpg-agent; then
266272
if [[ $prompt == "yes" ]]; then
267273
for r in $REPOS_MVN; do
268274
echo_info "---------------- Releasing $r ----------------"
269-
cd "$r" || echo_error "Failed to change directory to '$r'"
275+
cd_or_die "$r"
270276
mvn-c -q -DautoVersionSubmodules=true -Dgpg.useagent=true -Darguments=-Dgpg.useagent=true -B -D"releaseVersion=$VERSION" clean release:prepare
271277
if [[ $? -gt 0 ]]; then
272278
echo_error "RELEASE FAILURE"
@@ -302,7 +308,7 @@ if gpg-agent; then
302308

303309
echo_success "---------------- YUM repositories complete, tagging git repositories ----------------"
304310

305-
cd "$RELEASE_ROOT/src" || echo_error "Failed to change directory to '$RELEASE_ROOT/src'"
311+
cd_or_die "$RELEASE_ROOT/src"
306312

307313
echo_info "---------------- Updating template-library-core ----------------"
308314
clean_templates

0 commit comments

Comments
 (0)