-
Notifications
You must be signed in to change notification settings - Fork 1
[Tophat] Add Tophat integration for Checkout Kit React Native builds #401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kieran-osgood-shopify
wants to merge
4
commits into
kieran-osgood/e2e-browserstack/phase-7-soft-launch
Choose a base branch
from
kieran-osgood/07-03-addtophatintegrationforcheckoutkitreactnativebuilds
base: kieran-osgood/e2e-browserstack/phase-7-soft-launch
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
34d7d06
Add Tophat integration for Checkout Kit React Native builds
kieran-osgood-shopify f06de08
Remind devs to set Bitrise PAT in Tophat after dev up
kieran-osgood-shopify 4552542
Make Tophat targets extensible via shared manifest and labeled entries
kieran-osgood-shopify 96fe2c9
Document Tophat E2E reporter behavior
kieran-osgood-shopify File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ up: | |
| - mint | ||
| - xcbeautify | ||
| - jq | ||
| - fzf | ||
| - swiftlint | ||
| - swiftformat | ||
| - sccache | ||
|
|
@@ -32,6 +33,10 @@ up: | |
| name: Run Checkout Kit workspace setup | ||
| met?: ./scripts/setup_dev_workspace --check --skip-optional-prompts | ||
| meet: ./scripts/setup_dev_workspace --skip-optional-prompts | ||
| - tophat_mobile | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a predefined dev command that installs and sets up tophat! |
||
| - run_always: | ||
| name: Configure Tophat Quick Launch items | ||
| run: ruby scripts/tophat/configure_quick_launch | ||
|
|
||
| open: | ||
| "GitHub": "https://github.com/Shopify/checkout-kit" | ||
|
|
@@ -74,6 +79,11 @@ commands: | |
| desc: Copy the root .env into the current worktree so `dev up` can regenerate sample config | ||
| run: ./scripts/copy_worktree_env | ||
|
|
||
| tophat: | ||
| desc: "Install a PR's build to a device via Tophat. Usage: dev tophat [<pr-number-or-url>] [<target>]" | ||
| syntax: "[<pr-number-or-url>] [<target>]" | ||
| run: ruby scripts/tophat/dev_tophat "$@" | ||
|
|
||
| format: | ||
| desc: Auto-format and apply safe lint autocorrections across supported workspaces | ||
| aliases: [fix] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,49 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "json" | ||
| require "uri" | ||
| require_relative "json_http_client" | ||
|
|
||
| # Publishes normalized E2E run results back to GitHub as commit statuses, | ||
| # check runs, and a sticky pull request comment for failures. | ||
| # check runs, and a sticky pull request comment with Tophat install links. | ||
| class E2EGitHubReporter | ||
| COMMENT_MARKER = "<!-- checkout-kit-e2e-report -->" | ||
| TOPHAT_INSTALL_BASE = "http://localhost:29070/install/bitrise-branch" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| def initialize(results, repository:, sha:, pr_number:, token: nil, strict: false) | ||
| def initialize(results, repository:, sha:, pr_number:, branch: nil, token: nil, strict: false, app_slug: nil, targets: []) | ||
| @results = results | ||
| @repository = repository | ||
| @sha = sha | ||
| @pr_number = pr_number | ||
| @branch = branch | ||
| @token = token | ||
| @strict = strict | ||
| @app_slug = app_slug | ||
| @targets = targets | ||
| end | ||
|
|
||
| def publish! | ||
| commit_status_payloads.each { |payload| client.post_json("/repos/#{@repository}/statuses/#{@sha}", payload) } | ||
| client.post_json("/repos/#{@repository}/check-runs", check_run_payload) | ||
| sync_failure_comment | ||
| sync_comment | ||
| end | ||
|
|
||
| def tophat_install_url(target) | ||
| pairs = target.fetch("recipes").flat_map do |recipe| | ||
| [ | ||
| ["platform", recipe.fetch("platform")], | ||
| ["destination", recipe.fetch("destination")], | ||
| ["app_slug", @app_slug], | ||
| ["branch", @branch], | ||
| ["workflow", recipe.fetch("workflow")], | ||
| ["artifact_name", recipe.fetch("artifact_name")] | ||
| ] | ||
| end | ||
| "#{TOPHAT_INSTALL_BASE}?#{URI.encode_www_form(pairs)}" | ||
| end | ||
|
|
||
| def comment_body | ||
| [COMMENT_MARKER, tophat_install_markdown, markdown_summary].join("\n\n") | ||
| end | ||
|
|
||
| def markdown_summary | ||
|
|
@@ -63,14 +86,22 @@ def commit_status_payloads | |
| end | ||
| end | ||
|
|
||
| def failure_comment_body | ||
| return nil if failed_results.empty? | ||
| private | ||
|
|
||
| [COMMENT_MARKER, markdown_summary].join("\n") | ||
| def tophat_install_markdown | ||
| lines = [] | ||
| lines << "## Install this build" | ||
| lines << "" | ||
| lines << "Open Tophat, select your target device, then click Install. Links open on the Mac running Tophat." | ||
| lines << "" | ||
| lines << "| SDK | Install |" | ||
| lines << "|---|---|" | ||
| @targets.each do |target| | ||
| lines << "| #{target.fetch("label")} | [Install with Tophat](#{tophat_install_url(target)}) |" | ||
| end | ||
| lines.join("\n") | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def check_run_payload | ||
| conclusion = failed_results.empty? ? "success" : "failure" | ||
| { | ||
|
|
@@ -85,21 +116,17 @@ def check_run_payload | |
| } | ||
| end | ||
|
|
||
| def sync_failure_comment | ||
| body = failure_comment_body | ||
| existing = existing_failure_comment | ||
| if body | ||
| if existing | ||
| client.patch_json("/repos/#{@repository}/issues/comments/#{existing.fetch("id")}", {body: body}) | ||
| else | ||
| client.post_json("/repos/#{@repository}/issues/#{@pr_number}/comments", {body: body}) | ||
| end | ||
| elsif existing | ||
| client.patch_json("/repos/#{@repository}/issues/comments/#{existing.fetch("id")}", {body: "#{COMMENT_MARKER}\n✅ Checkout Kit E2E failures resolved."}) | ||
| def sync_comment | ||
| body = comment_body | ||
| existing = existing_comment | ||
| if existing | ||
| client.patch_json("/repos/#{@repository}/issues/comments/#{existing.fetch("id")}", {body: body}) | ||
| else | ||
| client.post_json("/repos/#{@repository}/issues/#{@pr_number}/comments", {body: body}) | ||
| end | ||
| end | ||
|
|
||
| def existing_failure_comment | ||
| def existing_comment | ||
| issue_comments.find do |comment| | ||
| comment.fetch("body", "").include?(COMMENT_MARKER) | ||
| end | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| ruby "$SCRIPT_DIR/tophat/configure_quick_launch" "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "json" | ||
| require "open3" | ||
|
|
||
| module CheckoutKitTophat | ||
| TOPHATCTL = "/Applications/Tophat.app/Contents/MacOS/tophatctl" | ||
| MANIFEST = File.expand_path("targets.json", __dir__) | ||
| BITRISE_PAT_URL = "https://app.bitrise.io/me/account/security" | ||
| PLATFORM_LABELS = {"ios" => "iOS", "android" => "Android"}.freeze | ||
| module_function | ||
|
|
||
| def abort_with(message) | ||
| warn message | ||
| exit 1 | ||
| end | ||
|
|
||
| def capture(*command) | ||
| stdout, status = Open3.capture2(*command) | ||
| abort_with("Command failed: #{command.join(" ")}") unless status.success? | ||
| stdout | ||
| end | ||
|
|
||
| def load_manifest | ||
| JSON.parse(File.read(MANIFEST)) | ||
| end | ||
|
|
||
| def require_tophat! | ||
| abort_with("Tophat is not installed at #{TOPHATCTL}. Run 'dev up' to install it.") unless File.executable?(TOPHATCTL) | ||
| end | ||
|
|
||
| def install_options(manifest) | ||
| manifest.fetch("targets").flat_map do |target| | ||
| platforms = target.fetch("recipes").map { |recipe| recipe.fetch("platform") }.uniq | ||
| platforms.map do |platform| | ||
| { | ||
| "id" => "#{target.fetch("id")}-#{platform}", | ||
| "label" => "#{target.fetch("label")} (#{PLATFORM_LABELS.fetch(platform, platform)})", | ||
| "target" => target, | ||
| "platform" => platform | ||
| } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def available_target_ids(manifest) | ||
| install_options(manifest).map { |option| option.fetch("id") } | ||
| end | ||
|
|
||
| def artifact_provider_parameters(recipe, app_slug, branch) | ||
| { | ||
| "app_slug" => app_slug, | ||
| "branch" => branch, | ||
| "workflow" => recipe.fetch("workflow"), | ||
| "artifact_name" => recipe.fetch("artifact_name") | ||
| } | ||
| end | ||
|
|
||
| def bitrise_branch_recipe(recipe, app_slug, branch) | ||
| { | ||
| "artifactProviderID" => "bitrise-branch", | ||
| "launchArguments" => [], | ||
| "artifactProviderParameters" => artifact_provider_parameters(recipe, app_slug, branch) | ||
| } | ||
| end | ||
|
|
||
| def install_config(recipe, device, app_slug, branch) | ||
| [ | ||
| bitrise_branch_recipe(recipe, app_slug, branch).merge( | ||
| "device" => { | ||
| "name" => device.fetch("name"), | ||
| "platform" => device.fetch("platform"), | ||
| "runtimeVersion" => device.fetch("runtimeVersion") | ||
| } | ||
| ) | ||
| ] | ||
| end | ||
|
|
||
| def quick_launch_entry(target, app_slug, branch) | ||
| { | ||
| "id" => "checkout-kit-#{target.fetch("id")}", | ||
| "name" => "Checkout Kit (#{target.fetch("label")})", | ||
| "recipes" => target.fetch("recipes").map do |recipe| | ||
| quick_launch_recipe(recipe, app_slug, branch) | ||
| end | ||
| } | ||
| end | ||
|
|
||
| def quick_launch_recipe(recipe, app_slug, branch) | ||
| config = bitrise_branch_recipe(recipe, app_slug, branch).merge( | ||
| "platformHint" => recipe.fetch("platform") | ||
| ) | ||
| destination = recipe.fetch("destination") | ||
| config["destinationHint"] = destination unless destination == "any" | ||
| config | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/usr/bin/env ruby | ||
| # frozen_string_literal: true | ||
|
|
||
| require "tempfile" | ||
| require_relative "common" | ||
|
|
||
| def add_quick_launch_entry(entry) | ||
| Tempfile.create(["tophat-quick-launch", ".json"]) do |file| | ||
| file.write(JSON.generate(entry)) | ||
| file.flush | ||
| system(CheckoutKitTophat::TOPHATCTL, "apps", "add", file.path) || CheckoutKitTophat.abort_with("Failed to configure Tophat Quick Launch entry #{entry.fetch("id")}") | ||
| end | ||
| end | ||
|
|
||
| CheckoutKitTophat.require_tophat! | ||
| manifest = CheckoutKitTophat.load_manifest | ||
|
|
||
| manifest.fetch("targets").each do |target| | ||
| entry = CheckoutKitTophat.quick_launch_entry(target, manifest.fetch("app_slug"), manifest.fetch("default_branch")) | ||
| add_quick_launch_entry(entry) | ||
| end | ||
|
|
||
| puts <<~REMINDER | ||
|
|
||
| ==> Tophat Quick Launch items configured for Checkout Kit. | ||
| Installs need a Bitrise Personal Access Token: | ||
| 1. Create a PAT at #{CheckoutKitTophat::BITRISE_PAT_URL} | ||
| 2. Add it to Tophat -> Settings -> Extensions -> Bitrise | ||
| REMINDER |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we aren't building on main - so this wont work until we decide to do that, if we decide that main builds are not desirable then we can just remove this quick launch open