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

Add new :append_datetime param and fix dates to UTC. #53

Merged
merged 5 commits into from
Mar 13, 2021
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
23 changes: 16 additions & 7 deletions lib/fastlane/plugin/changelog/actions/stamp_changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ def self.run(params)
UI.important("WARNING: No changes in [Unreleased] section to stamp!")
else
section_identifier = params[:section_identifier] unless params[:section_identifier].to_s.empty?
stamp_date = params[:stamp_date]
should_stamp_date = params[:should_stamp_date]
stamp_datetime_format = params[:stamp_datetime_format]
git_tag = params[:git_tag]
placeholder_line = params[:placeholder_line]

stamp(changelog_path, section_identifier, stamp_date, git_tag, placeholder_line)
stamp(changelog_path, section_identifier, should_stamp_date, stamp_datetime_format, git_tag, placeholder_line)
end
end

def self.stamp(changelog_path, section_identifier, stamp_date, git_tag, placeholder_line)
def self.stamp(changelog_path, section_identifier, should_stamp_date, stamp_datetime_format, git_tag, placeholder_line)
# 1. Update [Unreleased] section with given identifier
Actions::UpdateChangelogAction.run(changelog_path: changelog_path,
section_identifier: UNRELEASED_IDENTIFIER,
updated_section_identifier: section_identifier,
append_date: stamp_date,
should_append_date: should_stamp_date,
append_datetime_format: stamp_datetime_format,
excluded_placeholder_line: placeholder_line)

file_content = ""
Expand Down Expand Up @@ -129,10 +131,17 @@ def self.available_options
env_name: "FL_STAMP_CHANGELOG_SECTION_IDENTIFIER",
description: "The unique section identifier to stamp the [Unreleased] section with",
is_string: true),
FastlaneCore::ConfigItem.new(key: :stamp_date,
env_name: "FL_STAMP_CHANGELOG_SECTION_STAMP_DATE",
description: "Specifies whether the current date should be appended to section identifier",
FastlaneCore::ConfigItem.new(key: :should_stamp_date,
env_name: "FL_STAMP_CHANGELOG_SHOULD_STAMP_DATE",
description: "Specifies whether the current date as per the stamp_datetime_format should be stamped to the section identifier",
default_value: true,
is_string: false,
optional: true),
FastlaneCore::ConfigItem.new(key: :stamp_datetime_format,
env_name: "FL_STAMP_CHANGELOG_DATETIME_FORMAT",
description: "The strftime format string to use for the date in the stamped section",
default_value: '%FZ',
is_string: true,
optional: true),
FastlaneCore::ConfigItem.new(key: :git_tag,
env_name: "FL_STAMP_CHANGELOG_GIT_TAG",
Expand Down
22 changes: 17 additions & 5 deletions lib/fastlane/plugin/changelog/actions/update_changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ def self.run(params)
line_old = line.dup
line.sub!(section_name, new_section_identifier)

if params[:append_date]
now = Time.now.strftime("%Y-%m-%d")
should_append_date = params[:should_append_date]

if should_append_date
append_datetime_format = params[:append_datetime_format]

now = Time.now.utc.strftime(append_datetime_format)
ENV["FL_UPDATE_APPEND_DATETIME_VAL"] = now

line.concat(" - " + now)
line.delete!(line_separator) # remove line break, because concatenation adds line break between section identifer & date
line.concat(line_separator) # add line break to the end of the string, in order to start next line on the next line
Expand Down Expand Up @@ -114,12 +120,18 @@ def self.available_options
description: "The updated unique section identifier (without square brackets)",
is_string: true,
optional: true),
FastlaneCore::ConfigItem.new(key: :append_date,
env_name: "FL_UPDATE_CHANGELOG_APPEND_DATE",
description: "Appends the current date in YYYY-MM-DD format after the section identifier",
FastlaneCore::ConfigItem.new(key: :should_append_date,
env_name: "FL_UPDATE_CHANGELOG_SHOULD_APPEND_DATE",
description: "Specifies whether the current date as per the append_datetime_format should be appended to section identifier",
default_value: true,
is_string: false,
optional: true),
FastlaneCore::ConfigItem.new(key: :append_datetime_format,
env_name: "FL_UPDATE_CHANGELOG_APPEND_DATETIME_FORMAT",
description: "The strftime format string to use for the date after the section identifier",
default_value: '%FZ',
is_string: true,
optional: true),
FastlaneCore::ConfigItem.new(key: :excluded_placeholder_line,
env_name: "FL_UPDATE_CHANGELOG_EXCLUDED_PLACEHOLDER_LINE",
description: "Placeholder string to be ignored in updated section",
Expand Down
2 changes: 1 addition & 1 deletion lib/fastlane/plugin/changelog/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Fastlane
module Changelog
VERSION = "0.15.0"
VERSION = "0.15.1"
end
end
37 changes: 30 additions & 7 deletions spec/update_changelog_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
expect(read_result).to eq(post_update_read_result)
end

it 'updates [Unreleased] section identifier without appending date' do
# Update [Unreleased] section identifier with new one
it 'updates [Unreleased] section identifier without appending a date' do
# Update [Unreleased] section identifier with new one - explicitly ask to not use a date.
Fastlane::FastFile.new.parse("lane :test do
update_changelog(changelog_path: '#{changelog_mock_path}',
updated_section_identifier: '#{updated_section_identifier}',
append_date: false)
should_append_date: false)
end").runner.execute(:test)

# Read updated section line
Expand All @@ -80,12 +80,35 @@
expect(modifiedSectionLine).to eq("## [12.34.56]\n")
end

it 'updates [Unreleased] section identifier with appending date' do
# Update [Unreleased] section identifier with new one
it 'updates [Unreleased] section identifier appending a date via the default datetime format' do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect

# Update [Unreleased] section identifier with new one via the default datetime format
Fastlane::FastFile.new.parse("lane :test do
update_changelog(changelog_path: '#{changelog_mock_path}',
updated_section_identifier: '#{updated_section_identifier}')
end").runner.execute(:test)

# Read updated section line
modifiedSectionLine = ""
File.open(changelog_mock_path_hook, "r") do |file|
file.each_line do |line|
if line =~ /\#{2}\s?\[#{updated_section_identifier}\]/
modifiedSectionLine = line
break
end
end
end

# Expect the modified section line to be with current date
now = Time.now.utc.strftime("%FZ")
expect(modifiedSectionLine).to eq("## [12.34.56] - #{now}\n")
end

it 'updates [Unreleased] section identifier appending a date via a user specified datetime format' do
# Update [Unreleased] section identifier with new one via the user specified datetime format
Fastlane::FastFile.new.parse("lane :test do
update_changelog(changelog_path: '#{changelog_mock_path}',
updated_section_identifier: '#{updated_section_identifier}',
append_date: true)
append_datetime_format: '%FT%TZ')
end").runner.execute(:test)

# Read updated section line
Expand All @@ -100,7 +123,7 @@
end

# Expect the modified section line to be with current date
now = Time.now.strftime("%Y-%m-%d")
now = Time.now.utc.strftime("%FT%TZ")
expect(modifiedSectionLine).to eq("## [12.34.56] - #{now}\n")
end
end
Expand Down