-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
298 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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,10 +1,13 @@ | ||
lane :test do | ||
qawolf( | ||
file_path: "./fastlane/fastlane-test-app-debug.apk", | ||
filename: "app.apk" | ||
upload_to_qawolf( | ||
file_path: "./fastlane/fastlane-test-app-debug.apk" | ||
) | ||
notify_deploy_qawolf( | ||
deployment_type: "android", | ||
run_input_path: "bad.apk", | ||
variables: { | ||
HELLO: "WORLD", | ||
RUN_INPUT_PATH: "bad123.apk" | ||
} | ||
) | ||
# upload_to_qawolf( | ||
# qawolf_api_key: ENV["QAWOLF_API_KEY"], | ||
# file_path: "./fastlane/fastlane-test-app-debug.apk" | ||
# ) | ||
end |
143 changes: 143 additions & 0 deletions
143
lib/fastlane/plugin/qawolf/actions/notify_deploy_qawolf_action.rb
This file contains 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,143 @@ | ||
require 'fastlane/action' | ||
require 'fastlane_core' | ||
require_relative '../helper/qawolf_helper' | ||
|
||
module Fastlane | ||
module Actions | ||
module SharedValues | ||
QAWOLF_RUN_ID = :QAWOLF_RUN_ID | ||
end | ||
|
||
# Casing is important for the action name! | ||
class NotifyDeployQawolfAction < Action | ||
def self.run(params) | ||
qawolf_api_key = params[:qawolf_api_key] # Required | ||
qawolf_base_url = params[:qawolf_base_url] | ||
run_input_path = params[:run_input_path] || Actions.lane_context[SharedValues::QAWOLF_RUN_INPUT_PATH] | ||
|
||
if run_input_path.nil? | ||
UI.user_error!("🐺 No run input path found. Please run the `upload_to_qawolf` action first or set the `run_input_path` option.") | ||
end | ||
|
||
if params[:run_input_path].nil? == false && Actions.lane_context[SharedValues::QAWOLF_RUN_INPUT_PATH].nil? == false | ||
UI.important("🐺 Both `run_input_path` and `QAWOLF_RUN_INPUT_PATH` are set. Using `run_input_path`.") | ||
end | ||
|
||
UI.message("🐺 Calling QA Wolf deploy success webhook...") | ||
|
||
variables = params[:variables] || {} | ||
|
||
options = { | ||
branch: params[:branch], | ||
commit_url: params[:commit_url], | ||
deployment_type: params[:deployment_type], | ||
deployment_url: params[:deployment_url], | ||
deduplication_key: params[:deduplication_key], | ||
hosting_service: params[:hosting_service], | ||
sha: params[:sha], | ||
variables: variables.merge({ | ||
RUN_INPUT_PATH: run_input_path | ||
}) | ||
} | ||
|
||
run_id = Helper::QawolfHelper.notify_deploy(qawolf_api_key, qawolf_base_url, options) | ||
|
||
UI.success("🐺 QA Wolf triggered run: #{run_id}") | ||
UI.success("🐺 Setting environment variable QAWOLF_RUN_ID = #{run_id}") | ||
|
||
Actions.lane_context[SharedValues::QAWOLF_RUN_ID] = run_id | ||
end | ||
|
||
def self.description | ||
"Fastlane plugin for QA Wolf integration to trigger test runs." | ||
end | ||
|
||
def self.authors | ||
["QA Wolf"] | ||
end | ||
|
||
def self.details | ||
"Calls the QA Wolf deployment success webhook to trigger test runs. Requires the `upload_to_qawolf` action to be run first." | ||
end | ||
|
||
def self.output | ||
[ | ||
['QAWOLF_RUN_ID', 'The ID of the run triggered in QA Wolf.'] | ||
] | ||
end | ||
|
||
def self.available_options | ||
[ | ||
FastlaneCore::ConfigItem.new(key: :qawolf_api_key, | ||
env_name: "QAWOLF_API_KEY", | ||
description: "Your QA Wolf API key", | ||
optional: false, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :qawolf_base_url, | ||
env_name: "QAWOLF_BASE_URL", | ||
description: "Your QA Wolf base URL", | ||
optional: true, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :branch, | ||
description: "If using Git, set this to the branch name so it can be displayed in the QA Wolf UI and find any pull requests in the linked repo", | ||
optional: true, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :commit_url, | ||
description: "If you do not specify a hosting service, include this and the `sha` option to ensure the commit hash is a clickable link in QA Wolf", | ||
optional: true, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :deduplication_key, | ||
description: "By default, new runs will cancel ongoing runs if the `branch` and `environment` combination is matched, so setting this will instead cancel runs that have the same key", | ||
optional: true, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :deployment_type, | ||
description: "Arbitrary string to describe the deployment type. Configured in the QA Wolf UI when creating deployment triggers", | ||
optional: true, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :deployment_url, | ||
description: "When set, will be available as `process.env.URL` in tests", | ||
optional: true, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :hosting_service, | ||
description: "GitHub, GitLab, etc. Must be configured in QA Wolf", | ||
optional: true, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :sha, | ||
description: "If a Git commit triggered this, include the commit hash so that we can create commit checks if you also have a GitHub repo linked. Also displayed in the QA Wolf UI", | ||
optional: true, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :variables, | ||
description: "Optional key-value pairs to pass to the test run. These will be available as `process.env` in tests", | ||
optional: true, | ||
type: Object), | ||
FastlaneCore::ConfigItem.new(key: :run_input_path, | ||
env_name: "QAWOLF_RUN_INPUT_PATH", | ||
description: "The path of the run input file to run in QA Wolf. Set by the `upload_to_qawolf` action", | ||
optional: true, | ||
type: String) | ||
] | ||
end | ||
|
||
def self.is_supported?(platform) | ||
# Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example) | ||
# See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform | ||
[:ios, :android].include?(platform) | ||
end | ||
|
||
def self.example_code | ||
[ | ||
'notify_deploy_qawolf', | ||
'notify_deploy_qawolf( | ||
qawolf_api_key: ENV["QAWOLF_API_KEY"], | ||
branch: "<BRANCH_NAME>", | ||
commit_url: "<URL>", | ||
deployment_type: "<DEPLOYMENT_TYPE>", | ||
deployment_url: "<URL>", | ||
hosting_service: "GitHub|GitLab", | ||
sha: "<SHA>" | ||
)' | ||
] | ||
end | ||
end | ||
end | ||
end |
This file contains 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 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 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,5 +1,5 @@ | ||
module Fastlane | ||
module Qawolf | ||
VERSION = "0.1.0" | ||
VERSION = "0.2.0" | ||
end | ||
end |
This file contains 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,72 @@ | ||
require 'webmock/rspec' | ||
|
||
describe Fastlane::Actions::NotifyDeployQawolfAction do | ||
describe "#run" do | ||
let(:run_input_path) { "file.apk" } | ||
let(:params) do | ||
{ | ||
qawolf_api_key: "api_key", | ||
run_input_path: run_input_path | ||
} | ||
end | ||
let(:deploy_response) do | ||
{ | ||
results: [{ created_suite_id: "created_suite_id" }] | ||
} | ||
end | ||
|
||
before do | ||
url = URI.join(Fastlane::Helper::QawolfHelper::BASE_URL, Fastlane::Helper::QawolfHelper::WEBHOOK_DEPLOY_SUCCESS_ENDPOINT) | ||
|
||
stub_request(:post, url.to_s) | ||
.to_return( | ||
status: 200, | ||
body: deploy_response.to_json, | ||
headers: {} | ||
) | ||
end | ||
|
||
it "triggers a test run" do | ||
result = described_class.run(params) | ||
expect(result).to eq(deploy_response[:results][0][:created_suite_id]) | ||
end | ||
|
||
context "with no run input path set" do | ||
let(:run_input_path) { nil } | ||
|
||
it "fails when no test run is triggered" do | ||
expect do | ||
described_class.run(params) | ||
end.to raise_error(FastlaneCore::Interface::FastlaneError) | ||
end | ||
end | ||
|
||
context "with no results" do | ||
let(:deploy_response) do | ||
{ | ||
results: [] | ||
} | ||
end | ||
|
||
it "fails when no test run is triggered" do | ||
expect do | ||
described_class.run(params) | ||
end.to raise_error(FastlaneCore::Interface::FastlaneError) | ||
end | ||
end | ||
|
||
context "with failure reason set" do | ||
let(:deploy_response) do | ||
{ | ||
results: [{ failure_reason: "failure_reason" }] | ||
} | ||
end | ||
|
||
it "fails when no test run is triggered" do | ||
expect do | ||
described_class.run(params) | ||
end.to raise_error(FastlaneCore::Interface::FastlaneError) | ||
end | ||
end | ||
end | ||
end |
This file contains 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