Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
ee53b739
Commit
ee53b739
authored
Dec 13, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/minor_update_script' of /home/git/repositories/gitlab/gitlabhq
parents
b1eb3d46
c638ef33
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
124 additions
and
0 deletions
+124
-0
lib/gitlab/upgrader.rb
lib/gitlab/upgrader.rb
+97
-0
script/upgrade.rb
script/upgrade.rb
+3
-0
spec/lib/gitlab/upgrader_spec.rb
spec/lib/gitlab/upgrader_spec.rb
+24
-0
No files found.
lib/gitlab/upgrader.rb
0 → 100644
View file @
ee53b739
require
"colored"
require_relative
"version_info"
module
Gitlab
class
Upgrader
def
execute
puts
"GitLab
#{
current_version
.
major
}
upgrade tool"
.
yellow
puts
"Your version is
#{
current_version
}
"
puts
"Latest available version for GitLab
#{
current_version
.
major
}
is
#{
latest_version
}
"
if
latest_version?
puts
"You use latest GitLab version"
else
puts
"Newer GitLab version is available"
answer
=
if
ARGV
.
first
==
"-y"
"yes"
else
prompt
(
"Do you want to upgrade (yes/no)? "
.
blue
,
%w{yes no}
)
end
if
answer
==
"yes"
upgrade
else
exit
0
end
end
end
def
latest_version?
current_version
>=
latest_version
end
def
current_version
@current_version
||=
Gitlab
::
VersionInfo
.
parse
(
current_version_raw
)
end
def
latest_version
@latest_version
||=
Gitlab
::
VersionInfo
.
parse
(
latest_version_raw
)
end
def
current_version_raw
File
.
read
(
File
.
join
(
gitlab_path
,
"VERSION"
)).
strip
end
def
latest_version_raw
git_tags
=
`git ls-remote --tags origin | grep tags
\/
v
#{
current_version
.
major
}
`
git_tags
=
git_tags
.
lines
.
to_a
.
select
{
|
version
|
version
=~
/v\d\.\d\.\d\Z/
}
last_tag
=
git_tags
.
last
.
match
(
/v\d\.\d\.\d/
).
to_s
end
def
update_commands
{
"Stash changed files"
=>
"git stash"
,
"Get latest code"
=>
"git fetch"
,
"Switch to new version"
=>
"git checkout -b v
#{
latest_version
}
"
,
"Install gems"
=>
"bundle"
,
"Migrate DB"
=>
"bundle exec rake db:migrate RAILS_ENV=production"
,
"Recompile assets"
=>
"bundle exec rake assets:clean assets:precompile RAILS_ENV=production"
,
"Clear cache"
=>
"bundle exec rake cache:clear RAILS_ENV=production"
}
end
def
upgrade
update_commands
.
each
do
|
title
,
cmd
|
puts
title
.
yellow
puts
" ->
#{
cmd
}
"
if
system
(
cmd
)
puts
" -> OK"
.
green
else
puts
" -> FAILED"
.
red
puts
"Failed to upgrade. Try to repeat task or proceed with upgrade manually "
exit
1
end
end
puts
"Done"
end
def
gitlab_path
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'../..'
))
end
# Prompt the user to input something
#
# message - the message to display before input
# choices - array of strings of acceptable answers or nil for any answer
#
# Returns the user's answer
def
prompt
(
message
,
choices
=
nil
)
begin
print
(
message
)
answer
=
STDIN
.
gets
.
chomp
end
while
!
choices
.
include?
(
answer
)
answer
end
end
end
script/upgrade.rb
0 → 100644
View file @
ee53b739
require_relative
"../lib/gitlab/upgrader"
Gitlab
::
Upgrader
.
new
.
execute
spec/lib/gitlab/upgrader_spec.rb
0 → 100644
View file @
ee53b739
require
'spec_helper'
describe
Gitlab
::
Upgrader
do
let
(
:upgrader
)
{
Gitlab
::
Upgrader
.
new
}
let
(
:current_version
)
{
Gitlab
::
VERSION
}
describe
'current_version_raw'
do
it
{
upgrader
.
current_version_raw
.
should
==
current_version
}
end
describe
'latest_version?'
do
it
'should be true if newest version'
do
upgrader
.
stub
(
latest_version_raw:
current_version
)
upgrader
.
latest_version?
.
should
be_true
end
end
describe
'latest_version_raw'
do
it
'should be latest version for GitLab 5'
do
upgrader
.
stub
(
current_version_raw:
"5.3.0"
)
upgrader
.
latest_version_raw
.
should
==
"v5.4.2"
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment