Skip to content

Commit

Permalink
Update asana_create_action_item to use ERB templates
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Sep 13, 2024
1 parent 090f338 commit a23842c
Show file tree
Hide file tree
Showing 19 changed files with 227 additions and 213 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "fastlane/action"
require "fastlane_core/configuration/config_item"
require "asana"
require "erb"
require "yaml"
require_relative "../helper/ddg_apple_automation_helper"
require_relative "../helper/github_actions_helper"
Expand All @@ -22,6 +23,7 @@ def self.run(params)
template_name = params[:template_name]
is_scheduled_release = params[:is_scheduled_release]
github_handle = params[:github_handle]
args = (params[:template_args] || {}).merge(Hash(ENV).transform_keys(&:downcase))

task_id = Helper::DdgAppleAutomationHelper.extract_asana_task_id(task_url)
automation_subtask_id = AsanaGetReleaseAutomationSubtaskIdAction.run(task_url: task_url, asana_access_token: token)
Expand All @@ -38,10 +40,16 @@ def self.run(params)
Helper::GitHubActionsHelper.set_output("asana_assignee_id", assignee_id)

if template_name
template_file = Helper::DdgAppleAutomationHelper.path_for_asset_file("asana_create_action_item/templates/#{template_name}.yml")
template_content = YAML.safe_load(Helper::DdgAppleAutomationHelper.load_file(template_file))
task_name = Helper::DdgAppleAutomationHelper.sanitize_html_and_replace_env_vars(template_content["name"])
html_notes = Helper::DdgAppleAutomationHelper.sanitize_html_and_replace_env_vars(template_content["html_notes"])
template_file = Helper::DdgAppleAutomationHelper.path_for_asset_file("asana_create_action_item/templates/#{template_name}.yml.erb")
template_content = Helper::DdgAppleAutomationHelper.load_file(template_file)

erb_template = ERB.new(template_content)
yaml = erb_template.result(binding)

task_data = YAML.safe_load(yaml)

task_name = Helper::DdgAppleAutomationHelper.sanitize_html_and_replace_env_vars(task_data["name"])
html_notes = Helper::DdgAppleAutomationHelper.sanitize_html_and_replace_env_vars(task_data["html_notes"])
end

