-
Notifications
You must be signed in to change notification settings - Fork 9
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
3 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
lib/fastlane/plugin/wpmreleasetoolkit/actions/common/publish_release_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,63 @@ | ||
require 'fastlane/action' | ||
require_relative '../../helper/github_helper' | ||
|
||
module Fastlane | ||
module Actions | ||
class PublishReleaseAction < Action | ||
def self.run(params) | ||
repository = params[:repository] | ||
name = params[:name] | ||
prerelease = params[:prerelease] | ||
|
||
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token]) | ||
|
||
url = github_helper.publish_release( | ||
repository: repository, | ||
name: name, | ||
prerelease: prerelease | ||
) | ||
UI.success("Successfully published GitHub Release #{name}. You can see it at '#{url}'") | ||
url | ||
end | ||
|
||
def self.description | ||
'Publishes an existing GitHub Release still in draft mode' | ||
end | ||
|
||
def self.authors | ||
['Automattic'] | ||
end | ||
|
||
def self.return_value | ||
'The URL of the published GitHub Release' | ||
end | ||
|
||
def self.details | ||
'Publishes an existing GitHub Release still in draft mode' | ||
end | ||
|
||
def self.available_options | ||
[ | ||
FastlaneCore::ConfigItem.new(key: :repository, | ||
description: 'The slug (`<org>/<repo>`) of the GitHub repository we want to create the release on', | ||
optional: false, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :name, | ||
description: 'The name of the release', | ||
optional: false, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :prerelease, | ||
description: 'True if this is a pre-release', | ||
optional: true, | ||
default_value: false, | ||
type: Boolean), | ||
Fastlane::Helper::GithubHelper.github_token_config_item, | ||
] | ||
end | ||
|
||
def self.is_supported?(platform) | ||
true | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require 'spec_helper' | ||
|
||
describe Fastlane::Actions::PublishReleaseAction do | ||
let(:test_token) { 'ghp_fake_token' } | ||
let(:test_repo) { 'repo-test/project-test' } | ||
let(:test_name) { '1.0.0' } | ||
let(:github_helper) { double(Fastlane::Helper::GithubHelper) } | ||
|
||
before do | ||
allow(Fastlane::Helper::GithubHelper).to receive(:new).and_return(github_helper) | ||
end | ||
|
||
context 'when providing valid parameters' do | ||
it 'publishes the release and returns the URL' do | ||
expect(github_helper).to receive(:publish_release).with( | ||
repository: test_repo, | ||
name: test_name, | ||
prerelease: false | ||
).and_return('https://github.com/repo-test/project-test/releases/tag/1.0.0') | ||
|
||
result = run_described_fastlane_action( | ||
github_token: test_token, | ||
repository: test_repo, | ||
name: test_name | ||
) | ||
|
||
expect(result).to eq('https://github.com/repo-test/project-test/releases/tag/1.0.0') | ||
end | ||
|
||
it 'publishes a prerelease when specified' do | ||
expect(github_helper).to receive(:publish_release).with( | ||
repository: test_repo, | ||
name: test_name, | ||
prerelease: true | ||
).and_return('https://github.com/repo-test/project-test/releases/tag/1.0.0-beta') | ||
|
||
result = run_described_fastlane_action( | ||
github_token: test_token, | ||
repository: test_repo, | ||
name: test_name, | ||
prerelease: true | ||
) | ||
|
||
expect(result).to eq('https://github.com/repo-test/project-test/releases/tag/1.0.0-beta') | ||
end | ||
end | ||
|
||
context 'when successful' do | ||
it 'prints a success message' do | ||
allow(github_helper).to receive(:publish_release).and_return('https://github.com/repo-test/project-test/releases/tag/1.0.0') | ||
|
||
allow(Fastlane::UI).to receive(:success).with(anything).at_least(:once) | ||
expect(Fastlane::UI).to receive(:success).with("Successfully published GitHub Release 1.0.0. You can see it at 'https://github.com/repo-test/project-test/releases/tag/1.0.0'") | ||
|
||
run_described_fastlane_action( | ||
github_token: test_token, | ||
repository: test_repo, | ||
name: test_name | ||
) | ||
end | ||
end | ||
end |