Class: Fastlane::Actions::CreateChangelogAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/react_native_release/actions/create_changelog.rb

documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



82
83
84
85
# File 'lib/fastlane/plugin/react_native_release/actions/create_changelog.rb', line 82

def self.authors
  # So no one will ever forget your contribution to fastlane :) You are awesome btw!
  ["cball"]
end

.available_optionsObject



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fastlane/plugin/react_native_release/actions/create_changelog.rb', line 60

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :title,
                                 env_name: "FL_CREATE_CHANGELOG_TITLE",
                                 description: "What title should we use for the CHANGELOG?",
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :commit_message,
                                 env_name: "FL_CREATE_CHANGELOG_COMMIT_MESSAGE",
                                 description: "What should the commit message be?",
                                 type: String,
                                 default_value: "chore(changelog): Update CHANGELOG [skip ci]")
  ]
end

.descriptionObject



52
53
54
# File 'lib/fastlane/plugin/react_native_release/actions/create_changelog.rb', line 52

def self.description
  "Determines if a release should happen based on conventional commits."
end

.detailsObject



56
57
58
# File 'lib/fastlane/plugin/react_native_release/actions/create_changelog.rb', line 56

def self.details
  "If using conventional commits, only continues to release if there are features / fixes."
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/fastlane/plugin/react_native_release/actions/create_changelog.rb', line 87

def self.is_supported?(platform)
  [:ios, :android].include?(platform)
end

.return_valueObject



74
75
76
# File 'lib/fastlane/plugin/react_native_release/actions/create_changelog.rb', line 74

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fastlane/plugin/react_native_release/actions/create_changelog.rb', line 6

def self.run(params)
  title = params[:title]
  commit_message = params[:commit_message]
  # Determine our local branch name, set the upstream, and pull.
  # We need to pull since another build may have already finished and created a changelog
  local_branch ||= other_action.git_branch.gsub(/origin/, '')
  sh("git branch --set-upstream-to=origin/#{local_branch} #{local_branch}")
  other_action.git_pull 

  # Get release notes since last version
  # This exports a slack and a regular markdown format
  notes = other_action.conventional_changelog(title: title, format: 'slack')
  notesMD = other_action.conventional_changelog(title: title, format: 'markdown')

  # Prepend new Changelog to existing one
  UI.message("pre-pending to CHANGELOG")
  UI.message(notes)
  new_file = '../CHANGELOG.md.new'
  original_file = '../CHANGELOG.md'

  open(new_file, 'w') do |nf|
    notesMD.split("\n").each { |line| nf.puts line }
    nf.puts "\n"
    
    File.foreach(original_file) do |li|
      nf.puts li
    end
  end

  File.delete original_file
  File.rename new_file, original_file

  # Commit it
  other_action.git_commit(
    path: [File.join(Dir.pwd, original_file)],
    message: commit_message,
    skip_git_hooks: true
  )

  { plain: notes, markdown: notesMD }
end