File: postversion.rb

package info (click to toggle)
ruby-asciidoctor-pdf 2.3.19-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,972 kB
  • sloc: ruby: 44,316; sh: 133; java: 45; makefile: 4
file content (30 lines) | stat: -rw-r--r-- 994 bytes parent folder | download | duplicates (5)
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
# frozen_string_literal: true

release_version = ENV['RELEASE_VERSION']
major_minor_version = ((release_version.split '.').slice 0, 2).join '.'
prerelease = (release_version.count '[a-z]') > 0 ? %(.#{(release_version.split '.', 3)[-1]}) : nil

changelog_file = 'CHANGELOG.adoc'
antora_file = 'docs/antora.yml'

changelog_contents = File.readlines changelog_file, mode: 'r:UTF-8'
last_release_idx = changelog_contents.index {|l| (l.start_with? '== ') && (%r/^== \d/.match? l) }
changelog_contents.insert last_release_idx, <<~END
== Unreleased

_No changes since previous release._

END

antora_contents = (File.readlines antora_file, mode: 'r:UTF-8').map do |l|
  if l.start_with? 'prerelease: '
    %(prerelease: #{prerelease ? ?' + prerelease + ?' : 'false'}\n)
  elsif l.start_with? 'version: '
    %(version: '#{major_minor_version}'\n)
  else
    l
  end
end

File.write changelog_file, changelog_contents.join, mode: 'w:UTF-8'
File.write antora_file, antora_contents.join, mode: 'w:UTF-8'