Skip to content

Commit 436d817

Browse files
committed
book: also generate the URLs for the downloadable formats of the book
... but do this only for the English version, as the other versions are not available in downloadable formats. As the idea is to run this script in a GitHub workflow on a shallow clone, let's be prepared for the situation where the tip commit of the default branch is _not_ (yet?) tagged and therefore no tag is present in the clone. In this situation, let's just go ahead and fetch all tags, then move along and update the URLs accordingly. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent d12d9cd commit 436d817

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

script/update-book2.rb

+11
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,17 @@ def local_genbook2(language_code, worktree_path)
266266
book = genbook(language_code) do |filename|
267267
File.open(File.join(worktree_path, filename), "r") { |infile| File.read(infile) }
268268
end
269+
if language_code == 'en'
270+
latest_tag = `git -C "#{worktree_path}" for-each-ref --format '%(refname:short)' --sort=-committerdate --count=1 refs/tags/`.chomp
271+
if latest_tag.empty?
272+
puts "No tag found in #{worktree_path}, trying to fetch tags"
273+
latest_tag = `git -C "#{worktree_path}" fetch --tags origin && git -C "#{worktree_path}" for-each-ref --format '%(refname:short)' --sort=-committerdate --count=1 refs/tags/`.chomp
274+
raise "Still no tags in #{worktree_path}?" if latest_tag.empty?
275+
end
276+
book.ebook_pdf = "https://github.com/progit/progit2/releases/download/#{latest_tag}/progit.pdf"
277+
book.ebook_epub = "https://github.com/progit/progit2/releases/download/#{latest_tag}/progit.epub"
278+
book.ebook_mobi = "https://github.com/progit/progit2/releases/download/#{latest_tag}/progit.mobi"
279+
end
269280
book.save
270281
end
271282
end

0 commit comments

Comments
 (0)