Class: Fastlane::Actions::SetChangelogAction

Inherits:
Fastlane::Action show all
Defined in:
lib/fastlane/actions/set_changelog.rb

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, output, return_value, sh, step_text

Class Method Details

.authorsObject



102
103
104
# File 'lib/fastlane/actions/set_changelog.rb', line 102

def self.authors
  ["KrauseFx"]
end

.available_optionsObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/fastlane/actions/set_changelog.rb', line 76

def self.available_options
  user = CredentialsManager::AppfileConfig.try_fetch_value(:itunes_connect_id)
  user ||= CredentialsManager::AppfileConfig.try_fetch_value(:apple_id)

  [
    FastlaneCore::ConfigItem.new(key: :app_identifier,
                               short_option: "-a",
                               env_name: "FASTLANE_APP_IDENTIFIER",
                               description: "The bundle identifier of your app",
                               default_value: CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)),
    FastlaneCore::ConfigItem.new(key: :username,
                               short_option: "-u",
                               env_name: "FASTLANE_USERNAME",
                               description: "Your Apple ID Username",
                               default_value: user),
    FastlaneCore::ConfigItem.new(key: :version,
                                 env_name: "FL_SET_CHANGELOG_VERSION",
                                 description: "The version number to create/update",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :changelog,
                                 env_name: "FL_SET_CHANGELOG_CHANGELOG",
                                 description: "Changelog text that should be uploaded to iTunes Connect",
                                 optional: true)
  ]
end

.descriptionObject



68
69
70
# File 'lib/fastlane/actions/set_changelog.rb', line 68

def self.description
  "Set the changelog for all languages on iTunes Connect"
end

.detailsObject



72
73
74
# File 'lib/fastlane/actions/set_changelog.rb', line 72

def self.details
  "This is useful if you have only one changelog for all languages"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/fastlane/actions/set_changelog.rb', line 106

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

.run(params) ⇒ Object



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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fastlane/actions/set_changelog.rb', line 4

def self.run(params)
  require 'spaceship'

  Spaceship::Tunes.(params[:username])
  app = Spaceship::Application.find(params[:app_identifier])

  version_number = params[:version]
  unless version_number
    # Automatically fetch the latest version
    UI.message("Fetching the latest version for this app")
    if app.edit_version and app.edit_version.version
      version_number = app.edit_version.version
    else
      UI.message("You have to specify a new version number: ")
      version_number = STDIN.gets.strip
    end
  end

  UI.message("Going to update version #{version_number}")

  changelog = params[:changelog]
  unless changelog
    path = "./fastlane/changelog.txt"
    UI.message("Looking for changelog in '#{path}'...")
    if File.exist? path
      changelog = File.read(path)
    else
      UI.error("Couldn't find changelog.txt")
      UI.message("Please enter the changelog here:")
      changelog = STDIN.gets
    end
  end

  UI.important("Going to update the changelog to:\n\n#{changelog}\n\n")

  if (v = app.edit_version)
    if v.version != version_number
      # Version is already there, make sure it matches the one we want to create
      UI.message("Changing existing version number from '#{v.version}' to '#{version_number}'")
      v.version = version_number
      v.save!
    else
      UI.message("Updating changelog for existing version #{v.version}")
    end
  else
    UI.message("Creating the new version: #{version_number}")
    app.create_version!(version_number)
    app = Spaceship::Application.find(params[:app_identifier]) # Replace with .reload method once available
    v = app.edit_version
  end

  v.release_notes.languages.each do |lang|
    v.release_notes[lang] = changelog
  end
  UI.message("Uploading changes to iTunes Connect...")
  v.save!

  UI.success("👼 Successfully pushed the new changelog to #{v.url}")
end