Skip to content

Commit a31af15

Browse files
committed
Make sure every failure is reported to alerts-sync
1 parent 4abd709 commit a31af15

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

bin/update-default-gem.sh

+15-10
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,28 @@ function log() {
2323
echo -e "[$$: $(date "+%Y-%m-%d %H:%M:%S %Z")] $1" >> "$log_path"
2424
}
2525

26+
# Run a given command. If it fails, notify Slack and exits abnormally.
27+
function run() {
28+
if ! "$@"; then
29+
"${this_repo}/bin/notify-slack-failed-gem-update.rb" "$log_path" >> "$log_path" 2>&1
30+
log "Failed: $@"
31+
exit 1
32+
fi
33+
}
34+
2635
# Initialize working directory only if missing
2736
if [ ! -d "$ruby_workdir" ]; then
2837
git clone "file://${ruby_repo}" "$ruby_workdir"
2938
fi
3039

3140
log "### start ###"
3241

33-
git -C "$ruby_workdir" fetch origin master >> "$log_path" 2>&1
34-
git -C "$ruby_workdir" reset --hard origin/master >> "$log_path" 2>&1
42+
run git -C "$ruby_workdir" fetch origin master >> "$log_path" 2>&1
43+
run git -C "$ruby_workdir" reset --hard origin/master >> "$log_path" 2>&1
3544

36-
if ruby -C "$ruby_workdir" tool/sync_default_gems.rb "$gem_name" "$before..$after" >> "$log_path" 2>&1; then
37-
# Pushing ruby_workdir to cgit to make sure all git hooks are performed on sync-ed commits.
38-
if ! SVN_ACCOUNT_NAME=git git -C "$ruby_workdir" push origin "HEAD:master" >> "$log_path" 2>&1; then
39-
log "Failed: git push"
40-
fi
41-
else
42-
"${this_repo}/bin/notify-slack-failed-gem-update.rb" "$log_path" >> "$log_path" 2>&1
43-
fi
45+
run ruby -C "$ruby_workdir" tool/sync_default_gems.rb "$gem_name" "$before..$after" >> "$log_path" 2>&1
46+
47+
# Pushing ruby_workdir to cgit to make sure all git hooks are performed on sync-ed commits.
48+
SVN_ACCOUNT_NAME=git run git -C "$ruby_workdir" push origin "HEAD:master" >> "$log_path" 2>&1
4449

4550
log "### end ###\n"

0 commit comments

Comments
 (0)