Skip to content

Commit

Permalink
breaking changes
Browse files Browse the repository at this point in the history
- add required `executable_file_basename` option for the upload plugin
- add optional `executable_environment_key` to customize the `RUN_INPUT_PATH` name for the notify plugin
- rename `run_input_path` option to `executable_filename` for the notify plugin
- update notify plugin to automatically set git branch and commit hash when available
  • Loading branch information
smonn committed Nov 18, 2024
1 parent 4a05840 commit d0a0244
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 47 deletions.
5 changes: 4 additions & 1 deletion fastlane/Fastfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
lane :test do
upload_to_qawolf(
file_path: "./fastlane/fastlane-test-app-debug.apk"
file_path: "./fastlane/fastlane-test-app-debug.apk",
executable_file_basename: "fastlane_test"
)
notify_deploy_qawolf(
deployment_type: "android",
sha: false,
executable_environment_key: "ANDROID_APP",
variables: {
HELLO: "WORLD"
}
Expand Down
45 changes: 29 additions & 16 deletions lib/fastlane/plugin/qawolf/actions/notify_deploy_qawolf_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,28 @@ module SharedValues

# Casing is important for the action name!
class NotifyDeployQawolfAction < Action
BASE_PATH = "/home/wolf/run-inputs-executables/"

def self.run(params)
qawolf_api_key = params[:qawolf_api_key] # Required
qawolf_base_url = params[:qawolf_base_url]

UI.message("🐺 Calling QA Wolf deploy success webhook...")

variables = params[:variables] || {}
executable_environment_key = params[:executable_environment_key]
branch = params[:branch] if params[:branch].kind_of?(String) && !params[:branch].empty?
sha = params[:sha] if params[:sha].kind_of?(String) && !params[:sha].empty?

options = {
branch: params[:branch],
branch: 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(params)
})
sha: sha,
variables: variables.merge({ executable_environment_key => run_input_path(params) })
}

run_id = Helper::QawolfHelper.notify_deploy(qawolf_api_key, qawolf_base_url, options)
Expand All @@ -42,11 +45,11 @@ def self.run(params)
end

def self.run_input_path(params)
if params[: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.")
if params[:executable_filename].nil?
UI.user_error!("🐺 No executable filename found. Please run the `upload_to_qawolf` action first or set the `executable_filename` option.")
end

return params[:run_input_path]
return "#{BASE_PATH}#{params[:executable_filename]}"
end

def self.description
Expand Down Expand Up @@ -79,10 +82,16 @@ def self.available_options
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",
FastlaneCore::ConfigItem.new(key: :executable_environment_key,
description: "Sets the environment key to use for the executable. Will alias the executable file's absolute path in tests to, for example, `process.env.RUN_INPUT_PATH` Defaults to `RUN_INPUT_PATH`",
optional: true,
default_value: "RUN_INPUT_PATH",
type: String),
FastlaneCore::ConfigItem.new(key: :branch,
description: "Defaults to the current git branch if available. Override by providing a custom value, or set it to false to send an empty value. Displayed in the QA Wolf UI to help find any pull requests in the linked repo",
optional: true,
default_value: Actions.git_branch,
type: Object),
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,
Expand All @@ -104,16 +113,18 @@ def self.available_options
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",
description: "Defaults to the current git commit hash. Override by providing a custom value, or set to false to send an empty value. We use it to create commit checks if you also have a GitHub repo linked. Also displayed in the QA Wolf UI",
optional: true,
type: String),
default_value: Actions.last_git_commit_hash(false),
type: Object),
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",
default_value: {},
type: Hash),
FastlaneCore::ConfigItem.new(key: :executable_filename,
env_name: "QAWOLF_EXECUTABLE_FILENAME",
description: "The filename of the executable to use in QA Wolf. Set by the `upload_to_qawolf` action",
optional: true,
type: String)
]
Expand All @@ -130,6 +141,8 @@ def self.example_code
'notify_deploy_qawolf',
'notify_deploy_qawolf(
qawolf_api_key: ENV["QAWOLF_API_KEY"],
executable_environment_key: "MY_APP",
executable_filename: "<FILENAME>",
branch: "<BRANCH_NAME>",
commit_url: "<URL>",
deployment_type: "<DEPLOYMENT_TYPE>",
Expand Down
37 changes: 21 additions & 16 deletions lib/fastlane/plugin/qawolf/actions/upload_to_qawolf_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Fastlane
module Actions
module SharedValues
QAWOLF_RUN_INPUT_PATH = :QAWOLF_RUN_INPUT_PATH
QAWOLF_EXECUTABLE_FILENAME = :QAWOLF_EXECUTABLE_FILENAME
end

# Casing is important for the action name!
Expand All @@ -16,20 +16,20 @@ def self.run(params)
qawolf_api_key = params[:qawolf_api_key] # Required
qawolf_base_url = params[:qawolf_base_url]
file_path = params[:file_path] || default_file_path
filename = params[:filename]
executable_file_basename = params[:executable_file_basename]

validate_file_path(file_path)

UI.message("🐺 Uploading to QA Wolf...")

run_input_path = Helper::QawolfHelper.upload_file(qawolf_api_key, qawolf_base_url, file_path, filename)
uploaded_filename = Helper::QawolfHelper.upload_file(qawolf_api_key, qawolf_base_url, file_path, executable_file_basename)

ENV["QAWOLF_RUN_INPUT_PATH"] = run_input_path
ENV["QAWOLF_EXECUTABLE_FILENAME"] = uploaded_filename

