Skip to content
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

[match] Fixes missing job-token error in GitLab storage mode #21520

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions match/lib/match/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ def self.available_options
default_value: 'https://gitlab.com',
description: "GitLab Host (i.e. 'https://gitlab.com')",
optional: true),
FastlaneCore::ConfigItem.new(key: :job_token,
env_name: "CI_JOB_TOKEN",
description: "GitLab CI_JOB_TOKEN",
optional: true),
FastlaneCore::ConfigItem.new(key: :private_token,
env_name: "PRIVATE_TOKEN",
description: "GitLab Access Token",
optional: true),

# Keychain
FastlaneCore::ConfigItem.new(key: :keychain_name,
Expand Down
61 changes: 61 additions & 0 deletions match/spec/storage/gitlab_secure_files_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,65 @@
end
end
end

describe 'Runner Configuration' do
let(:available_options) { Match::Options.available_options }
let(:base_options) {
{
storage_mode: 'gitlab_secure_files',
gitlab_project: 'test/project',
readonly: true,
skip_provisioning_profiles: true,
app_identifier: 'fake-app-identifier'
}
}
let(:configuration) {
FastlaneCore::Configuration.create(available_options, base_options)
}
let(:runner) {
Match::Runner.new.run(configuration)
}

before do
allow_any_instance_of(Match::Runner).to receive(:fetch_certificate)
expect(Match::Storage::GitLab::Client).to receive_message_chain(:new, :prompt_for_access_token)
expect(Match::Storage::GitLab::Client).to receive_message_chain(:new, :files).and_return([])
end

it 'allows the optional job_token param' do
base_options[:job_token] = 'foo'

expect(runner).to be true
expect(configuration.fetch(:storage_mode)).to eq('gitlab_secure_files')
expect(configuration.fetch(:job_token)).to eq('foo')
expect(configuration.fetch(:private_token)).to be nil
end

it 'allows the optional private_token param' do
base_options[:private_token] = 'bar'

expect(runner).to be true
expect(configuration.fetch(:storage_mode)).to eq('gitlab_secure_files')
expect(configuration.fetch(:job_token)).to be nil
expect(configuration.fetch(:private_token)).to eq('bar')
end

it 'uses the PRIVATE_TOKEN ENV variable when supplied' do
stub_const('ENV', ENV.to_hash.merge('PRIVATE_TOKEN' => 'env-private'))

expect(runner).to be true
expect(configuration.fetch(:storage_mode)).to eq('gitlab_secure_files')
expect(configuration.fetch(:job_token)).to be nil
expect(configuration.fetch(:private_token)).to eq('env-private')
end

it 'uses the CI_JOB_TOKEN ENV variable when supplied' do
stub_const('ENV', ENV.to_hash.merge('CI_JOB_TOKEN' => 'env-job'))

expect(runner).to be true
expect(configuration.fetch(:storage_mode)).to eq('gitlab_secure_files')
expect(configuration.fetch(:job_token)).to eq('env-job')
expect(configuration.fetch(:private_token)).to be nil
end
end
end