-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathupdate-default-gem.sh
executable file
·51 lines (40 loc) · 1.52 KB
/
update-default-gem.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
#!/bin/bash -eu
# This is executed as `sudo -u git /home/git/git.ruby-lang.org/bin/update-default-gem.sh`
# when GitHub ruby/xxx's push webhook is delivered to `cgi-bin/webhook.cgi`.
#
# This supports only updating master branch for now.
# Cancel impact from git hook
unset GIT_DIR
# Cancel impact from LANG=C set by apache2
export LANG=en_US.UTF-8
gem_user="$1"
gem_name="$2"
before="$3"
after="$4"
this_repo="/home/git/git.ruby-lang.org"
ruby_repo="/var/git/ruby.git"
ruby_workdir="/data/git.ruby-lang.org/update-default-gem-${gem_name}"
log_path="/tmp/update-default-gem-${gem_name}.log"
function log() {
echo -e "[$$: $(date "+%Y-%m-%d %H:%M:%S %Z")] $1" >> "$log_path"
}
# Run a given command. If it fails, notify Slack and exits abnormally.
function run() {
echo "+ $@" >> "$log_path"
if ! "$@"; then
"${this_repo}/bin/notify-slack-failed-gem-update.rb" "$log_path" >> "$log_path" 2>&1
log "Failed: $@"
exit 1
fi
}
# Initialize working directory only if missing
if [ ! -d "$ruby_workdir" ]; then
git clone "file://${ruby_repo}" "$ruby_workdir"
fi
log "### start ###"
run git -C "$ruby_workdir" fetch origin master >> "$log_path" 2>&1
run git -C "$ruby_workdir" reset --hard origin/master >> "$log_path" 2>&1
run ruby -C "$ruby_workdir" tool/sync_default_gems.rb "$gem_name" "$before..$after" >> "$log_path" 2>&1
# Pushing ruby_workdir to cgit to make sure all git hooks are performed on sync-ed commits.
SVN_ACCOUNT_NAME=git run git -C "$ruby_workdir" push origin "HEAD:master" >> "$log_path" 2>&1
log "### end ###\n"