Skip to content

Commit

Permalink
Merge branch 'main' into dominik/find-release
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Sep 5, 2024
2 parents 8e2dcb2 + f63e985 commit 17d7ea9
Show file tree
Hide file tree
Showing 27 changed files with 409 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ gem 'rubocop-require_tools'
# SimpleCov is a code coverage analysis tool for Ruby.
gem 'simplecov'

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

gem 'octokit'
Expand Down
5 changes: 4 additions & 1 deletion fastlane-plugin-ddg_apple_automation.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Gem::Specification.new do |spec|
# Don't add a dependency to fastlane or fastlane_re
# since this would cause a circular dependency

spec.add_dependency('httparty')
# spec.add_dependency 'your-dependency', '~> 1.0.0'
spec.add_dependency('asana')
spec.add_dependency('climate_control')
spec.add_dependency('httpparty')
spec.add_dependency('octokit')
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
require "fastlane/action"
require "fastlane_core/configuration/config_item"
require "asana"
require_relative "../helper/ddg_apple_automation_helper"
require_relative "asana_extract_task_id_action"

module Fastlane
module Actions
class AsanaAddCommentAction < Action
def self.run(params)
asana_access_token = params[:asana_access_token]
task_id = params[:task_id]
task_url = params[:task_url]
template_name = params[:template_name]
comment = params[:comment]
workflow_url = params[:workflow_url]

begin
validate_params(task_id, task_url, comment, template_name, workflow_url)
rescue ArgumentError => e
UI.user_error!(e.message)
return
end

task_id = Fastlane::Actions::AsanaExtractTaskIdAction.run(task_url: task_url) if task_url

if template_name
template_content = load_template_file(template_name)
return unless template_content

html_text = process_template_content(template_content)
create_story(asana_access_token, task_id, html_text: html_text)
else
text = "#{comment}\n\nWorkflow URL: #{workflow_url}"
create_story(asana_access_token, task_id, text: text)
end
end

def self.description
"Adds a comment to the Asana task"
end

def self.authors
["DuckDuckGo"]
end

def self.return_value
""
end

def self.details
# Optional:
""
end

def self.available_options
[
FastlaneCore::ConfigItem.asana_access_token,
FastlaneCore::ConfigItem.new(key: :task_id,
description: "Asana task ID",
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :task_url,
description: "Asana task URL",
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :comment,
description: "Comment to add to the Asana task",
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :template_name,
description: "Name of a template file (without extension) for the comment. Templates can be found in assets/asana_add_comment/templates subdirectory.
The file is processed before being sent to Asana",
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :workflow_url,
description: "Workflow URL to include in the comment",
optional: true,
type: String)
]
end

def self.is_supported?(platform)
true
end

def self.validate_params(task_id, task_url, comment, template_name, workflow_url)
if task_id.to_s.empty? && task_url.to_s.empty?
raise ArgumentError, "Both task_id and task_url cannot be empty. At least one must be provided."
end

if comment.to_s.empty? && template_name.to_s.empty?
raise ArgumentError, "Both comment and template_name cannot be empty. At least one must be provided."
end

if comment && workflow_url.to_s.empty?
raise ArgumentError, "If comment is provided, workflow_url cannot be empty"
end
end

def self.load_template_file(template_name)
template_file = Helper::DdgAppleAutomationHelper.path_for_asset_file("asana_add_comment/templates/#{template_name}.html")
File.read(template_file)
rescue StandardError
UI.user_error!("Error: The file '#{template_name}.html' does not exist.")
end

def self.create_story(asana_access_token, task_id, text: nil, html_text: nil)
client = Asana::Client.new do |c|
c.authentication(:access_token, asana_access_token)
end
begin
if text
client.stories.create_story_for_task(task_gid: task_id, text: text)
else
client.stories.create_story_for_task(task_gid: task_id, html_text: html_text)
end
rescue StandardError => e
UI.user_error!("Failed to post comment: #{e}")
end
end