UI.success("🐺 Uploaded #{file_path} to QA Wolf successfully. Run input path: #{run_input_path}")
UI.success("🐺 Setting environment variable QAWOLF_RUN_INPUT_PATH = #{run_input_path}")
UI.success("🐺 Uploaded #{file_path} to QA Wolf successfully. Executable filename: #{uploaded_filename}")
UI.success("🐺 Setting environment variable QAWOLF_EXECUTABLE_FILENAME = #{uploaded_filename}")

Actions.lane_context[SharedValues::QAWOLF_RUN_INPUT_PATH] = run_input_path
Actions.lane_context[SharedValues::QAWOLF_EXECUTABLE_FILENAME] = uploaded_filename
end

# Validate file_path.
Expand Down Expand Up @@ -58,7 +58,7 @@ def self.details

def self.output
[
['QAWOLF_RUN_INPUT_PATH', 'Uploaded file location for the executable artifact.']
['QAWOLF_EXECUTABLE_FILENAME', 'Uploaded filename for the executable artifact.']
]
end

Expand Down Expand Up @@ -94,12 +94,16 @@ def self.available_options
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :file_path,
description: "Path to the app file",
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :filename,
description: "Optional uploaded filename to use instead of the original filename",
description: "Path to the built app file",
optional: true,
type: String,
verify_block: proc do |value|
file_path = File.expand_path(value)
UI.user_error!("Couldn't find file at path '#{file_path}'") unless File.exist?(file_path)
end),
FastlaneCore::ConfigItem.new(key: :executable_file_basename,
description: "Required file basename for the uploaded executable",
optional: false,
type: String)
]
end
Expand All @@ -112,12 +116,13 @@ def self.is_supported?(platform)

def self.example_code
[
'qawolf',
'upload_to_qawolf',
'upload_to_qawolf(
executable_file_basename: "my_app"
)',
'upload_to_qawolf(
qawolf_api_key: ENV["QAWOLF_API_KEY"],
file_path: "/path_to/app.apk",
filename: "custom_filename.apk"
executable_file_basename: "my_app"
)'
]
end
Expand Down
11 changes: 8 additions & 3 deletions lib/fastlane/plugin/qawolf/helper/qawolf_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,21 @@ def self.get_signed_url(qawolf_api_key, qawolf_base_url, filename)
# +qawolf_api_key+:: QA Wolf API key
# +qawolf_base_url+:: QA Wolf API base URL
# +file_path+:: Path to the file to be uploaded.
# +filename+:: Optional filename to use instead of the file's basename.
def self.upload_file(qawolf_api_key, qawolf_base_url, file_path, filename = nil)
# +executable_file_basename+:: Name to use for the uploaded file without extension
def self.upload_file(qawolf_api_key, qawolf_base_url, file_path, executable_file_basename)
unless executable_file_basename
UI.user_error!("`executable_file_basename` is required")
end

file_content = File.open(file_path, "rb")

headers = {
user_agent: "qawolf_fastlane_plugin",
content_type: "application/octet-stream"
}

signed_url, run_input_path = get_signed_url(qawolf_api_key, qawolf_base_url, filename || File.basename(file_path))
uploaded_filename = "#{executable_file_basename}#{File.extname(file_path)}"
signed_url, run_input_path = get_signed_url(qawolf_api_key, qawolf_base_url, uploaded_filename)

RestClient.put(signed_url, file_content, headers)

Expand Down
2 changes: 1 addition & 1 deletion lib/fastlane/plugin/qawolf/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Fastlane
module Qawolf
VERSION = "0.2.0"
VERSION = "0.3.0"
end
end
6 changes: 3 additions & 3 deletions spec/fastlane/actions/notify_deploy_qawolf_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

describe Fastlane::Actions::NotifyDeployQawolfAction do
describe "#run" do
let(:run_input_path) { "file.apk" }
let(:executable_filename) { "file.apk" }
let(:params) do
{
qawolf_api_key: "api_key",
run_input_path: run_input_path
executable_filename: executable_filename
}
end
let(:deploy_response) do
Expand All @@ -32,7 +32,7 @@
end

context "with no run input path set" do
let(:run_input_path) { nil }
let(:executable_filename) { nil }

it "fails when no test run is triggered" do
expect do
Expand Down
15 changes: 8 additions & 7 deletions spec/fastlane/actions/upload_to_qawolf_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
qawolf_api_key: "api_key",
file_path: file_path,
filename: nil
executable_file_basename: "my_app"
}
end

Expand All @@ -22,7 +22,7 @@
allow(File).to receive(:open).with(file_path, "rb").and_return('empty file')

url = URI.join(Fastlane::Helper::QawolfHelper::BASE_URL, Fastlane::Helper::QawolfHelper::SIGNED_URL_ENDPOINT)
url.query = URI.encode_www_form({ 'file' => params[:filename] || File.basename(file_path) })
url.query = URI.encode_www_form({ 'file' => "#{params[:executable_file_basename]}#{File.extname(file_path)}" })

stub_request(:get, url.to_s)
.to_return(
Expand All @@ -47,18 +47,19 @@
end.to raise_error(FastlaneCore::Interface::FastlaneError)
end

context "with filename specified" do
context "with no executable_file_basename specified" do
let(:params) do
{
qawolf_api_key: "api_key",
file_path: file_path,
filename: "custom_filename.apk"
executable_file_basename: nil
}
end

it "uploads the file with custom filename" do
result = described_class.run(params)
expect(result).to eq(signed_url_response[:playgroundFileLocation])
it "fails to upload" do
expect do
described_class.run(params)
end.to raise_error(FastlaneCore::Interface::FastlaneError)
end
end

Expand Down

0 comments on commit d0a0244

Please sign in to comment.