-
Notifications
You must be signed in to change notification settings - Fork 1
/
autupdate.sh
executable file
·133 lines (104 loc) · 3.7 KB
/
autupdate.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
#!/bin/bash
# Usage:
# GITHUB_TOKEN=my-private-token REPOS_PATH=/home/access-update-scripts/infrastructure WORKSPACE=/workspace ./autupdate.sh
SCRIPT_PATH=$(cd "$(dirname "$0")" ; pwd -P)
REPOS_FILE="${REPOS_PATH:-$SCRIPT_PATH}/projects.yml"
REPOS=$(./repos_wanting_update.rb $REPOS_FILE)
CLONE_LOCATION=${WORKSPACE:-$TMPDIR}
cd $CLONE_LOCATION
mkdir -p $CLONE_LOCATION/.autoupdate
cd $CLONE_LOCATION/.autoupdate
mkdir gem_report
mkdir npm_report
mkdir yarn_report
GEM_SUCCESS_REPORTS_ARRAY=("/dev/null")
NPM_SUCCESS_REPORTS_ARRAY=("/dev/null")
YARN_SUCCESS_REPORTS_ARRAY=("/dev/null")
# Ruby / Rails applications
for item in $REPOS; do
IFS='/' read org repo <<< "$item"
retVal=-1
echo "$org/$repo"
cd $CLONE_LOCATION/.autoupdate
git clone git@github.com:$org/$repo
cd $repo
git fetch origin
git checkout -B update-dependencies
# This allows our default branches to vary across projects
git reset --hard $(git symbolic-ref refs/remotes/origin/HEAD)
if [[ -f '.autoupdate/preupdate' ]]; then
.autoupdate/preupdate
if [ $? -ne 0 ]; then
continue
fi
fi
if [[ -f '.autoupdate/update' ]]; then
.autoupdate/update
else
if test -f '.circleci/config.yml' && grep -q ruby-rails .circleci/config.yml; then
latest=$(circleci orb info sul-dlss/ruby-rails --skip-update-check | grep 'Latest:' | cut -d@ -f2)
sed -i -e "s/sul-dlss\/ruby-rails@.*/sul-dlss\/ruby-rails@$latest/" .circleci/config.yml &&
git add .circleci/config.yml &&
git commit -m "Update CircleCI orb"
fi
if [[ -f 'Gemfile.lock' ]]; then
bundle update > $CLONE_LOCATION/.autoupdate/gem_report/$repo.txt
retVal=$?
git add Gemfile.lock >> $CLONE_LOCATION/.autoupdate/gem_report/$repo.txt &&
git commit -m "Update Ruby dependencies" >> $CLONE_LOCATION/.autoupdate/gem_report/$repo.txt
if [ $retVal -ne 0 ]; then
echo "ERROR UPDATING RUBY ${repo}"
cat $CLONE_LOCATION/.autoupdate/gem_report/$repo.txt
fi
fi
if [[ -f 'yarn.lock' ]]; then
yarn upgrade > $CLONE_LOCATION/.autoupdate/yarn_report/$repo.txt
retVal=$?
git add yarn.lock &&
git commit -m "Update Yarn dependencies"
if [ $retVal -ne 0 ]; then
echo "ERROR UPDATING YARN ${repo}"
cat $CLONE_LOCATION/.autoupdate/yarn_report/$repo.txt
fi
fi
if [[ -f 'package-lock.json' ]]; then
npm update > $CLONE_LOCATION/.autoupdate/npm_report/$repo.txt &&
npm audit fix > $CLONE_LOCATION/.autoupdate/npm_report/$repo.txt
retVal=$?
git add package-lock.json package.json &&
git commit -m "Update NPM dependencies"
if [ $retVal -ne 0 ]; then
echo "ERROR UPDATING NPM ${repo}"
cat $CLONE_LOCATION/.autoupdate/npm_report/$repo.txt
fi
fi
fi
if [[ -f '.autoupdate/postupdate' ]]; then
.autoupdate/postupdate
if [ $? -ne 0 ]; then
continue
fi
fi
if [ $retVal -eq 0 ]; then
git push origin update-dependencies &&
hub pull-request -f -m "Update dependencies"
retVal=$?
if [ $retVal -eq 0 ]; then
if [[ -f 'Gemfile.lock' ]]; then
GEM_SUCCESS_REPORTS_ARRAY+=("$CLONE_LOCATION/.autoupdate/gem_report/$repo.txt")
fi
if [[ -f 'yarn.lock' ]]; then
YARN_SUCCESS_REPORTS_ARRAY+=("$CLONE_LOCATION/.autoupdate/yarn_report/$repo.txt")
fi
if [[ -f 'package-lock.json' ]]; then
NPM_SUCCESS_REPORTS_ARRAY+=("$CLONE_LOCATION/.autoupdate/npm_report/$repo.txt")
fi
else
echo "ERROR PUSHING ${repo}"
fi
fi
echo " ===== "
done
cd $SCRIPT_PATH
./slack_bot.rb "Dependency Updates Shipped!"
./slack_bot.rb "`cat ${GEM_SUCCESS_REPORTS_ARRAY[*]} | grep "(was " | cut -f 2-5 -d " " | sort | uniq`"