Skip to content

Commit

Permalink
Start new release actions (#16)
Browse files Browse the repository at this point in the history
Co-authored-by: Dominik Kapusta <[email protected]>
  • Loading branch information
kshann and ayoy authored Nov 18, 2024
1 parent 0e98d75 commit c4f9f41
Show file tree
Hide file tree
Showing 28 changed files with 2,728 additions and 76 deletions.
6 changes: 0 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ gem 'rubocop-require_tools'
# SimpleCov is a code coverage analysis tool for Ruby.
gem 'simplecov'

gem 'asana'
gem 'climate_control'
gem 'httparty'

gem 'octokit'

gemspec

plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
Expand Down
1 change: 1 addition & 0 deletions fastlane-plugin-ddg_apple_automation.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
spec.add_dependency('climate_control')
spec.add_dependency('httpparty')
spec.add_dependency('octokit')
spec.add_dependency('semantic')
end
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def self.details
def self.available_options
[
FastlaneCore::ConfigItem.asana_access_token,
FastlaneCore::ConfigItem.is_scheduled_release,
FastlaneCore::ConfigItem.new(key: :task_url,
description: "Asana release task URL",
optional: false,
Expand Down Expand Up @@ -127,12 +128,7 @@ def self.available_options
FastlaneCore::ConfigItem.new(key: :github_handle,
description: "Github user handle",
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :is_scheduled_release,
description: "Indicates whether the release was scheduled or started manually",
optional: true,
type: Boolean,
default_value: false)
type: String)
]
end

Expand All @@ -149,10 +145,7 @@ def self.create_subtask(token:, task_id:, assignee_id:, task_name:, notes: nil,
subtask_options[:notes] = notes unless notes.nil?
subtask_options[:html_notes] = html_notes unless html_notes.nil?

asana_client = Asana::Client.new do |c|
c.authentication(:access_token, token)
c.default_headers("Asana-Enable" => "new_goal_memberships,new_user_task_lists")
end
asana_client = Helper::AsanaHelper.make_asana_client(token)
asana_client.tasks.create_subtask_for_task(**subtask_options)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require "time"
require_relative "../helper/asana_helper"
require_relative "../helper/ddg_apple_automation_helper"
require_relative "../helper/git_helper"
require_relative "../helper/github_actions_helper"

module Fastlane
Expand All @@ -16,14 +17,12 @@ def self.setup_constants(platform)
case platform
when "ios"
@constants = {
repo_name: "duckduckgo/ios",
release_task_prefix: "iOS App Release",
hotfix_task_prefix: "iOS App Hotfix Release",
release_section_id: "1138897754570756"
}
when "macos"
@constants = {
repo_name: "duckduckgo/macos-browser",
release_task_prefix: "macOS App Release",
hotfix_task_prefix: "macOS App Hotfix Release",
release_section_id: "1202202395298964"
Expand All @@ -37,8 +36,12 @@ def self.run(params)
platform = params[:platform] || Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]
setup_constants(platform)

latest_marketing_version = find_latest_marketing_version(github_token)
UI.message("Checking latest marketing version")
latest_marketing_version = find_latest_marketing_version(github_token, params[:platform])
UI.success("Latest marketing version: #{latest_marketing_version}")
UI.message("Searching for release task for version #{latest_marketing_version}")
release_task_id = find_release_task(latest_marketing_version, asana_access_token)
UI.user_error!("No release task found for version #{latest_marketing_version}") unless release_task_id

release_task_url = Helper::AsanaHelper.asana_task_url(release_task_id)
release_branch = "release/#{latest_marketing_version}"
Expand All @@ -55,11 +58,11 @@ def self.run(params)
}
end

def self.find_latest_marketing_version(github_token)
def self.find_latest_marketing_version(github_token, platform)
client = Octokit::Client.new(access_token: github_token)

# NOTE: `client.latest_release` returns release marked as "latest", i.e. a public release
latest_internal_release = client.releases(@constants[:repo_name], { per_page: 1 }).first
latest_internal_release = client.releases(Helper::GitHelper.repo_name(platform), { per_page: 1 }).first

version = extract_version_from_tag_name(latest_internal_release&.tag_name)
if version.to_s.empty?
Expand All @@ -83,11 +86,7 @@ def self.validate_semver(version)
end

def self.find_release_task(version, asana_access_token)
asana_client = Asana::Client.new do |c|
c.authentication(:access_token, asana_access_token)
c.default_headers("Asana-Enable" => "new_goal_memberships,new_user_task_lists")
end

asana_client = Helper::AsanaHelper.make_asana_client(asana_access_token)
release_task_id = nil

begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "fastlane_core/configuration/config_item"
require "asana"
require_relative "../helper/asana_helper"
require_relative "../helper/ddg_apple_automation_helper"
require_relative "asana_add_comment_action"
require_relative "asana_get_user_id_for_github_handle_action"

Expand All @@ -20,10 +21,7 @@ def self.run(params)
asana_user_id = find_asana_user_id(params)
args[:assignee_id] = asana_user_id

asana_client = Asana::Client.new do |c|
c.authentication(:access_token, token)
c.default_headers("Asana-Enable" => "new_goal_memberships,new_user_task_lists")
end
asana_client = Helper::AsanaHelper.make_asana_client(token)

begin
UI.important("Adding user #{asana_user_id} as collaborator on release task's 'Automation' subtask")
Expand Down Expand Up @@ -78,6 +76,7 @@ def self.details
def self.available_options
[
FastlaneCore::ConfigItem.asana_access_token,
FastlaneCore::ConfigItem.is_scheduled_release,
FastlaneCore::ConfigItem.new(key: :task_url,
description: "Asana release task URL",
optional: false,
Expand All @@ -99,12 +98,7 @@ def self.available_options
FastlaneCore::ConfigItem.new(key: :github_handle,
description: "Github user handle",
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :is_scheduled_release,
description: "Indicates whether the release was scheduled or started manually",
optional: true,
type: Boolean,
default_value: false)
type: String)
]
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "fastlane/action"
require "fastlane_core/configuration/config_item"
require "octokit"
require_relative "../helper/asana_helper"
require_relative "../helper/ddg_apple_automation_helper"
require_relative "../helper/git_helper"
require_relative "../helper/github_actions_helper"

module Fastlane
module Actions
class BumpBuildNumberAction < Action
def self.run(params)
Helper::GitHelper.setup_git_user
params[:platform] ||= Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]
options = params.values
Helper::DdgAppleAutomationHelper.increment_build_number(options[:platform], options, other_action)
end

