Repository navigation
Expand file tree
/
Copy pathmpub
More file actions
executable file
·231 lines (185 loc) · 5.86 KB
/
Copy pathmpub
File metadata and controls
executable file
·231 lines (185 loc) · 5.86 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/env tclsh
#
# MPUB, publish new release and update website
# Copyright (C) Modules Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##########################################################################
proc reportUsage {} {
puts "Usage: $::argv0 \[options\]
Publish new Modules release and update website
Options:
-h, --help Show this help message and exit"
}
proc sgr {sgrcode str} {
return "\033\[${sgrcode}m$str\033\[0m"
}
proc logadd {str} {
if {[info exists ::logfid]} {
puts $::logfid $str
}
}
proc reportInfo {str} {
logadd "--- $str"
puts [sgr 2 $str]
}
proc reportError {str} {
logadd "### ERROR: $str"
puts "[sgr {1;31} ERROR]: $str"
}
proc runcmd {args} {
reportInfo "Running command: $args"
eval exec >@$::logfid $args
}
proc ignoreexp {errmsg expmsg} {
if {[string first $expmsg $errmsg] == -1} {
error $errmsg
}
}
# parse arguments
set hintmsg "\n Try '$argv0 --help' for more information."
if {$argc > 1} {
reportError "Unexpected number of arguments$hintmsg"
exit 1
} elseif {$argc == 1} {
switch -- [lindex $argv 0] {
-h - --help {
reportUsage
exit 0
}
default {
reportError "Invalid option '[lindex $argv 0]'$hintmsg"
exit 1
}
}
}
# surround whole code to catch error and quit properly
if {[catch {
set exitcode 0
set dlurl http://downloads.sourceforge.net/modules
set cwd [pwd]
# define and open log file
set logfile mpub.out
set logfid [open $logfile w]
# get current branch
set relbranch [exec git branch --show-current]
if {[regexp {^(main|v\d+.\d+.x)$} $relbranch]} {
reportInfo "Found branch '$relbranch'"
} else {
error "git branch '$relbranch' is not a valid release branch"
}
# ensure head sit on a tag
set reltag [exec git describe --tags --exact-match]
reportInfo "Found release tag '$reltag'"
if {[regexp {^v(\d+.\d+.\d+(-(alpha|beta))?)$} $reltag match relver]} {
reportInfo "Extract release version number '$relver'"
} else {
error "git tag '$reltag' is not a valid release tag"
}
# get previous version for website update
set prevtag [lindex [exec git tag --list v*] end-1]
reportInfo "Found previous release tag '$prevtag'"
if {[regexp {^v(\d+.\d+.\d+(-(alpha|beta))?)$} $prevtag match prevver]} {
reportInfo "Extract previous release version number '$prevver'"
} else {
error "git tag '$prevtag' is not a valid release tag"
}
# check mrel status
if {[file exists mpub.ok]} {
reportInfo {Found 'mrel' successful state}
} else {
reportError {'mrel' must be run prior 'mpub'}
}
# get name of GitHub remote repository
if {![info exists env(MREL_GITHUB_REMOTE)]} {
puts -nonewline "GitHub remote: "
flush stdout
gets stdin env(MREL_GITHUB_REMOTE)
}
set ghremote $env(MREL_GITHUB_REMOTE)
reportInfo "GitHub remote set to '$ghremote'"
# get name of SourceForge remote repository
if {![info exists env(MREL_SOURCEFORGE_REMOTE)]} {
puts -nonewline "SourceForge remote: "
flush stdout
gets stdin env(MREL_SOURCEFORGE_REMOTE)
}
set sfremote $env(MREL_SOURCEFORGE_REMOTE)
reportInfo "SourceForge remote set to '$sfremote'"
set distgz modules-$relver.tar.gz
set distbz modules-$relver.tar.bz2
set distwin modules-$relver-win.zip
# Phase 1: push to git repositories
# ---------------------------------------------------------
runcmd 2>@$logfid git push $sfremote c-3.2
runcmd 2>@$logfid git push $sfremote $relbranch
runcmd 2>@$logfid git push $sfremote $reltag
runcmd 2>@$logfid git push $ghremote c-3.2
runcmd 2>@$logfid git push $ghremote $relbranch
runcmd 2>@$logfid git push $ghremote $reltag
# Phase 2: publish release dists
# ---------------------------------------------------------
set fid [open mpubbatch w]
puts $fid "cd /home/frs/project/modules/Modules
mkdir modules-$relver
cd modules-$relver
put doc/build/NEWS.txt
put doc/build/MIGRATING.txt
put $distgz
put $distbz
put $distwin"
close $fid
runcmd sftp -o BatchMode=yes -b mpubbatch frs.sourceforge.net
file delete mpubbatch
# Phase 3: verify uploaded dists
# ---------------------------------------------------------
file mkdir dlcheck
cd dlcheck
runcmd 2>@$logfid curl -LJO $dlurl/$distgz
runcmd 2>@$logfid curl -LJO $dlurl/$distbz
runcmd 2>@$logfid curl -LJO $dlurl/$distwin
runcmd md5sum --check ../mpub.ok
file delete $distgz $distbz $distwin
cd ..
file delete dlcheck
# Phase 4: update website
# ---------------------------------------------------------
if {[catch {runcmd make distclean} errmsg]} {
# skip error if things have already been cleaned up
ignoreexp $errmsg {*** Makefile.inc is missing, please run\
'./configure'. Stop.}
}
runcmd 2>@$logfid git checkout gh-pages
# update index.html
set fid [open index.html r]
set index [read $fid]
close $fid
set fid [open index.html w]
puts -nonewline $fid [string map [list modules-$prevver modules-$relver\
"Download ($prevtag)" "Download ($reltag)"] $index]
close $fid
runcmd 2>@$logfid git commit -s -m "release of version $relver" index.html
# upload new page
runcmd 2>@$logfid git push $ghremote gh-pages
runcmd 2>@$logfid git checkout $relbranch
# everything's done, clean file transmitted by mrel
file delete mpub.ok
# exit in error if any occurred
} errmsg]} {
reportError $errmsg
set exitcode 1
}
close $logfid
exit $exitcode
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent syntax=tcl: