Skip to content

Skip doc generation if no plugin version up. #72

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

Merged
merged 3 commits into from
Apr 1, 2022
Merged
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
22 changes: 22 additions & 0 deletions plugindocs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PluginDocs < Clamp::Command
option "--main", :flag, "Fetch the plugin's docs from main instead of the version found in PLUGINS_JSON", :default => false
option "--settings", "SETTINGS_YAML", "Path to the settings file.", :default => File.join(File.dirname(__FILE__), "settings.yml"), :attribute_name => :settings_path
option("--parallelism", "NUMBER", "for performance", default: 4) { |v| Integer(v) }
option "--skip-existing", :flag, "Don't generate documentation if asciidoc file exists"

parameter "PLUGINS_JSON", "The path to the file containing plugin versions json"

Expand Down Expand Up @@ -73,6 +74,15 @@ def execute
injection_variables[:default_plugin] = (is_default_plugin ? 1 : 0)
content = inject_variables(content, injection_variables)

# Even if no version bump, sometimes generating content might be different.
# For this case, we skip to accept the changes.
# eg: https://github.com/elastic/logstash-docs/pull/983/commits
if skip_existing? && File.exist?(output_asciidoc) \
&& no_version_bump?(output_asciidoc, content)
$stderr.puts("#{plugin.desc}: skipping since no version bump and doc exists.\n")
next
end

# write the doc
File.write(output_asciidoc, content)
puts "#{plugin.canonical_name}@#{plugin.tag}: #{release_date}\n"
Expand Down Expand Up @@ -119,6 +129,18 @@ def github_source_from_gem_data(gem_name, gem_data)
def tag(version)
version ? "v#{version}" : "main"
end

##
# Checks if no version bump and return true if so, false otherwise.
#
# @param output_asciidoc [String]
# @param content [String]
# @return [Boolean]
def no_version_bump?(output_asciidoc, content)
existing_file_content = File.read(output_asciidoc)
version_fetch_regex = /^\:version: (.*?)\n/
existing_file_content[version_fetch_regex, 1] == content[version_fetch_regex, 1]
end
end

if __FILE__ == $0
Expand Down