def self.process_template_content(template_content)
template_content.gsub(/\$\{(\w+)\}/) { ENV.fetch($1, '') } # replace environment variables
.gsub(/\s+/, ' ') # replace multiple whitespaces with a single space
.gsub(/>\s+</, '><') # remove spaces between HTML tags
.strip # remove leading and trailing whitespaces
.gsub(%r{<br\s*/?>}, "\n") # replace <br> tags with newlines
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<body>
<h2>[ACTION NEEDED] Publishing ${TAG} hotfix release to Sparkle failed</h2>
<a data-asana-gid='${ASSIGNEE_ID}' />, please proceed with generating appcast2.xml and uploading files to S3 from your
local machine, <a data-asana-gid='${TASK_ID}' data-asana-dynamic='false'>according to instructions</a>.<br>
<br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<body>
<h2>[ACTION NEEDED] Publishing ${TAG} internal release to Sparkle failed</h2>
<a data-asana-gid='${ASSIGNEE_ID}' />, please proceed with generating appcast2.xml and uploading files to S3 from your
local machine, <a data-asana-gid='${TASK_ID}' data-asana-dynamic='false'>according to instructions</a>.<br>
<br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<body>
<h2>[ACTION NEEDED] Publishing ${TAG} release to Sparkle failed</h2>
<a data-asana-gid='${ASSIGNEE_ID}' />, please proceed with generating appcast2.xml and uploading files to S3 from your
local machine, <a data-asana-gid='${TASK_ID}' data-asana-dynamic='false'>according to instructions</a>.<br>
<br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<body>
🐛 Debug symbols archive for ${TAG} build is uploaded to <code>${DSYM_S3_PATH}</code>.<br>
<br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<body>
📥 DMG for ${TAG} is available from <a href='${DMG_URL}'>${DMG_URL}</a>.<br>
<br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<body>
<h2>Hotfix branch ${BRANCH} ready ⚙️</h2>
<ul>
<li>🔱 <code>${BRANCH}</code> branch has been created off <code>${RELEASE_TAG}</code> tag.</li>
<li>Point any pull requests with changes required for the hotfix release to that branch.</li>
</ul>
<br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<body>
Build ${TAG} is now available for internal testing through Sparkle and TestFlight.<br>
<br>
Added in this release:
${TASKS_SINCE_LAST_INTERNAL_RELEASE}<br>
<br>
<a href='${DMG_URL}'>📥 DMG download link</a>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<body>
Build ${TAG} is now available for internal testing through Sparkle and TestFlight.<br>
<br>
<a href='${DMG_URL}'>📥 DMG download link</a>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<body>
<h2>[ACTION NEEDED] Internal release build ${TAG} ready</h2>
<ul>
<li>📥 DMG is available from <a href='${DMG_URL}'>${DMG_URL}</a>.</li>
<li>🏷️ Repository is tagged with <code>${TAG}</code> tag.</li>
<li>🚢 GitHub <a href='${RELEASE_URL}'>${TAG} pre-release</a> is created.</li>
<li><b>❗️ Merging <code>${BRANCH}</code> to <code>${BASE_BRANCH}</code> failed.</b>
<ul>
<li><a data-asana-gid='${ASSIGNEE_ID}' />, please proceed with manual merging <a data-asana-gid='${TASK_ID}'
data-asana-dynamic='false'>according to instructions</a>.</li>
</ul>
</li>
</ul>
<br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<body>
<h2>[ACTION NEEDED] Internal release build ${TAG} ready</h2>
<ul>
<li>📥 DMG is available from <a href='${DMG_URL}'>${DMG_URL}</a>.</li>
<li><b>❗️ Tagging repository failed.</b></li>
<li><b>⚠️ GitHub release creation was skipped.</b></li>
<li><b>⚠️ Merging <code>${BRANCH}</code> to <code>${BASE_BRANCH}</code> was skipped.</b></li>
</ul>
<a data-asana-gid='${ASSIGNEE_ID}' />, please proceed with manual tagging and merging <a data-asana-gid='${TASK_ID}'
data-asana-dynamic='false'>according to instructions</a>.<br>
<br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<body>
<h2>Internal release build ${TAG} ready ✅</h2>
<ul>
<li>📥 DMG is available from <a href='${DMG_URL}'>${DMG_URL}</a>.
<ul>
<li>If this is a subsequent internal release (started by calling <em>Bump Internal Release</em> workflow), the
DMG will be automatically published to Sparkle in a few minutes. Sit tight.</li>
</ul>
</li>
<li>🏷️ Repository is tagged with <code>${TAG}</code> tag.</li>
<li>🚢 GitHub <a href='${RELEASE_URL}'>${TAG} pre-release</a> is created.</li>
<li>🔱 <code>${BRANCH}</code> branch has been successfully merged to <code>${BASE_BRANCH}</code>.</li>
</ul>
<br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<body>
Build ${TAG} is now available publicly through Sparkle and TestFlight.<br>
<br>
<a href='${DMG_URL}'>📥 DMG download link</a>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<body>
<h2>[ACTION NEEDED] Failed to publish ${TAG} release – tagging failed</h2>
<ul>
<li><b>❗️ Tagging repository with ${TAG} tag failed.</b></li>
<li><b>⚠️ GitHub release creation was skipped.</b></li>
<li><b>⚠️ Deleting <code>${BRANCH}</code> was skipped.</b></li>
</ul>
<br>
<a data-asana-gid='${ASSIGNEE_ID}' />, please proceed with the release <a data-asana-gid='${TASK_ID}'
data-asana-dynamic='false'>according to instructions</a>.<br>
<br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<body>
<h2>[ACTION NEEDED] Public release ${TAG} tagged</h2>
<ul>
<li>🏷️ Repository is tagged with <code>${TAG}</code> tag.</li>
<li>🚢 GitHub <a href='${RELEASE_URL}'>${TAG} release</a> is created.</li>
<li><b>❗️ Deleting <code>${BRANCH}</code> failed.</b>
<ul>
<li><a data-asana-gid='${ASSIGNEE_ID}' />, please proceed with deleting the branch manually <a
data-asana-gid='${TASK_ID}' data-asana-dynamic='false'>according to instructions</a>.</li>
</ul>
</li>
</ul>
<br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<body>
<h2>Public release ${TAG} has been tagged ✅</h2>
<ul>
<li>📥 DMG is available from <a href='${DMG_URL}'>${DMG_URL}</a>.</li>
<li>🏷️ Repository is tagged with <code>${TAG}</code> tag.</li>
<li>🚢 GitHub <a href='${RELEASE_URL}'>${TAG} release</a> is created.</li>
<li>🔱 <code>${BRANCH}</code> branch has been deleted.</li>
<li>🚀 The relase will be published to Sparkle in a few minutes (you'll get notified).</li>
</ul>
<br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<body>
<h2>Build ${TAG} is available for internal testing through Sparkle 🚀</h2>
<ul>
<li>🌟 New appcast file has been generated and uploaded to S3, together with binary delta files.</li>
<li>👀 <a data-asana-gid='${ASSIGNEE_ID}' />, please proceed by following instructions in <a
data-asana-gid='${TASK_ID}' /> which concludes the internal release process.</li>
</ul>
<br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<body>
<h2>Build ${TAG} is available publicly through Sparkle 🚀</h2>
<ul>
<li>🌟 New appcast file has been generated and uploaded to S3, together with binary delta files.</li>
<li>👀 <a data-asana-gid='${ASSIGNEE_ID}' />, please proceed by following instructions in <a
data-asana-gid='${TASK_ID}' /> and <a data-asana-gid='${ANNOUNCEMENT_TASK_ID}' /> which concludes the release
process.</li>
</ul>
<br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
</body>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "fastlane_core/configuration/config_item"
require 'fastlane_core/ui/ui'
require "fastlane_core/ui/ui"

module Fastlane
UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI)
Expand All @@ -18,6 +18,10 @@ def self.asana_task_url(task_id)
end
"#{ASANA_APP_URL}/#{task_id}/f"
end

def self.path_for_asset_file(file)
File.expand_path("../assets/#{file}", __dir__)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fastlane/plugin/ddg_apple_automation/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Fastlane
module DdgAppleAutomation
VERSION = "0.5.0"
VERSION = "0.6.0"
end
end
Loading

0 comments on commit 17d7ea9

Please sign in to comment.