Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change table rake task to update README.md #111

Merged
merged 1 commit into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ for file in facts/*/centos-*.facts; do cat $file | sed -e 's/CentOS/Scientific/'
for file in facts/*/centos-*.facts; do cat $file | sed -e 's/CentOS/OracleLinux/' > $(echo $file | sed 's/centos/oraclelinux/'); done
```

Then update array `Facter version and Operating System coverage` with output of rake task `table`.
Then update the table in this README by running `bundle exec rake table`

## Supplying custom external facts

Expand Down
14 changes: 11 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,22 @@ task :table do
# Extract the OS list
os_versions = os_facter_matrix.keys.uniq.sort

readme_path = File.expand_path(File.join(__dir__, 'README.md'))
readme = File.read(readme_path).split("\n")
new_readme = readme[0..readme.index { |r| r.start_with?('| ') } - 1]

# Write out a nice table
os_version_width = (os_versions.map{|x| x.size } + [17]).max
puts "| #{'operating system'.center(os_version_width)} |#{facter_versions.map{|x| " #{x} |" }.join}"
puts "| #{'-' * (os_version_width)} |#{facter_versions.map{|x| " --- |" }.join}"
new_readme << "| #{'operating system'.center(os_version_width)} |#{facter_versions.map{|x| " #{x} |" }.join}"
new_readme << "| #{'-' * (os_version_width)} |#{facter_versions.map{|x| " --- |" }.join}"
os_versions.each do |label|
fvs = facter_versions.map{ |facter_version| os_facter_matrix[label][facter_version] || 0 }
row = "| #{label.ljust(os_version_width)} |"
fvs.each { |fv| row += (fv > 0? " #{fv.to_s.center(3)} |" : " |" ) }
puts row
new_readme << row
end

File.open(readme_path, 'w') do |fd|
fd.puts (new_readme + readme[readme.rindex { |r| r.start_with?('| ') } + 1..-1]).join("\n")
end
end