def self.description
"Prepares a subsequent internal release"
end

def self.authors
["DuckDuckGo"]
end

def self.return_value
"The newly created release task ID"
end

def self.details
"This action increments the project build number and pushes the changes to the remote repository."
end

def self.available_options
[
FastlaneCore::ConfigItem.asana_access_token,
FastlaneCore::ConfigItem.github_token,
FastlaneCore::ConfigItem.platform
]
end

def self.is_supported?(platform)
true
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require "fastlane/action"
require "fastlane_core/configuration/config_item"
require "octokit"
require_relative "../helper/asana_helper"
require_relative "../helper/ddg_apple_automation_helper"
require_relative "../helper/git_helper"
require_relative "../helper/github_actions_helper"

module Fastlane
module Actions
class StartNewReleaseAction < Action
def self.run(params)
Helper::GitHelper.setup_git_user
params[:platform] ||= Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]

options = params.values
options[:asana_user_id] = Helper::AsanaHelper.get_asana_user_id_for_github_handle(options[:github_handle])

release_branch_name, new_version = Helper::DdgAppleAutomationHelper.prepare_release_branch(
params[:platform], params[:version], other_action
)
options[:version] = new_version
options[:release_branch_name] = release_branch_name

release_task_id = Helper::AsanaHelper.create_release_task(options[:platform], options[:version], options[:asana_user_id], options[:asana_access_token])
options[:release_task_id] = release_task_id

Helper::AsanaHelper.update_asana_tasks_for_internal_release(options)
end

def self.description
"Starts a new release"
end

def self.authors
["DuckDuckGo"]
end

def self.return_value
"The newly created release task ID"
end

def self.details
<<-DETAILS
This action performs the following tasks:
* creates a new release branch,
* updates version and build number,
* updates embedded files,
* pushes the changes to the remote repository,
* creates a new Asana release task based off the provided task template,
* updates the Asana release task with tasks included in the release.
DETAILS
end

def self.available_options
[
FastlaneCore::ConfigItem.asana_access_token,
FastlaneCore::ConfigItem.github_token,
FastlaneCore::ConfigItem.platform,
FastlaneCore::ConfigItem.new(key: :version,
description: "Version number to force (calculated automatically if not provided)",
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :github_handle,
description: "Github user handle",
optional: false,
type: String),
FastlaneCore::ConfigItem.new(key: :target_section_id,
description: "Section ID in Asana where tasks included in the release should be moved",
optional: false,
type: String)
]
end

def self.is_supported?(platform)
true
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.setup_constants(platform)
end

def self.run(params)
other_action.ensure_git_branch(branch: "^(:?release|hotfix)/.*$")
other_action.ensure_git_branch(branch: "^(:?release|hotfix)/.+$")
Helper::GitHelper.setup_git_user

params[:platform] ||= Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]
Expand Down Expand Up @@ -198,6 +198,7 @@ def self.available_options
[
FastlaneCore::ConfigItem.asana_access_token,
FastlaneCore::ConfigItem.github_token,
FastlaneCore::ConfigItem.is_scheduled_release,
FastlaneCore::ConfigItem.platform,
FastlaneCore::ConfigItem.new(key: :asana_task_url,
description: "Asana release task URL",
Expand Down Expand Up @@ -226,12 +227,7 @@ def self.available_options
FastlaneCore::ConfigItem.new(key: :is_prerelease,
description: "Is this a pre-release? (a.k.a. internal release)",
optional: false,
type: Boolean),
FastlaneCore::ConfigItem.new(key: :is_scheduled_release,
description: "Indicates whether the release was scheduled or started manually",
optional: true,
type: Boolean,
default_value: false)
type: Boolean)
]
end

Expand Down
Loading

0 comments on commit c4f9f41

Please sign in to comment.