Skip to content

Commit dc1e242

Browse files
committed
HV-648 ruby script for SourceForge and JBoss doc server uploads
1 parent 9f027e7 commit dc1e242

File tree

8 files changed

+324
-0
lines changed

8 files changed

+324
-0
lines changed

distribution/src/main/assembly/dist.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<formats>
2222
<format>tar.gz</format>
2323
<format>zip</format>
24+
<format>dir</format>
2425
</formats>
2526

2627
<!-- Configure the artifacts to include -->

distribution/src/scripts/Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source "http://rubygems.org"
2+
3+
gem "choice"
4+
gem "net-sftp"
5+
gem "nokogiri"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
GEM
2+
remote: http://rubygems.org/
3+
specs:
4+
choice (0.1.6)
5+
net-sftp (2.1.1)
6+
net-ssh (>= 2.6.5)
7+
net-ssh (2.6.5)
8+
nokogiri (1.5.6)
9+
10+
PLATFORMS
11+
ruby
12+
13+
DEPENDENCIES
14+
choice
15+
net-sftp
16+
nokogiri

distribution/src/scripts/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Releasing Hibernate Validator
2+
3+
The script in this directory allow you to deploy the release bundles for a Hibernate Validator release
4+
on SourceForge. It also can sync the
5+
6+
## Prerequisites
7+
8+
* ssh key-based authentication to Sourceforge and JBoss docs server
9+
* Ruby >= 1.9
10+
* Bundler
11+
12+
#install bundler
13+
> gem install bundler
14+
15+
# install ruby dependencies (gems) via bundler
16+
> bundle install
17+
18+
## How to run the script
19+
20+
> ./release.rb -s <sourceforge-user>
21+
22+
## Tips & Tricks
23+
24+
* To list all available script options use '-h'
25+
26+
> ./release.rb -h
27+
28+
## Resources
29+
30+
* [Bundler](http://gembundler.com/)
31+
* [SourceForge sftp](https://sourceforge.net/apps/trac/sourceforge/wiki/SFTP)
32+
* [SourceForge ssh]()
33+
34+
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
class ArtifactProvider
2+
3+
def initialize(bundle_name, base_dir)
4+
@base_bundle_name = bundle_name
5+
@module_dir = base_dir
6+
@target_dir = @module_dir + "/target"
7+
@release_version = getPomVersion()
8+
@sourceForgeArtifacts = prepareSourceForgeArtifacts()
9+
@docs_directory = prepareDocsDirectory()
10+
11+
puts ""
12+
puts "Releasing " + @base_bundle_name + " version " + @release_version
13+
puts ""
14+
puts " The following SourceForge artifacts will be uploaded:"
15+
@sourceForgeArtifacts.each { |x| puts " * " + x }
16+
puts ""
17+
puts " The following directory will be synced to JBoss Docs server:"
18+
puts " * " + @docs_directory
19+
puts ""
20+
puts " Continue [y/N]"
21+
continueRelease = $stdin.gets
22+
continueRelease.chomp!
23+
abort("Aborting release process") unless continueRelease == "y"
24+
end
25+
26+
def getReleaseVersion
27+
return @release_version
28+
end
29+
30+
def getSourceForgeArtifacts()
31+
return @sourceForgeArtifacts
32+
end
33+
34+
def getDocsDirectory()
35+
return @docs_directory
36+
end
37+
38+
private
39+
40+
def prepareDocsDirectory()
41+
docs_dir = getBundlePath(@target_dir, @base_bundle_name, @release_version, :dir)
42+
docs_dir << "/"<< @base_bundle_name << "-" << @release_version << "/docs"
43+
44+
abort("Docs directory " + docs_dir + " cannot be found.") unless File.exist?(docs_dir)
45+
return docs_dir
46+
end
47+
48+
def prepareSourceForgeArtifacts()
49+
readme = @module_dir + "/../README.md"
50+
abort(readme + " cannot be found. List of SourceForge artifacts not complete.") unless File.exist?(readme)
51+
52+
changelog = @module_dir + "/../changelog.txt"
53+
abort(changelog + " cannot be found. List of SourceForge artifacts not complete.") unless File.exist?(changelog)
54+
55+
tar_bundle = getBundlePath(@target_dir, @base_bundle_name, @release_version, :tar)
56+
abort("tar bundle '" + tar_bundle + "' cannot be found. List of SourceForge artifacts not complete.") unless File.exist?(tar_bundle)
57+
58+
zip_bundle = getBundlePath(@target_dir, @base_bundle_name, @release_version, :zip)
59+
abort("zip bundle '" + zip_bundle + "' cannot be found. List of SourceForge artifacts not complete.") unless File.exist?(zip_bundle)
60+
61+
return [readme, changelog, tar_bundle, zip_bundle]
62+
end
63+
64+
def getPomVersion()
65+
pom = @module_dir + "/pom.xml"
66+
if(!File.file?( pom ))
67+
abort("Unable to locate pom file")
68+
end
69+
70+
f = File.open(pom)
71+
doc = Nokogiri::XML(f)
72+
f.close
73+
doc.remove_namespaces!
74+
75+
if(!(/hibernate-validator-distribution/ =~ doc.xpath('//artifactId').text))
76+
abort("Script is not run from the distribution directory")
77+
end
78+
79+
return doc.xpath('//parent/version').text
80+
end
81+
82+
def getBundlePath(target_dir, project, version, type)
83+
bundle_name = target_dir + "/" + project + "-" + version + "-dist"
84+
if(type == :tar)
85+
bundle_name << ".tar.gz"
86+
elsif (type == :zip)
87+
bundle_name << ".zip"
88+
elsif (type == :dir)
89+
else
90+
abort("Wrong bundle type: '" + type + "'")
91+
end
92+
return bundle_name
93+
end
94+
end
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
class JBossDocsUploader
2+
3+
def initialize(local_docs_dir, release_version)
4+
@docs = local_docs_dir
5+
@version = release_version[0..2]
6+
@base_dir = "/docs_htdocs/hibernate/validator"
7+
@remote = @base_dir + "/" + @version
8+
9+
puts " Docs upload to " + @remote
10+
puts " Continue [y/N]"
11+
continueRelease = $stdin.gets
12+
continueRelease.chomp!
13+
abort("Aborting release process") unless continueRelease == "y"
14+
end
15+
16+
def put
17+
user = "hibernate"
18+
host = "filemgmt.jboss.org"
19+
20+
Net::SFTP.start(host, user) do |sftp|
21+
puts "Preparing to upload docs from: " + @docs
22+
begin
23+
sftp.stat!(@remote)
24+
puts "Deleting existing remote path: " + @remote
25+
recursive_delete(sftp, @remote)
26+
rescue Net::SFTP::StatusException => e
27+
raise unless e.code == 2
28+
puts "Creating remote path: " + @remote
29+
sftp.mkdir!(@remote)
30+
end
31+
puts "Uploading docs"
32+
sftp.upload!(@docs, @remote) do |event, uploader, *args|
33+
case event
34+
when :open then
35+
# args[0] : file metadata
36+
puts "starting upload: #{args[0].local} -> #{args[0].remote} (#{args[0].size} bytes}"
37+
when :put then
38+
# args[0] : file metadata
39+
# args[1] : byte offset in remote file
40+
# args[2] : data being written (as string)
41+
puts "writing #{args[2].length} bytes to #{args[0].remote} starting at #{args[1]}"
42+
when :close then
43+
# args[0] : file metadata
44+
puts "finished with #{args[0].remote}"
45+
when :finish then
46+
puts ""
47+
puts ""
48+
end
49+
end
50+
puts "Docs upload complete"
51+
end
52+
end
53+
54+
private
55+
56+
def recursive_delete(sftp, dir)
57+
handle = sftp.opendir!(dir)
58+
59+
while (items = sftp.readdir!(handle)) do
60+
items.each { |item|
61+
full_path = dir + "/" + item.name
62+
if item.directory?
63+
if item.name != '.' && item.name != '..'
64+
recursive_delete(sftp, full_path)
65+
sftp.rmdir!(full_path)
66+
end
67+
else
68+
sftp.remove!(full_path)
69+
end
70+
}
71+
end
72+
sftp.close(handle)
73+
end
74+
end
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env ruby
2+
# encoding: UTF-8
3+
4+
require "rubygems"
5+
require "bundler/setup"
6+
7+
require 'choice'
8+
require 'nokogiri'
9+
require 'net/sftp'
10+
11+
require_relative 'artifact_provider'
12+
require_relative 'source_forge_uploader'
13+
require_relative 'jboss_docs_uploader'
14+
15+
Choice.options do
16+
header 'Application options:'
17+
18+
separator 'Required:'
19+
20+
option :sourceforge_user, :required => true do
21+
short '-s'
22+
long '--sourceforge-user=<user>'
23+
desc 'The SourceForge user name'
24+
end
25+
26+
separator 'Common:'
27+
28+
option :help do
29+
short '-h'
30+
long '--help'
31+
desc 'Show this message.'
32+
end
33+
end
34+
35+
artifactProvider = ArtifactProvider.new("hibernate-validator", "../..")
36+
37+
# Upload to SourceForge
38+
sourceForgeUploader = SourceForgeUploader.new( artifactProvider.getSourceForgeArtifacts, Choice.choices.sourceforge_user, artifactProvider.getReleaseVersion )
39+
sourceForgeUploader.put
40+
41+
# Upload to JBoss Docs server
42+
jbossUploader = JBossDocsUploader.new( artifactProvider.getDocsDirectory, artifactProvider.getReleaseVersion )
43+
jbossUploader.put
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
class SourceForgeUploader
2+
3+
def initialize(upload_artifacts, sourceforge_user, release_version)
4+
@artifacts = upload_artifacts
5+
@user = sourceforge_user
6+
@version = release_version
7+
@base_dir = "/home/frs/project/hibernate/OldFiles/test"
8+
@release_dir = @base_dir + "/" + @version
9+
10+
puts " SourceFroge upload to " + @release_dir
11+
puts " Continue [y/N]"
12+
continueRelease = $stdin.gets
13+
continueRelease.chomp!
14+
abort("Aborting release process") unless continueRelease == "y"
15+
end
16+
17+
def put
18+
# SourceForge
19+
frs_user = @user + ",hibernate"
20+
frs_host = "frs.sourceforge.net"
21+
Net::SFTP.start(frs_host, frs_user) do |sftp|
22+
begin
23+
sftp.stat!(@release_dir)
24+
abort("Remote directory " + @release_dir + " exists")
25+
rescue Net::SFTP::StatusException => e
26+
raise unless e.code == 2
27+
end
28+
29+
sftp.mkdir! @release_dir
30+
31+
@artifacts.each do |artifact|
32+
local = artifact
33+
remote = @release_dir + "/" + File.basename(local)
34+
puts "Uploading " + File.basename(local)
35+
sftp.upload!(local, remote)do |event, uploader, *args|
36+
case event
37+
when :open then
38+
# args[0] : file metadata
39+
puts "starting upload: #{args[0].local} -> #{args[0].remote} (#{args[0].size} bytes}"
40+
when :put then
41+
# args[0] : file metadata
42+
# args[1] : byte offset in remote file
43+
# args[2] : data being written (as string)
44+
puts "writing #{args[2].length} bytes to #{args[0].remote} starting at #{args[1]}"
45+
when :close then
46+
# args[0] : file metadata
47+
puts "finished with #{args[0].remote}"
48+
when :finish then
49+
puts ""
50+
puts ""
51+
end
52+
end
53+
end
54+
end
55+
puts "SourceForge upload complete"
56+
end
57+
end

0 commit comments

Comments
 (0)