begin
Expand Down Expand Up @@ -100,6 +108,11 @@ def self.available_options
The file is processed before being sent to Asana",
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :template_args,
description: "Template arguments. For backward compatibility, environment variables are added to this hash",
optional: true,
type: Hash,
default_value: {}),
FastlaneCore::ConfigItem.new(key: :github_handle,
description: "Github user handle",
optional: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
name: Generate appcast2.xml for ${TAG} hotfix release and upload assets to S3
name: Generate appcast2.xml for <%= args['tag'] %> hotfix release and upload assets to S3
html_notes: |
<body>
Publishing ${TAG} hotfix release failed in CI. Please follow the steps to generate the appcast file and upload files to S3 from your local machine.<br>
Publishing <%= args['tag'] %> hotfix release failed in CI. Please follow the steps to generate the appcast file and upload files to S3 from your local machine.<br>
<ol>
<li>Create a new file called <code>release-notes.txt</code> on your disk.
<ul>
<li>Add each release note as a separate line and don't add bullet points (•) – the script will add them automatically.</li>
</ul></li>
<li>Run <code>appcastManager</code>:
<ul>
<li><code>./scripts/appcast_manager/appcastManager.swift --release-hotfix-to-public-channel --dmg ~/Downloads/${DMG_NAME} --release-notes release-notes.txt</code></li>
<li><code>./scripts/appcast_manager/appcastManager.swift --release-hotfix-to-public-channel --dmg ~/Downloads/<%= args['dmg_name'] %> --release-notes release-notes.txt</code></li>
</ul></li>
<li>Verify that the new build is in the appcast file with the latest release notes and no internal channel tag. The phased rollout tag should <em>not</em> be present:
<ul>
<li><code>&lt;sparkle:phasedRolloutInterval&gt;43200&lt;/sparkle:phasedRolloutInterval&gt;</code></li>
</ul></li>
<li>Run <code>upload_to_s3.sh</code> script:
<ul>
<li><code>./scripts/upload_to_s3/upload_to_s3.sh --run --overwrite-duckduckgo-dmg ${VERSION}</code></li>
<li><code>./scripts/upload_to_s3/upload_to_s3.sh --run --overwrite-duckduckgo-dmg <%= args['version'] %></code></li>
</ul></li>
</ol>
When done, please verify that "Check for Updates" works correctly:
<ol>
<li>Launch a debug version of the app with an old version number.</li>
<li>Make sure you're not identified as an internal user in the app.</li>
<li>Go to Main Menu → DuckDuckGo → Check for Updates...</li>
<li>Verify that you're being offered to update to ${TAG}.</li>
<li>Verify that you're being offered to update to <%= args['tag'] %>.</li>
<li>Verify that the update works.</li>
</ol><br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
🔗 Workflow URL: <a href='<%= args['worklow_url'] %>'><%= args['worklow_url'] %></a>.
</body>

Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: Generate appcast2.xml for ${TAG} internal release and upload assets to S3
name: Generate appcast2.xml for <%= args['tag'] %> internal release and upload assets to S3
html_notes: |
<body>
Publishing ${TAG} internal release failed in CI. Please follow the steps to generate the appcast file and upload files to S3 from your local machine.<br>
Publishing <%= args['tag'] %> internal release failed in CI. Please follow the steps to generate the appcast file and upload files to S3 from your local machine.<br>
<ol>
<li>Download <a href='${DMG_URL}'>the DMG for ${TAG} release</a>.</li>
<li>Download <a href='<%= args['dmg_url'] %>'>the DMG for <%= args['tag'] %> release</a>.</li>
<li>Create a new file called <code>release-notes.txt</code> on your disk.
<ul>
<li>Add each release note as a separate line and don't add bullet points (•) – the script will add them automatically.</li>
</ul></li>
<li>Run <code>appcastManager</code>:
<ul>
<li><code>./scripts/appcast_manager/appcastManager.swift --release-to-internal-channel --dmg ~/Downloads/${DMG_NAME} --release-notes release-notes.txt</code></li>
<li><code>./scripts/appcast_manager/appcastManager.swift --release-to-internal-channel --dmg ~/Downloads/<%= args['dmg_name'] %> --release-notes release-notes.txt</code></li>
</ul></li>
<li>Verify that the new build is in the appcast file with the following internal channel tag:
<ul>
Expand All @@ -26,9 +26,9 @@ html_notes: |
<li>Launch a debug version of the app with an old version number.</li>
<li>Identify as an internal user in the app.</li>
<li>Go to Main Menu → DuckDuckGo → Check for Updates...</li>
<li>Verify that you're being offered to update to ${TAG}.</li>
<li>Verify that you're being offered to update to <%= args['tag'] %>.</li>
<li>Verify that the update works.</li>
</ol><br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
🔗 Workflow URL: <a href='<%= args['worklow_url'] %>'><%= args['worklow_url'] %></a>.
</body>

Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
name: Generate appcast2.xml for ${TAG} public release and upload assets to S3
name: Generate appcast2.xml for <%= args['tag'] %> public release and upload assets to S3
html_notes: |
<body>
Publishing ${TAG} release failed in CI. Please follow the steps to generate the appcast file and upload files to S3 from your local machine.<br>
Publishing <%= args['tag'] %> release failed in CI. Please follow the steps to generate the appcast file and upload files to S3 from your local machine.<br>
<ol>
<li>Create a new file called <code>release-notes.txt</code> on your disk.
<ul>
<li>Add each release note as a separate line and don't add bullet points (•) – the script will add them automatically.</li>
</ul></li>
<li>Run <code>appcastManager</code>:
<ul>
<li><code>./scripts/appcast_manager/appcastManager.swift --release-to-public-channel --version ${VERSION} --release-notes release-notes.txt</code></li>
<li><code>./scripts/appcast_manager/appcastManager.swift --release-to-public-channel --version <%= args['version'] %> --release-notes release-notes.txt</code></li>
</ul></li>
<li>Verify that the new build is in the appcast file with the latest release notes, the phased rollout tag (below) and no internal channel tag:
<ul>
<li><code>&lt;sparkle:phasedRolloutInterval&gt;43200&lt;/sparkle:phasedRolloutInterval&gt;</code></li>
</ul></li>
<li>Run <code>upload_to_s3.sh</code> script:
<ul>
<li><code>./scripts/upload_to_s3/upload_to_s3.sh --run --overwrite-duckduckgo-dmg ${VERSION}</code></li>
<li><code>./scripts/upload_to_s3/upload_to_s3.sh --run --overwrite-duckduckgo-dmg <%= args['version'] %></code></li>
</ul></li>
</ol>
When done, please verify that "Check for Updates" works correctly:
<ol>
<li>Launch a debug version of the app with an old version number.</li>
<li>Make sure you're not identified as an internal user in the app.</li>
<li>Go to Main Menu → DuckDuckGo → Check for Updates...</li>
<li>Verify that you're being offered to update to ${TAG}.</li>
<li>Verify that you're being offered to update to <%= args['tag'] %>.</li>
<li>Verify that the update works.</li>
</ol><br>
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>.
🔗 Workflow URL: <a href='<%= args['worklow_url'] %>'><%= args['worklow_url'] %></a>.
</body>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Delete <%= args['branch'] %> branch
html_notes: |
<body>
The <code><%= args['tag'] %></code> public release has been successfully tagged and published in GitHub releases,
but deleting <code><%= args['branch'] %></code> branch failed. Please delete it manually:
<ul>
<li><code>git push origin --delete <%= args['branch'] %></code></li>
</ul>
Complete this task when ready, or if the release branch has already been deleted.<br>
<br>
🔗 Workflow URL: <a href='<%= args['worklow_url'] %>'><%= args['worklow_url'] %></a>.
</body>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Tag <%= args['branch'] %> branch and create GitHub release
html_notes: |
<body>
Failed to tag the release with <code><%= args['tag'] %></code> tag.<br>
Please follow instructions below to tag the branch, make GitHub release and merge release branch to <code><%= args['base_branch'] %></code> manually.<br>
<br>
Issue the following git commands to tag the release and merge the branch:
<ul>
<li><code>git fetch origin</code></li>
<li><code>git checkout <%= args['branch'] %></code> switch to the release branch</li>
<li><code>git pull origin <%= args['branch'] %></code> pull latest changes</li>
<li><code>git tag <%= args['tag'] %></code> tag the release</li>
<li><code>git push origin <%= args['tag'] %></code> push the tag</li>
<li><code>git checkout <%= args['base_branch'] %></code> switch to <%= args['base_branch'] %></li>
<li><code>git pull origin <%= args['base_branch'] %></code> pull the latest code</li>
<li><code>git merge <%= args['branch'] %></code>
<ul>
<li>Resolve conflicts as needed</li>
<li>When merging a hotfix branch into an internal release branch, you will get conflicts in version and build number xcconfig files:
<ul>
<li>In the version file: accept the internal version number (higher).</li>
<li>In the build number file: accept the hotfix build number (higher). This step is very important in order to calculate the build number of the next internal release correctly.</li>
</ul></li>
</ul></li>
<li><code>git push origin <%= args['base_branch'] %></code> push merged branch</li>
</ul><br>
To create GitHub release:
<ul>
<li>Set up GH CLI if you haven't yet: <a data-asana-gid='1203791243007683'/></li>
<li>Run the following command:
<ul>
<li><code>gh release create <%= args['tag'] %> --generate-notes --prerelease --notes-start-tag <%= args['last_release_tag'] %></code></li>
</ul></li>
</ul><br>
Complete this task when ready and proceed with testing the build. If you're bumping an internal release, you should get another task asking you to publish the release in Sparkle.
Look for other tasks in <a data-asana-gid='<%= args['automation_task_id'] %>'/> task and handle them as needed.<br>
<br>
🔗 Workflow URL: <a href='<%= args['worklow_url'] %>'><%= args['worklow_url'] %></a>.
</body>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Merge <%= args['branch'] %> to <%= args['base_branch'] %>
html_notes: |
<body>
The <code><%= args['tag'] %></code> release has been successfully tagged and published in GitHub releases,
but merging to <code><%= args['base_branch'] %></code> failed. Please resolve conflicts and merge <code><%= args['branch'] %></code> to <code><%= args['base_branch'] %></code> manually.<br>
<br>
Issue the following git commands:
<ul>
<li><code>git fetch origin</code></li>
<li><code>git checkout <%= args['branch'] %></code> switch to the release branch</li>
<li><code>git pull origin <%= args['branch'] %></code> pull latest changes</li>
<li><code>git checkout <%= args['base_branch'] %></code> switch to <%= args['base_branch'] %></li>
<li><code>git pull origin <%= args['base_branch'] %></code> pull the latest code</li>
<li><code>git merge <%= args['branch'] %></code>
<ul>
<li>Resolve conflicts as needed</li>
<li>When merging a hotfix branch into an internal release branch, you will get conflicts in version and build number xcconfig files:
<ul>
<li>In the version file: accept the internal version number (higher).</li>
<li>In the build number file: accept the hotfix build number (higher). This step is very important in order to calculate the build number of the next internal release correctly.</li>
</ul></li>
</ul></li>
<li><code>git push origin <%= args['base_branch'] %></code> push merged branch</li>
</ul>
Complete this task when ready and proceed with testing the build.<br>
<br>
🔗 Workflow URL: <a href='<%= args['worklow_url'] %>'><%= args['worklow_url'] %></a>.
</body>
Loading

0 comments on commit a23842c

Please sign in to comment.