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
134
135
136
137
138
139
140
141
142
143
|
#!/usr/bin/ruby
require
'fileutils'
require
'net/smtp'
dir =
ARGV
[
0
]
to_mail =
""
#mail address list
$svn_ser
=
"http://192.168.12.12/svn"
if
to_mail.empty?
puts
"Please Setting Maillist"
Process.exit(
7
)
end
`export
SVN_EDITOR
=
"/bin/vi"
`
usage =<<
EOF
-------------------
./script.rb svn_path
-------------------
EOF
if
dir.
nil
?
puts usage
Process.exit(
1
)
end
if
not
(
File
.directory?(dir))
puts
"It's Not exist Dir"
Process.exit(
2
)
end
Dir
:
:chdir
(dir)
if
not
(
File
.directory?
'.svn'
)
puts
"This Dir is not SVN Working Dir"
Process.exit(
3
)
end
`svn log -v>/tmp/svn_temp_temp`
svn_log =
File
.open(
"/tmp/svn_temp_temp"
,
'r'
)
def
format_srt(sa)
m =
0
str, ok =
""
,
""
sa.
each
{|x|
if
not
(/^---+$/.match(x).
nil
?)
if
/^Commit:Release-\d+\.\d+/.match(str)
and
m ==
1
break
else
ok = ok + str
end
str = x
m =
1
elsif
not
(/^r[
0
-
9
]+\s/.match(x).
nil
?)
tmp_array = x.split(
'|'
)
str = str +
"\nReVersion:%42s\nAuthor:%45s\nDate:%47s\n"
%[tmp_array[
0
].chop,tmp_array[
1
][
1
,
18
].chop,tmp_array[
2
][
1
,
19
]]
elsif
not
(/^\s..[
ADUCMG
]|^Changed\spaths/.match(x).
nil
?)
if
/\/tag\/release-\d+\.|release_notes\.txt/.match(x).
nil
?
str = str + x
else
x =
''
end
elsif
not
(/\s.+\w.*|\w.*/.match(x).
nil
?)
str = str +
"Commit:"
+ x
elsif
not
(/\s.*$/.match(x).
nil
?)
str = str
end
}
return
ok.gsub(/\s*$/,
''
).gsub(/Changed paths/,
'ChangePath'
) +
"\n------------------------------------------------------------------------"
end
def
check_re_no()
re_no =
""
File
.open(
"release_notes.txt"
,
'r'
).
each
{ |x|
if
/Release-/.match(x)
re_no = x
break
end
}
return
re_no.split(
'-'
)[
1
].to_f
end
def
rel_title(re_no)
re_module =
Dir
.pwd.split(
'/'
)[-
1
]
release_no = <<
EOF
////////////////////////////////////////////////////////////////////////
Module
:
#{re_module} Release-#{re_no}
////////////////////////////////////////////////////////////////////////
EOF
return
release_no
end
def
tag(dir,log,project)
copy_www =
$svn_ser
+
"/"
+ project + dir.split(project)[-
1
]
#$svn_ser + / + TD1T + /Code/RTL
tag_www =
$svn_ser
+
"/"
+ project +
"/Tag"
+ dir.split(project)[-
1
]
#$svn_ser + / + TD1T + /Tag + /Code/RTL
if
File
.exist?(
"release_notes.txt"
)
#exist
dir_no = check_re_no +
1
log = rel_title(dir_no.to_s) +
"\n\n"
+log
writefile(log)
`svn ci release_notes.txt -m
"Release-"
#{dir_no.to_s}`
`svn copy
#{copy_www} #{tag_www + "/release-" + dir_no.to_s } -m "Release-"#{dir_no.to_s}`
return
dir_no
else
log = rel_title(
'1.0'
) +
"\n\n"
+log
writefile(log)
`svn ci release_notes.txt -m
"Release-1.0"
`
`cd
#{dir.split(project)[0] + project} && svn mkdir --parents #{"./Tag" + dir.split(project)[1]} && svn ci #{dir.split(project)[0] + project + "/Tag"} -m "add tag path"`
`svn copy
#{copy_www} #{tag_www + "/release-1.0"} -m "Release-1.0"`
return
"1.0"
end
end
def
mailer(mailadd,re_no,svn_name)
re_no =
"Release:% 31s"
%re_no
re_module =
"Module:% 33s"
%
Dir
.pwd.split(
'/'
)[-
1
]
re_user =
"Author:% 34s"
% `cd
$HOME
&& grep username -h -
A2
./.subversion/auth/svn.simple/* | tail -
1
`
project =
"Project:% 33s"
% svn_name
path =
"Path:% 36s"
%
Dir
.pwd.split(svn_name)[
1
]
File
.open(mailadd,
'r'
).
each
{|dst|
msgstr = <<
END_OF_MESSAGE
From:
SVN
<sync.svn
@163
.com>
To:
#{dst.chomp}
Subject: SVN_Release
#{project.chomp}
#{re_no.chomp}
#{re_module.chomp}
#{re_user.chomp}
#{path}
END_OF_MESSAGE
acct =
'svn@163.com'
domain =
"163.com"
pass =
'1q1123452'
Net::
SMTP
.start(
'smtp.163.com'
,
25
, domain, acct, pass,
:login
) { |smtp|
smtp.send_message msgstr,
'svn@163.com'
,dst.chomp
}
#Net::SMTP.start(server, port, domain, acct, passwd, authtype)
}
end
def
writefile(str)
aFile =
File
.
new
(
"release_notes.txt"
,
"w"
)
aFile.puts str
aFile.close
end
def
svn_project_name()
name =
''
File
.open(
Dir
.pwd +
"/.svn/all-wcprops"
,
'r'
).
each
{ |x|
if
/!svn\/ver\/\d+/.match(x)
name = x
break
end
}
return
name.split(
'/'
)[
2
]
end
svn_name = svn_project_name
re_no = tag(
Dir
.pwd,format_srt(svn_log),svn_name)
mailer(to_mail,re_no,svn_name)
puts
"Release-#{re_no} Success"
`rm -f /tmp/svn_temp_temp`
|
本文转自 nonono11 51CTO博客,原文链接:http://blog.51cto.com/abian/1338362,如需转载请自行联系原作者