3 # This is a simple script to automate some of the common checks and
4 # tasks in building a new Debian package of stand. I suggest that you
7 # ./wodewick --changelog <PREVIOUS-VERSION>
9 # where <PREVIOUS-VERSION> was the version before, and add the output
12 # Then run ./wodewick --release or ./wodewick --build
14 # FIXME: add these to the build dependencies:
21 # FIXME: the .deb file check is actually a pain, since after running
22 # build, that check will fail.
26 def git_current_branch
27 `git branch` =~
/\* ([^\n]+)/m
31 def git_diff_from_origin_master
32 unless system("git fetch origin master")
33 raise "'git fetch origin master'"
35 # Now compare our current tree to FETCH_HEAD:
39 def git_tracked_repositories
40 return `git remote`.split("\n")
43 def last_version_in_changelog
44 return `dpkg-parsechangelog | egrep ^Version: | sed 's/^Version: //'`
47 def package_name_in_changelog
48 return `dpkg-parsechangelog | egrep ^Source: | sed 's/^Source: //'`
52 `egrep ^Maintainer: debian/control`.gsub(/^Maintainer
: (.*)\n/,'\1')
58 while (text
.length
> columns
) && (text
.length
> 0)
59 index
= (text
[0...columns
] =~
/\s+(\S*?)$/u
)
61 if columns
< text
.length
67 result
+= text
[0...index
]
68 text
= text
[index
..-1].gsub( /^\s*/um
, '' )
76 def indent_change(text
)
78 lines
= text
.split("\n")
79 lines
.each_index
do |i
|
81 result
+= " * #{lines[i]}\n"
83 result
+= " #{lines[i]}\n"
89 def changes_since(commit
)
90 result
= "#{$package_name} (#{$new_version}) unstable; urgency=low\n\n"
92 lines
= `git log --no-merges #{commit}..HEAD | git-shortlog -e`.split("\n")
94 if line
=~
/^([^ ].*) \(\d+\):$/
97 elsif line
=~
/^\s{6}(.*)/
99 formatted
= indent_change(wrapped
)
102 raise "Failed to parse a line in the log: '#{line}'"
105 result
+ "\n -- #{$maintainer_email} #{`date -R`}\n"
110 Usage: wodewick [OPTION]...
112 -h, --help Display this message and exit
113 -c, --check Run pre-packaging checks
114 -b, --build Run pre-packaging checks and build the Debian package
115 -r, --release Run pre-packaging checks, build the Debian package
116 and release (tag, push tags and upload)
117 -l, --changelog <SINCE>
118 Generate changelog entries since commit <SINCE>
119 in a format suitable for a Debian changelog.
127 $mantainer_email = nil
131 unless system("git --version > /dev/null")
132 raise "Couldn't find git on your $PATH"
135 unless FileTest
.exist
?("debian/rules")
136 raise "Must be run within a Debian package source directory"
139 unless FileTest
.exist
?(".git")
140 raise "This must be the top level of a git repository"
143 current_branch
= git_current_branch
144 unless current_branch
== "master"
145 raise "We're on the branch '#{current_branch}' instead of 'master'"
148 $origin_exists = git_tracked_repositories
.include? "origin"
150 # We only run the difference again origin/master if there's a
151 # tracked repository called 'origin'
154 differences
= git_diff_from_origin_master
155 unless differences
.empty
?
156 raise "There were differences between the working tree and " +
157 "origin/master\nTo see them run: git diff FETCH_HEAD"
162 $new_version = last_version_in_changelog
164 raise "Failed to find latest version from the changelog"
166 $package_name = package_name_in_changelog
168 raise "Failed to find package name from the changelog"
170 $maintainer_email = maintainer_email
171 unless $maintainer_email
172 raise "Failed to find the maintainer's name and email from the control file"
175 # If there's a deb with that version in the parent directory, it's a
176 # fair bet that we've forgotten to update the changelog...
178 debs
= Dir
.glob("../#{$package_name}_#{$new_version}_*.deb")
180 message
= "The following package files were found:\n "
181 message
+= debs
.join("\n ")
182 message
+= "\nDid you forget to update debian/changelog ?"
190 unless system("dpkg-buildpackage","-rfakeroot")
191 raise "Building the package failed"
200 unless system("git tag -s version-#{$new_version}")
201 raise "Failed to tag this commit as version-#{$new_version}"
204 # And optionally push those tags:
207 unless system("git push --tags")
208 raise "Failed to push tags to the origin"
212 open("last-released-version","w") do |f
|
220 options
= GetoptLong
.new(
221 [ "--help", "-h", GetoptLong
::NO_ARGUMENT ],
222 [ "--check", "-c", GetoptLong
::NO_ARGUMENT ],
223 [ "--build", "-b", GetoptLong
::NO_ARGUMENT ],
224 [ "--release", "-r", GetoptLong
::NO_ARGUMENT ],
225 [ "--changelog", "-l", GetoptLong
::REQUIRED_ARGUMENT ]
231 release_option
= false
232 changelog_option
= nil
234 options
.each
do |opt
,arg
|
243 release_option
= true
245 changelog_option
= arg
249 unless (help_option
or check_option
or build_option
or release_option
or changelog_option
)
250 raise "You must specify an option"
253 # --release subsumes --build, which subsumes --check:
257 elsif changelog_option
259 s
= changes_since(changelog_option
)
272 rescue Exception
=> e