diff --git a/.github/workflows/update-book.yml b/.github/workflows/update-book.yml index 491caa78e2..49e4203247 100644 --- a/.github/workflows/update-book.yml +++ b/.github/workflows/update-book.yml @@ -71,6 +71,8 @@ jobs: with: bundler-cache: true - name: update book/${{ matrix.language.lang }} + env: + GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # this seems to be needed to let `bundle exec` see `vendor/bundle/` { bundle check || bundle install --frozen; } && @@ -85,6 +87,13 @@ jobs: # commit it all git add -A external/book && + if ${{ inputs.force-rebuild == true && 'git diff-index --exit-code HEAD --' || 'false' }} + then + # Force the bundle to be non-empty + git fetch --depth 2 origin ${{ github.ref_name }} && + git update-ref refs/remotes/origin/${{ github.ref_name }} HEAD^ && + exit 0 + fi && git -c user.name=${{ github.actor }} \ -c user.email=${{ github.actor }}@noreply.github.com \ commit -m 'book: update ${{ matrix.language.lang }}' \ diff --git a/Gemfile b/Gemfile index 3f3e40db8c..980ffe5c19 100644 --- a/Gemfile +++ b/Gemfile @@ -8,3 +8,5 @@ gem "rss" gem "asciidoctor", "~> 2.0.0" gem "nokogiri" gem "diffy" + +gem "base64", "~> 0.2.0" diff --git a/Gemfile.lock b/Gemfile.lock index 76d21e3c1a..15f7a25eb9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,6 +4,7 @@ GEM addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) asciidoctor (2.0.23) + base64 (0.2.0) diffy (3.4.3) faraday (2.12.2) faraday-net_http (>= 2.0, < 3.5) @@ -58,6 +59,7 @@ PLATFORMS DEPENDENCIES asciidoctor (~> 2.0.0) + base64 (~> 0.2.0) diffy faraday-retry nokogiri @@ -67,6 +69,7 @@ DEPENDENCIES CHECKSUMS addressable (2.8.7) sha256=462986537cf3735ab5f3c0f557f14155d778f4b43ea4f485a9deb9c8f7c58232 asciidoctor (2.0.23) sha256=52208807f237dfa0ca29882f8b13d60b820496116ad191cf197ca56f2b7fddf3 + base64 (0.2.0) sha256=0f25e9b21a02a0cc0cea8ef92b2041035d39350946e8789c562b2d1a3da01507 diffy (3.4.3) sha256=4264b9e7db00d1cd426fcd32e36565779163cedc2340a95b0e6f025e71f9aaa7 faraday (2.12.2) sha256=157339c25c7b8bcb739f5cf1207cb0cefe8fa1c65027266bcbc34c90c84b9ad6 faraday-net_http (3.4.0) sha256=a1f1e4cd6a2cf21599c8221595e27582d9936819977bbd4089a601f24c64e54a diff --git a/external/book/content/book/az/v2/_index.html b/external/book/content/book/az/v2/_index.html index 3be6aec5ca..5069bcfb09 100644 --- a/external/book/content/book/az/v2/_index.html +++ b/external/book/content/book/az/v2/_index.html @@ -9,6 +9,8 @@ front_page: true repository_url: https://github.com/progit2-aze/progit2 sha: 9f5e87d19b622e05fd9f7cc215bcd39c79d5995b + ebook_pdf: https://github.com/progit2-aze/progit2/releases/download/2.1.167/progit_v2.1.167.pdf + ebook_epub: https://github.com/progit2-aze/progit2/releases/download/2.1.167/progit_v2.1.167.epub page_title: Git - Book url: "/book/az/v2.html" aliases: diff --git a/external/book/content/book/be/v2/_index.html b/external/book/content/book/be/v2/_index.html index 6e5799cedf..b866ca6cb6 100644 --- a/external/book/content/book/be/v2/_index.html +++ b/external/book/content/book/be/v2/_index.html @@ -9,6 +9,8 @@ front_page: true repository_url: https://github.com/progit/progit2-be sha: 5d7dee94e8f4f56fc28ef927e7435d869cd312ff + ebook_pdf: https://github.com/progit/progit2-be/releases/download/2.1.2/progit.pdf + ebook_epub: https://github.com/progit/progit2-be/releases/download/2.1.2/progit.epub page_title: Git - Book url: "/book/be/v2.html" aliases: diff --git a/external/book/content/book/bg/v2/_index.html b/external/book/content/book/bg/v2/_index.html index 30fbbf0de1..8b21d06b8b 100644 --- a/external/book/content/book/bg/v2/_index.html +++ b/external/book/content/book/bg/v2/_index.html @@ -9,6 +9,9 @@ front_page: true repository_url: https://github.com/progit/progit2-bg sha: bad96055d9e17cb562781652a87df1de93ab2c9b + ebook_pdf: https://github.com/progit/progit2-bg/releases/download/2.1.60/progit.pdf + ebook_epub: https://github.com/progit/progit2-bg/releases/download/2.1.60/progit.epub + ebook_mobi: https://github.com/progit/progit2-bg/releases/download/2.1.60/progit.mobi page_title: Git - Book url: "/book/bg/v2.html" aliases: diff --git a/external/book/content/book/de/v2/_index.html b/external/book/content/book/de/v2/_index.html index d3a994b17b..47593ac8d9 100644 --- a/external/book/content/book/de/v2/_index.html +++ b/external/book/content/book/de/v2/_index.html @@ -9,6 +9,8 @@ front_page: true repository_url: https://github.com/progit/progit2-de sha: c4f0a32f55f41264c4c72aef9800b3bce306486e + ebook_pdf: https://github.com/progit/progit2-de/releases/download/2.1.293/progit.pdf + ebook_epub: https://github.com/progit/progit2-de/releases/download/2.1.293/progit.epub page_title: Git - Book url: "/book/de/v2.html" aliases: diff --git a/external/book/content/book/en/v2/_index.html b/external/book/content/book/en/v2/_index.html index aed93767a8..787090106a 100644 --- a/external/book/content/book/en/v2/_index.html +++ b/external/book/content/book/en/v2/_index.html @@ -11,7 +11,6 @@ sha: 3404a4f5e0c1faab3e89ae93d48663413b31dd8d ebook_pdf: https://github.com/progit/progit2/releases/download/2.1.443/progit.pdf ebook_epub: https://github.com/progit/progit2/releases/download/2.1.443/progit.epub - ebook_mobi: https://github.com/progit/progit2/releases/download/2.1.443/progit.mobi page_title: Git - Book url: "/book/en/v2.html" aliases: diff --git a/external/book/content/book/es/v2/_index.html b/external/book/content/book/es/v2/_index.html index c379f7aea9..a47c77b70e 100644 --- a/external/book/content/book/es/v2/_index.html +++ b/external/book/content/book/es/v2/_index.html @@ -9,6 +9,8 @@ front_page: true repository_url: https://github.com/progit/progit2-es sha: 2264d131f4f6ca028ff4fe88ca60fc8384ee0c3c + ebook_pdf: https://github.com/progit/progit2-es/releases/download/2.1.23/progit.pdf + ebook_epub: https://github.com/progit/progit2-es/releases/download/2.1.23/progit.epub page_title: Git - Book url: "/book/es/v2.html" aliases: diff --git a/external/book/content/book/fr/v2/_index.html b/external/book/content/book/fr/v2/_index.html index 4d67ed8687..b5b58eb7f5 100644 --- a/external/book/content/book/fr/v2/_index.html +++ b/external/book/content/book/fr/v2/_index.html @@ -9,6 +9,8 @@ front_page: true repository_url: https://github.com/progit/progit2-fr sha: be26909d7508e6b2754965e7e5a75d3e44b81dbc + ebook_pdf: https://github.com/progit/progit2-fr/releases/download/2.1.77/progit.pdf + ebook_epub: https://github.com/progit/progit2-fr/releases/download/2.1.77/progit.epub page_title: Git - Book url: "/book/fr/v2.html" aliases: diff --git a/external/book/content/book/gr/v2/_index.html b/external/book/content/book/gr/v2/_index.html index 7608e9c128..4fc12be1be 100644 --- a/external/book/content/book/gr/v2/_index.html +++ b/external/book/content/book/gr/v2/_index.html @@ -9,6 +9,9 @@ front_page: true repository_url: https://github.com/progit2-gr/progit2 sha: bddb5f3e050e3ab66d197eaab033e65a2aa98e03 + ebook_pdf: https://github.com/progit2-gr/progit2/releases/download/2.1.4/progit_v2.1.4.pdf + ebook_epub: https://github.com/progit2-gr/progit2/releases/download/2.1.4/progit_v2.1.4.epub + ebook_mobi: https://github.com/progit2-gr/progit2/releases/download/2.1.4/progit_v2.1.4.mobi page_title: Git - Book url: "/book/gr/v2.html" aliases: diff --git a/external/book/content/book/it/v2/_index.html b/external/book/content/book/it/v2/_index.html index b7508f3844..cc8e3bd11c 100644 --- a/external/book/content/book/it/v2/_index.html +++ b/external/book/content/book/it/v2/_index.html @@ -9,6 +9,8 @@ front_page: true repository_url: https://github.com/progit/progit2-it sha: '08e643e3d7391c7f503a9de7965bf5579fb9f727' + ebook_pdf: https://github.com/progit/progit2-it/releases/download/2.1.4/progit.pdf + ebook_epub: https://github.com/progit/progit2-it/releases/download/2.1.4/progit.epub page_title: Git - Book url: "/book/it/v2.html" aliases: diff --git a/external/book/content/book/ja/v2/_index.html b/external/book/content/book/ja/v2/_index.html index a64692808b..05e33da8d6 100644 --- a/external/book/content/book/ja/v2/_index.html +++ b/external/book/content/book/ja/v2/_index.html @@ -9,6 +9,8 @@ front_page: true repository_url: https://github.com/progit/progit2-ja sha: bfb44c39ca152442e1186b4e2913134bd9a0b1e7 + ebook_pdf: https://github.com/progit/progit2-ja/releases/download/2.1.7/progit.pdf + ebook_epub: https://github.com/progit/progit2-ja/releases/download/2.1.7/progit.epub page_title: Git - Book url: "/book/ja/v2.html" aliases: diff --git a/external/book/content/book/ko/v2/_index.html b/external/book/content/book/ko/v2/_index.html index eeb06e4387..c652271de1 100644 --- a/external/book/content/book/ko/v2/_index.html +++ b/external/book/content/book/ko/v2/_index.html @@ -9,6 +9,8 @@ front_page: true repository_url: https://github.com/progit/progit2-ko sha: '0099163d19b4124ab13135dee7932b2cea6ec09b' + ebook_pdf: https://github.com/progit/progit2-ko/releases/download/2.1.80/progit.pdf + ebook_epub: https://github.com/progit/progit2-ko/releases/download/2.1.80/progit.epub page_title: Git - Book url: "/book/ko/v2.html" aliases: diff --git a/external/book/content/book/nl/v2/_index.html b/external/book/content/book/nl/v2/_index.html index 234d161e73..40012af6e2 100644 --- a/external/book/content/book/nl/v2/_index.html +++ b/external/book/content/book/nl/v2/_index.html @@ -8,7 +8,9 @@ language_code: nl front_page: true repository_url: https://github.com/progit/progit2-nl - sha: a81766ce9c37750b7d13fd6ef9bd5961605d619b + sha: a8d19c00fc6ed2da8cd400004638752ab1d9f735 + ebook_pdf: https://github.com/progit/progit2-nl/releases/download/2.1.117/progit.pdf + ebook_epub: https://github.com/progit/progit2-nl/releases/download/2.1.117/progit.epub page_title: Git - Book url: "/book/nl/v2.html" aliases: diff --git a/external/book/content/book/pl/v2/_index.html b/external/book/content/book/pl/v2/_index.html index cbace7c842..0a38bcc9a5 100644 --- a/external/book/content/book/pl/v2/_index.html +++ b/external/book/content/book/pl/v2/_index.html @@ -9,6 +9,8 @@ front_page: true repository_url: https://github.com/progit2-pl/progit2-pl sha: 3a939c84461d254478a87749d43bed97ada37602 + ebook_pdf: https://github.com/progit2-pl/progit2-pl/releases/download/2.1.1/progit.pdf + ebook_epub: https://github.com/progit2-pl/progit2-pl/releases/download/2.1.1/progit.epub page_title: Git - Book url: "/book/pl/v2.html" aliases: diff --git a/external/book/content/book/pt-br/v2/_index.html b/external/book/content/book/pt-br/v2/_index.html index 1954121886..5988707aaa 100644 --- a/external/book/content/book/pt-br/v2/_index.html +++ b/external/book/content/book/pt-br/v2/_index.html @@ -9,6 +9,8 @@ front_page: true repository_url: https://github.com/progit/progit2-pt-br sha: e30df8c08716f41756134ffb39b25e9fb34909ac + ebook_pdf: https://github.com/progit/progit2-pt-br/releases/download/2.1.48/progit.pdf + ebook_epub: https://github.com/progit/progit2-pt-br/releases/download/2.1.48/progit.epub page_title: Git - Book url: "/book/pt-br/v2.html" aliases: diff --git a/external/book/content/book/ru/v2/_index.html b/external/book/content/book/ru/v2/_index.html index 3070a4eaf2..e4af751181 100644 --- a/external/book/content/book/ru/v2/_index.html +++ b/external/book/content/book/ru/v2/_index.html @@ -9,6 +9,8 @@ front_page: true repository_url: https://github.com/progit/progit2-ru sha: 79a75ed52f39247873bf2d8ffd7ed08706487755 + ebook_pdf: https://github.com/progit/progit2-ru/releases/download/2.1.117/progit.pdf + ebook_epub: https://github.com/progit/progit2-ru/releases/download/2.1.117/progit.epub page_title: Git - Book url: "/book/ru/v2.html" aliases: diff --git a/external/book/content/book/sl/v2/_index.html b/external/book/content/book/sl/v2/_index.html index ba5428b9d1..9ed2484f68 100644 --- a/external/book/content/book/sl/v2/_index.html +++ b/external/book/content/book/sl/v2/_index.html @@ -8,7 +8,9 @@ language_code: sl front_page: true repository_url: https://github.com/progit/progit2-sl - sha: 16dcf83d9eaa6256fd962b6652f30d6b767f40a1 + sha: '096aaf52e250ec1c5a8e47ea147dc79e797ade70' + ebook_pdf: https://github.com/progit/progit2-sl/releases/download/2.1.78/progit.pdf + ebook_epub: https://github.com/progit/progit2-sl/releases/download/2.1.78/progit.epub page_title: Git - Book url: "/book/sl/v2.html" aliases: diff --git a/external/book/content/book/sr/v2/_index.html b/external/book/content/book/sr/v2/_index.html index 323260c62d..f486b421b9 100644 --- a/external/book/content/book/sr/v2/_index.html +++ b/external/book/content/book/sr/v2/_index.html @@ -9,6 +9,8 @@ front_page: true repository_url: https://github.com/progit/progit2-sr sha: d3a3670c50e4cd21c2828333f712b6eacaa7e10f + ebook_pdf: https://github.com/progit/progit2-sr/releases/download/2.1.3/progit.pdf + ebook_epub: https://github.com/progit/progit2-sr/releases/download/2.1.3/progit.epub page_title: Git - Book url: "/book/sr/v2.html" aliases: diff --git a/external/book/content/book/uk/v2/_index.html b/external/book/content/book/uk/v2/_index.html index c66b32a949..c677f6e9f9 100644 --- a/external/book/content/book/uk/v2/_index.html +++ b/external/book/content/book/uk/v2/_index.html @@ -9,6 +9,8 @@ front_page: true repository_url: https://github.com/progit/progit2-uk sha: d6bfd53e83b526f3d497983bfb784f4c832b1f9a + ebook_pdf: https://github.com/progit/progit2-uk/releases/download/2.1.12/progit.pdf + ebook_epub: https://github.com/progit/progit2-uk/releases/download/2.1.12/progit.epub page_title: Git - Book url: "/book/uk/v2.html" aliases: diff --git a/external/book/content/book/zh-tw/v2/_index.html b/external/book/content/book/zh-tw/v2/_index.html index 22338e7dad..f6707d4eaa 100644 --- a/external/book/content/book/zh-tw/v2/_index.html +++ b/external/book/content/book/zh-tw/v2/_index.html @@ -9,6 +9,9 @@ front_page: true repository_url: https://github.com/progit/progit2-zh-tw sha: f0a989f9aaf289c265cf95381b30653a9d04819b + ebook_pdf: https://github.com/progit/progit2-zh-tw/releases/download/2.1.0/progit_v2.1.0.pdf + ebook_epub: https://github.com/progit/progit2-zh-tw/releases/download/2.1.0/progit_v2.1.0.epub + ebook_mobi: https://github.com/progit/progit2-zh-tw/releases/download/2.1.0/progit_v2.1.0.mobi page_title: Git - Book url: "/book/zh-tw/v2.html" aliases: diff --git a/external/book/content/book/zh/v2/_index.html b/external/book/content/book/zh/v2/_index.html index 3cf9c46b3c..4580107461 100644 --- a/external/book/content/book/zh/v2/_index.html +++ b/external/book/content/book/zh/v2/_index.html @@ -9,6 +9,9 @@ front_page: true repository_url: https://github.com/progit/progit2-zh sha: a5267dfdbf4985d6b2bb94b0993007736fa0acbf + ebook_pdf: https://github.com/progit/progit2-zh/releases/download/2.1.73/progit.pdf + ebook_epub: https://github.com/progit/progit2-zh/releases/download/2.1.73/progit.epub + ebook_mobi: https://github.com/progit/progit2-zh/releases/download/2.1.73/progit.mobi page_title: Git - Book url: "/book/zh/v2.html" aliases: diff --git a/external/book/sync/book-nl.sha b/external/book/sync/book-nl.sha index 02e4af88fb..eef1dad2b7 100644 --- a/external/book/sync/book-nl.sha +++ b/external/book/sync/book-nl.sha @@ -1 +1 @@ -a81766ce9c37750b7d13fd6ef9bd5961605d619b +a8d19c00fc6ed2da8cd400004638752ab1d9f735 diff --git a/external/book/sync/book-sl.sha b/external/book/sync/book-sl.sha index ac78c50e62..37c6034046 100644 --- a/external/book/sync/book-sl.sha +++ b/external/book/sync/book-sl.sha @@ -1 +1 @@ -16dcf83d9eaa6256fd962b6652f30d6b767f40a1 +096aaf52e250ec1c5a8e47ea147dc79e797ade70 diff --git a/script/update-book2.rb b/script/update-book2.rb index 7fdea6b5d6..dac42c1e32 100644 --- a/script/update-book2.rb +++ b/script/update-book2.rb @@ -138,7 +138,7 @@ def genbook(language_code, &get_content) xlink = html.scan(/href="1-.*?\.html\#(.*?)"/) xlink&.each do |link| xref = link.first - book.xrefs[xref] = 'redirect-to-en' if !book.xrefs[xref] + book.xrefs[xref] = 'redirect-to-en' if !book.xrefs[xref] begin html.gsub!(/href="1-.*?\.html\##{xref}"/, "href=\"{{< relurl \"#{book_prefix}ch00/#{xref}\" >}}\"") rescue StandardError @@ -155,7 +155,7 @@ def genbook(language_code, &get_content) footnotes.add(xref) next end - book.xrefs[xref] = 'redirect-to-en' if !book.xrefs[xref] + book.xrefs[xref] = 'redirect-to-en' if !book.xrefs[xref] begin html.gsub!(/href="\##{xref}"/, "href=\"{{< relurl \"#{book_prefix}ch00/#{xref}\" >}}\"") rescue StandardError @@ -222,7 +222,7 @@ def genbook(language_code, &get_content) # record all the xrefs sec.search(".//*[@id]").each do |id| id_xref = id.attribute("id").to_s - book.xrefs[id_xref] = csection if !id_xref.start_with?('_footnoteref_') + book.xrefs[id_xref] = csection if !id_xref.start_with?('_footnoteref_') end section += 1 @@ -239,6 +239,24 @@ def genbook(language_code, &get_content) book end +# Update just the download data, based on the latest tag in the repository +def update_downloads(book, repo, octokit) + begin + rel = octokit.latest_release(repo) + get_url = lambda do |name_re| + asset = rel.assets.find { |asset| name_re.match(asset.name) } + asset&.browser_download_url + end + book.ebook_pdf = get_url.call(/\.pdf$/) + book.ebook_epub = get_url.call(/\.epub$/) + book.ebook_mobi = get_url.call(/\.mobi$/) + rescue Octokit::NotFound + book.ebook_pdf = nil + book.ebook_epub = nil + book.ebook_mobi = nil + end +end + # Generate book html directly from remote git repo def remote_genbook2(language_code) @octokit = Octokit::Client.new(access_token: ENV.fetch("GITHUB_API_TOKEN", nil)) @@ -269,20 +287,7 @@ def remote_genbook2(language_code) book.sha = repo_head.sha - begin - rel = @octokit.latest_release(repo) - get_url = lambda do |name_re| - asset = rel.assets.find { |asset| name_re.match(asset.name) } - asset&.browser_download_url - end - book.ebook_pdf = get_url.call(/\.pdf$/) - book.ebook_epub = get_url.call(/\.epub$/) - book.ebook_mobi = get_url.call(/\.mobi$/) - rescue Octokit::NotFound - book.ebook_pdf = nil - book.ebook_epub = nil - book.ebook_mobi = nil - end + update_downloads(book, repo, @octokit) book.save rescue StandardError => e @@ -300,12 +305,16 @@ def local_genbook2(language_code, worktree_path) raise e end book.sha = `git -C "#{worktree_path}" rev-parse HEAD`.chomp - if language_code == 'en' + access_token = ENV.fetch("GITHUB_API_TOKEN", nil) + if access_token && Book.all_books[language_code] + @octokit = Octokit::Client.new(access_token:) + update_downloads(book, Book.all_books[language_code], @octokit) + elsif language_code == 'en' latest_tag = `git -C "#{worktree_path}" for-each-ref --format '%(refname:short)' --sort=-committerdate --count=1 refs/tags/`.chomp if latest_tag.empty? puts "No tag found in #{worktree_path}, trying to fetch tags" 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 - raise "Still no tags in #{worktree_path}?" if latest_tag.empty? + raise "Still no tags in #{worktree_path}?" if latest_tag.empty? end book.ebook_pdf = "https://github.com/progit/progit2/releases/download/#{latest_tag}/progit.pdf" book.ebook_epub = "https://github.com/progit/progit2/releases/download/#{latest_tag}/progit.epub"