From 717b37e410b93917b09235ccba1e0427c5482704 Mon Sep 17 00:00:00 2001 From: Damian Szymanski Date: Thu, 12 Sep 2019 16:14:24 +0200 Subject: [PATCH 1/9] FreeBSD pkg addon --- lib/travis/build/addons.rb | 1 + lib/travis/build/addons/pkg.rb | 56 ++++++++++++++++++++++++++++++++++ lib/travis/build/errors.rb | 10 ++++++ spec/build/addons/pkg_spec.rb | 40 ++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 lib/travis/build/addons/pkg.rb create mode 100644 spec/build/addons/pkg_spec.rb diff --git a/lib/travis/build/addons.rb b/lib/travis/build/addons.rb index 2237bbc054..80f4c2069b 100644 --- a/lib/travis/build/addons.rb +++ b/lib/travis/build/addons.rb @@ -22,6 +22,7 @@ require 'travis/build/addons/sonarqube' require 'travis/build/addons/browserstack' require 'travis/build/addons/srcclr' +require 'travis/build/addons/pkg' module Travis module Build diff --git a/lib/travis/build/addons/pkg.rb b/lib/travis/build/addons/pkg.rb new file mode 100644 index 0000000000..cc3c96577e --- /dev/null +++ b/lib/travis/build/addons/pkg.rb @@ -0,0 +1,56 @@ +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? + # keeping empty for now + end + + def before_configure + # keeping empty for now + 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 ["sudo pkg install", "-y", packages].join(' '), 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 diff --git a/lib/travis/build/errors.rb b/lib/travis/build/errors.rb index 3ec7f577c9..0cd4b1b4b0 100644 --- a/lib/travis/build/errors.rb +++ b/lib/travis/build/errors.rb @@ -71,5 +71,15 @@ def doc_path '/user/installing-dependencies' end end + + class PkgConfigError < CompilationError + def initialize(msg = "\\`pkg\\` should be a list.") + super + end + + def doc_path + '/user/installing-dependencies' + end + end end end diff --git a/spec/build/addons/pkg_spec.rb b/spec/build/addons/pkg_spec.rb new file mode 100644 index 0000000000..51e15729e0 --- /dev/null +++ b/spec/build/addons/pkg_spec.rb @@ -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, "sudo pkg install -y git curl", echo: true, timing: true, assert: true] } + end + + context 'with single packages' do + let(:pkg_config) { { packages: ['git'] } } + + it { should include_sexp [:cmd, "sudo pkg install -y git", echo: true, timing: true, assert: true] } + end +end From fd52d08cc4497d12ad3feff50c207c7efb3d2488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Szyma=C5=84ski?= Date: Fri, 13 Sep 2019 07:23:53 +0200 Subject: [PATCH 2/9] Update lib/travis/build/addons/pkg.rb, Use su instead of sudo Co-Authored-By: Alex Arslan --- lib/travis/build/addons/pkg.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/build/addons/pkg.rb b/lib/travis/build/addons/pkg.rb index cc3c96577e..0115ce40c7 100644 --- a/lib/travis/build/addons/pkg.rb +++ b/lib/travis/build/addons/pkg.rb @@ -40,7 +40,7 @@ def install_pkg sh.echo "Installing #{config_pkg.count} packages", ansi: :yellow packages = config_pkg.map{|v| Shellwords.escape(v)}.join(' ') - sh.cmd ["sudo pkg install", "-y", packages].join(' '), echo: true, timing: true, assert: true + sh.cmd "su -m root -c 'pkg install -y #{packages.join(' ')}'", echo: true, timing: true, assert: true end def config_pkg From e2465274fdccd9160f4e33b9be1e801c7c2dd46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Szyma=C5=84ski?= Date: Fri, 13 Sep 2019 07:24:32 +0200 Subject: [PATCH 3/9] Update lib/travis/build/addons/pkg.rb, Use ASSUME_ALWAYS_YES, add branch support Co-Authored-By: Alex Arslan --- lib/travis/build/addons/pkg.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/travis/build/addons/pkg.rb b/lib/travis/build/addons/pkg.rb index 0115ce40c7..1a212c4ad4 100644 --- a/lib/travis/build/addons/pkg.rb +++ b/lib/travis/build/addons/pkg.rb @@ -29,7 +29,20 @@ def before_configure? end def before_configure - # keeping empty for now + 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_test} ${TRAVIS_ROOT}/usr/local/etc/pkg.conf"} + if 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 From 59c34f5c9437d6134422b773174835563d028e7d Mon Sep 17 00:00:00 2001 From: Damian Szymanski Date: Fri, 13 Sep 2019 07:28:37 +0200 Subject: [PATCH 4/9] Minor fix, it's string --- lib/travis/build/addons/pkg.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/build/addons/pkg.rb b/lib/travis/build/addons/pkg.rb index 1a212c4ad4..4450bdb83a 100644 --- a/lib/travis/build/addons/pkg.rb +++ b/lib/travis/build/addons/pkg.rb @@ -53,7 +53,7 @@ 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 -y #{packages.join(' ')}'", echo: true, timing: true, assert: true + sh.cmd "su -m root -c 'pkg install #{packages}'", echo: true, timing: true, assert: true end def config_pkg From 6b119dd419ea37dd868c32077620138d22a6191a Mon Sep 17 00:00:00 2001 From: Damian Szymanski Date: Fri, 13 Sep 2019 07:34:20 +0200 Subject: [PATCH 5/9] Update spec --- spec/build/addons/pkg_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/build/addons/pkg_spec.rb b/spec/build/addons/pkg_spec.rb index 51e15729e0..044c8988ed 100644 --- a/spec/build/addons/pkg_spec.rb +++ b/spec/build/addons/pkg_spec.rb @@ -29,12 +29,12 @@ context 'with multiple packages' do let(:pkg_config) { { packages: ['git', 'curl'] } } - it { should include_sexp [:cmd, "sudo pkg install -y git curl", echo: true, timing: true, assert: true] } + 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, "sudo pkg install -y git", echo: true, timing: true, assert: true] } + it { should include_sexp [:cmd, "su -m root -c 'pkg install git'", echo: true, timing: true, assert: true] } end end From 09891ec8a9e1d5fdcfc35c1988cd5a4abee8d3c8 Mon Sep 17 00:00:00 2001 From: Damian Szymanski Date: Tue, 3 Mar 2020 09:21:38 +0100 Subject: [PATCH 6/9] Fix indent --- lib/travis/build/addons/pkg.rb | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/travis/build/addons/pkg.rb b/lib/travis/build/addons/pkg.rb index 4450bdb83a..bc776d5982 100644 --- a/lib/travis/build/addons/pkg.rb +++ b/lib/travis/build/addons/pkg.rb @@ -29,20 +29,20 @@ def before_configure? 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_test} ${TRAVIS_ROOT}/usr/local/etc/pkg.conf"} - if 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 + 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_test} ${TRAVIS_ROOT}/usr/local/etc/pkg.conf"} + if 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 From 1dcb0b332fd1fc148ef1515fe82b98b3d39c8c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Szyma=C5=84ski?= Date: Tue, 3 Mar 2020 19:42:16 +0100 Subject: [PATCH 7/9] Update lib/travis/build/addons/pkg.rb Co-Authored-By: Alex Arslan --- lib/travis/build/addons/pkg.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/build/addons/pkg.rb b/lib/travis/build/addons/pkg.rb index bc776d5982..6276605af2 100644 --- a/lib/travis/build/addons/pkg.rb +++ b/lib/travis/build/addons/pkg.rb @@ -36,7 +36,7 @@ def before_configure FETCH_RETRY=5 FETCH_TIMEOUT=30 PKG_CONF - sh.cmd %Q{su -m root -c "mv #{tmp_test} ${TRAVIS_ROOT}/usr/local/etc/pkg.conf"} + sh.cmd %Q{su -m root -c "mv #{tmp_dest} ${TRAVIS_ROOT}/usr/local/etc/pkg.conf"} if config[:branch].to_s.downcase != 'quarterly' sed_find = 'pkg+http://pkg.FreeBSD.org/\([^/]*\)/quarterly' sed_replace = 'pkg+http://pkg.FreeBSD.org/\1/' + config[:branch] From 4644923c5fb7eba0e8280e54bc6790b73c35eef3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 Mar 2020 03:49:31 +0000 Subject: [PATCH 8/9] Bump puma from 3.12.3 to 3.12.4 Bumps [puma](https://github.com/puma/puma) from 3.12.3 to 3.12.4. - [Release notes](https://github.com/puma/puma/releases) - [Changelog](https://github.com/puma/puma/blob/master/History.md) - [Commits](https://github.com/puma/puma/compare/v3.12.3...v3.12.4) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6a2042fa2c..e6768a29a9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -111,7 +111,7 @@ GEM coderay (~> 1.1.0) method_source (~> 0.9.0) public_suffix (3.0.3) - puma (3.12.3) + puma (3.12.4) pusher-client (0.6.2) json websocket (~> 1.0) From 765a8d840f8a2e58badf07f0580455874ababbd7 Mon Sep 17 00:00:00 2001 From: Damian Szymanski Date: Wed, 4 Mar 2020 10:10:01 +0100 Subject: [PATCH 9/9] Run before configure --- lib/travis/build/addons/pkg.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/travis/build/addons/pkg.rb b/lib/travis/build/addons/pkg.rb index 6276605af2..a3dbd4c804 100644 --- a/lib/travis/build/addons/pkg.rb +++ b/lib/travis/build/addons/pkg.rb @@ -25,7 +25,7 @@ def before_prepare end def before_configure? - # keeping empty for now + config end def before_configure @@ -37,7 +37,7 @@ def before_configure 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].to_s.downcase != 'quarterly' + 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}