Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1780 from travis-ci/freebsd_pkg_addon
FreeBSD pkg addon
- Loading branch information
Showing
5 changed files
with
121 additions
and
1 deletion.
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
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,69 @@ | ||
require 'travis/build/addons/base' | ||
require 'shellwords' | ||
|
||
module Travis | ||
module Build | ||
class Addons | ||
class Pkg < Base | ||
SUPPORTED_OPERATING_SYSTEMS = %w[ | ||
freebsd | ||
].freeze | ||
|
||
def before_prepare? | ||
SUPPORTED_OPERATING_SYSTEMS.any? do |os_match| | ||
data[:config][:os].to_s == os_match | ||
end | ||
end | ||
|
||
def before_prepare | ||
return if config_pkg.empty? | ||
sh.newline | ||
sh.fold('pkg') do | ||
install_pkg | ||
end | ||
sh.newline | ||
end | ||
|
||
def before_configure? | ||
config | ||
end | ||
|
||
def before_configure | ||
sh.echo "Configuring default pkg options", ansi: :yellow | ||
tmp_dest = "${TRAVIS_TMPDIR}/99-travis-pkg-conf" | ||
sh.file tmp_dest, <<~PKG_CONF | ||
ASSUME_ALWAYS_YES=YES | ||
FETCH_RETRY=5 | ||
FETCH_TIMEOUT=30 | ||
PKG_CONF | ||
sh.cmd %Q{su -m root -c "mv #{tmp_dest} ${TRAVIS_ROOT}/usr/local/etc/pkg.conf"} | ||
if config[:branch] && config[:branch].to_s.downcase != 'quarterly' | ||
sed_find = 'pkg+http://pkg.FreeBSD.org/\([^/]*\)/quarterly' | ||
sed_replace = 'pkg+http://pkg.FreeBSD.org/\1/' + config[:branch] | ||
sed_cmd = %Q{sed -i'' -e 's,#{sed_find},#{sed_replace},' /etc/pkg/FreeBSD.conf} | ||
sh.cmd %Q{su -m root -c "#{sed_cmd}"} | ||
end | ||
end | ||
|
||
def config | ||
@config ||= Hash(super) | ||
end | ||
|
||
def install_pkg | ||
sh.echo "Installing #{config_pkg.count} packages", ansi: :yellow | ||
|
||
packages = config_pkg.map{|v| Shellwords.escape(v)}.join(' ') | ||
sh.cmd "su -m root -c 'pkg install #{packages}'", echo: true, timing: true, assert: true | ||
end | ||
|
||
def config_pkg | ||
@config_pkg ||= Array(config[:packages]).flatten.compact | ||
rescue TypeError => e | ||
if e.message =~ /no implicit conversion of Symbol into Integer/ | ||
raise Travis::Build::PkgConfigError.new | ||
end | ||
end | ||
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,40 @@ | ||
require "spec_helper" | ||
|
||
describe Travis::Build::Addons::Pkg, :sexp do | ||
let(:script) { stub('script') } | ||
#let(:pkg_config) { ['travis', { name: 'aws-cli', no_deps: true }] } | ||
let(:pkg_config) { {} } | ||
let(:data) { payload_for(:push, :ruby, config: { os: 'freebsd', addons: { pkg: pkg_config } }) } | ||
let(:sh) { Travis::Shell::Builder.new } | ||
let(:addon) { described_class.new(script, sh, Travis::Build::Data.new(data), pkg_config) } | ||
subject { sh.to_sexp } | ||
before { addon.before_prepare } | ||
|
||
context 'when on linux' do | ||
let(:data) { payload_for(:push, :ruby, config: { os: 'linux' }) } | ||
|
||
it 'will not run' do | ||
expect(addon.before_prepare?).to eql false | ||
end | ||
end | ||
|
||
context 'when on freebsd' do | ||
let(:data) { payload_for(:push, :ruby, config: { os: 'freebsd' }) } | ||
|
||
it 'will run' do | ||
expect(addon.before_prepare?).to eql true | ||
end | ||
end | ||
|
||
context 'with multiple packages' do | ||
let(:pkg_config) { { packages: ['git', 'curl'] } } | ||
|
||
it { should include_sexp [:cmd, "su -m root -c 'pkg install git curl'", echo: true, timing: true, assert: true] } | ||
end | ||
|
||
context 'with single packages' do | ||
let(:pkg_config) { { packages: ['git'] } } | ||
|
||
it { should include_sexp [:cmd, "su -m root -c 'pkg install git'", echo: true, timing: true, assert: true] } | ||
end | ||
end |